Commit Graph

1277 Commits

Author SHA1 Message Date
Kim Gräsman d46f3a4b0c [cmake] Use target-specific definitions and include dirs
... instead of legacy add_definitions and include_directories.

Move compile options to after target is defined.

Batch abstract target properties with set_target_properties, looks nicer
than setting them individually.
2022-04-24 16:01:09 +02:00
Kim Gräsman 6a3d1bc31f [cmake] Update comment style
Use Google C++-like comment style: comments are full sentences, including
punctuation, except trailing comments which are less formal.
2022-04-24 16:01:09 +02:00
Kim Gräsman 35e84050dc [cmake] Use more consistent formatting
* Use hanging closing parentheses for multiline invocations consistently
* Shorten overlong lines to colwidth 80
* Consistent placing of PRIVATE keyword
* Add space after if
2022-04-24 16:01:09 +02:00
Kim Gräsman ca2b549a8b [cmake] Use more consistent naming
Use lower_case for internal stuff, UPPER_CASE for externally configurable
stuff (as it turns out, only IWYU_LINK_CLANG_DYLIB).
2022-04-24 16:01:09 +02:00
Kim Gräsman 9d94cea91c Only compute use-flags once for fwd decl uses
Rather than recomputing use-flags for decl and using-decl (if one exists),
compute it once into a temporary.

Remove gratuitous const to fit other use-flags expression on one line.
2022-04-23 11:44:32 +02:00
Kim Gräsman 3233575084 Pull using-decl directly from shadow
No use abstracting GetUsingDeclarationOf when we already have the using-decl.

Collapse DynCastFrom into auto + llvm::dyn_cast.
2022-04-23 11:44:32 +02:00
Bolshakov ae98e1ebd7 Maintenance: redundant code removed
self-written using-decl lookup seems to became redundant after introducing
UsingType handling (ce4ccc665)
2022-04-21 21:46:25 +02:00
fanquake d3e7eb40b4 Add additional termios.h mappings
```cpp
include <bits/termios-c_lflag.h>  // for ECHO
include <bits/termios-struct.h>   // for termios
include <bits/termios-tcflow.h>   // for TCSANOW

void SetStdinEcho(bool enable)
{
    struct termios tty;
    tcgetattr(STDIN_FILENO, &tty);
    if (!enable) {
        tty.c_lflag &= ~ECHO;
    } else {
        tty.c_lflag |= ECHO;
    }
    (void)tcsetattr(STDIN_FILENO, TCSANOW, &tty);
}
```
2022-04-21 21:13:12 +02:00
Kim Gräsman 046ca22380 [clang compat] Use FileEntryRef in PPCallbacks::InclusionDirective()
Clang d79ad2f1dbc2db63121620f55d6cfa915f2733ac changed the File parameter from
const FileEntry* to Optional<FileEntryRef>. Parameter is unused in our
implementation, so this is only type system gymnastics.
2022-04-21 20:51:50 +02:00
fanquake f4467365f8 doc: update README.md for 0.18 release 2022-04-15 12:13:07 +02:00
Kim Gräsman 6d3997a3e4 Bump version to 0.19 on master 2022-03-31 20:25:08 +02:00
Kim Gräsman d888efc526 Add minimal testcases for C++20 consteval 2022-02-27 20:40:05 +01:00
Kim Gräsman 7d7fd80da7 See through C++20 consteval for conversion functions
When a consteval function is called, its call-expression is wrapped in a
ConstantExpr in the Clang AST. There's an upstream bug [1] where Clang
doesn't account for that when searching the AST for a cast-expression's
potential user-defined conversion function, leading to an assertion
failure or a crash.

Reimplement GetConversionFunction so it works in this case. This can
safely be reverted when the upstream bug is fixed.

[1] https://github.com/llvm/llvm-project/issues/53044
2022-02-27 20:40:05 +01:00
Kim Gräsman 383a9afb9e Update documentation for new exit codes
Some creative writing in both README and manpage.
2022-02-26 12:21:26 +01:00
Kim Gräsman 3ad4d9b058 [iwyu_tool] Exit with max exit code of IWYU invocations 2022-02-26 12:21:26 +01:00
Kim Gräsman d0ad085893 [fix_includes] Exit with zero on success 2022-02-26 12:21:26 +01:00
Kim Gräsman 8c1e9adf27 Add exit-code command-line options
Two new options:

  --error: sets the exit code to use if there are IWYU violations
  --error_always: sets the exit code to use whether there are IWYU
     violations or not

Add tests to capture all relevant combinations of

  (no warnings, warnings) x
  (--error, --error_always) x
  (explicit arguments, default values)

and make sure --error_always overrides --error.
2022-02-26 12:21:26 +01:00
Kim Gräsman b77197753c Normalize exit codes
Exit with EXIT_FAILURE if the command-line arguments are invalid or
Clang fails to parse the input. Otherwise exit with EXIT_SUCCESS.

Add tests to capture this new policy.
2022-02-26 12:21:26 +01:00
Kim Gräsman 6fa29afb5c Make it possible to verify exit code in tests
It is now possible to append a parenthesized exit code to the summary start
marker: '/**** IWYU_SUMMARY(1)' to indicate that IWYU should return exit
code 1 for this test.

The exit-code syntax is only parsed out of the main file under test (not
e.g. check-also or associated files).

The exit code marker is entirely optional, and most tests shouldn't care
about exit codes.
2022-02-26 12:21:26 +01:00
Kim Gräsman 0fef4d5711 Add new test suite 'driver'
For tests that don't really pertain to language, but have more to do
with driver details, e.g. argument parsing.

Add reusable indirect/direct headers up-front.
2022-02-26 12:21:26 +01:00
Kim Gräsman c14319abe9 Reflow overlong comment line 2022-02-25 23:06:23 +01:00
Kim Gräsman 7008f86fb4 Fix coding system for manpage
Emacs complains about uppercase "UTF-8".
2022-02-25 23:06:23 +01:00
Kim Gräsman ce9bcb74b7 Use scope-bound llvm::llvm_shutdown_obj for shutdown
No need to call it explicitly on alternate control-flow paths.
2022-02-25 23:06:23 +01:00
Kim Gräsman 83b30c22d2 Reflow comment 2022-02-20 16:28:21 +01:00
Kim Gräsman 058936b261 [clang compat] Use range-for over macro tokens
Clang 0d9b91524ea4db3760791bba15773c386a26d8ec renamed the MacroInfo
'tokens_iterator' to 'const_iterator', and broke our code. Use the more
abstract range iteration over 'tokens' instead for nicer code and backwards
compatibility.
2022-02-20 16:28:21 +01:00
Kim Gräsman 50fe9f1455 Use CHECK_UNREACHABLE_ for unreachable code 2022-02-20 16:28:21 +01:00
Kim Gräsman ca9af1e643 [iwyu_tool] Duck-use python3 'getfullargspec'
Using 'inspect.getargspec' in python3 raises a deprecation warning. Prefer
the supported 'inspect.getfullargspec' if it exists.
2022-02-20 16:28:21 +01:00
Kim Gräsman ed1373bf4f [iwyu_tool] Avoid duplicate method def in test
This was most certainly accidental; a new test overwrote an existing test by
using the same name.

Name the test method correctly for better coverage.
2022-02-20 16:28:21 +01:00
Kim Gräsman 9680fa6201 Avoid author-intent analysis on implicit decls
CodeAuthorWantsJustAForwardDeclare uses location information to see whether the
there's a forward-declare hint earlier in the same file.

Implicit decls do not have locations, so assume the author (actually the
compiler itself) does not intend to provide hints to IWYU.

I've found no way to test this in a self-contained example. It was originally
reported in issue #1005 as an assertion triggered by the AArch64 target's
implementation of va_list:

  $ cat /tmp/test.c
  #include <stdarg.h>

  void test(void) {
      va_list args;
  }

  $ include-what-you-use --target=aarch64-linux-gnu -c /tmp/test.c
  include-what-you-use: ...SourceLocation.h:433: ...
     Assertion `Loc.isValid()' failed.
  Aborted (core dumped)

Since I don't want the test suite to depend on environment (in this case,
particular targets being available), I'll leave it untested.
2022-02-12 11:54:15 +01:00
Kim Gräsman 208fbfffa5 [ci] Remove workaround for missing MLIR library 2022-02-06 10:49:35 +01:00
Carlos Gálvez 6739dcb1c1 Fix compilation problem with latest clang
The change was introduced in the llvm-project repo here:
105c913156

The goal is to be able to pass a nullptr directory
to the LookupFile function if we are not interested
in retrieving the current directory, instead of
creating a dummy variable that is not used after
the function is called.

Fixes #996
2022-02-02 17:20:53 +01:00
Kim Gräsman ce4ccc665e Handle new UsingType
Clang added a new AST node in
https://github.com/llvm/llvm-project/commit/e1600db19d6303f84b995acb93, which
shows up in the AST instead of a desugared type.

The presence of a using declaration would be omitted in the AST in favor of the
target type.

Outside of the test suite, we noticed this for <cstdint>, where the integer
types would show up as TypedefTypes in the AST, despite being pulled in via
using-declarations. They now show as UsingTypes. UsingType represents a new
so-called sugar type introduced by way of a using declaration, and links to its
UsingShadowDecl, which in turn makes it possible to chase through the
using-chain.

Report a use of the UsingShadowDecl, which is resolved centrally to the
underlying target decl (desugared typedef) as well as reporting the using-decl
itself. This is consistent with the prior behavior, but should provide better
results for tracking using declarations.
2022-01-10 19:28:40 +01:00
Kim Gräsman 2b89ba1922 [ci] Update packaging workarounds
Things have shifted around.
2022-01-09 20:31:13 +01:00
Kim Gräsman 150cce73eb [ci] Fix YAML syntax
In the previous commit, I merged overlooking the fact that it didn't work.

Apparently push and pull_request can be combined with schedule if they're all
dict forms; the former two can have empty values.
2022-01-09 20:31:13 +01:00
Kim Gräsman 88f564f719 [ci] Schedule nightly build
This will make it easier for us to detect when IWYU breaks due to upstream Clang
changes.

The default behavior for 'schedule' is to run the build for the default branch,
so it only applies to our master branch.
2022-01-09 19:49:32 +01:00
Kim Gräsman 5e1e5ac420 [ci] Fix phrasing in comment
The others are all in imperative mood.
2022-01-09 19:49:32 +01:00
Kim Gräsman 787166f773 Bump version to 0.18 on master 2021-12-05 13:59:17 +01:00
Kim Gräsman 8d1a3dd235 Update README for 0.17 2021-12-05 13:57:34 +01:00
Kim Gräsman 6625c91793 Clarify usage instructions for CMake integration
Based on excellent input from @zchrissirhcz in issue #975.
2021-12-05 12:59:43 +01:00
Alejandro Colomar a0da664a05 Add mappings for the macro 'SIGCHLD'
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
2021-12-05 10:44:25 +01:00
Alejandro Colomar 3dcdbf1520 Add mappings for the macro 'MAP_STACK'
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
2021-12-05 10:44:25 +01:00
Alejandro Colomar 635c287c4e Add mappings for (struct) 'stat'
Signed-off-by: Alejandro Colomar <alx.manpages@gmail.com>
2021-12-05 10:44:25 +01:00
Omar Sandoval 44480a2de0 Add export from <stdint.h> to <inttypes.h>
IWYU currently warns for this example:

  $ cat test.c
  #include <inttypes.h>
  #include <stdio.h>

  int main(void)
  {
          uint64_t x = UINT64_C(1234);
          printf("%" PRIu64 "\n", x);
          return 0;
  }
  $ include-what-you-use test.c

  test.c should add these lines:
  #include <stdint.h>    // for UINT64_C, uint64_t

  test.c should remove these lines:

  The full include-list for test.c:
  #include <inttypes.h>  // for PRIu64
  #include <stdint.h>    // for UINT64_C, uint64_t
  #include <stdio.h>     // for printf
  ---

However, the C standard states that "the header <inttypes.h> includes
the header <stdint.h>". So, this program shouldn't need to include
<stdint.h>.

Some mappings were previously added for individual symbols from
<stdint.h> (e.g., commit 24f9fdf0af ("Add more mappings for
[u]intptr_t"), but it's more accurate to export everything. Get rid of
the symbol mappings and add an include mapping.
2021-12-04 20:25:50 +01:00
Kim Gräsman a73561e3eb Work around missing llvm-omp-device-info in Debian packaging 2021-12-04 20:17:59 +01:00
Bolshakov 532dacdf31 Don't require aliased type method callability
Don't require aliased type method callability if explicitly forward-
declared according to the IWYU forward declaration policy
2021-10-03 16:29:52 +02:00
Salman Javed 75226c1ce8 Add `--update_comments` option
Fixes #75 and fixes #494.
Add `--update_comments` option to make IWYU always print the 'why'
#include comments, regardless of whether any include lines need to be
added or removed. With this change, IWYU will update the "// for xyz"
comments as the code changes, preventing the comments from becoming
stale.
2021-10-01 06:31:27 +02:00
Sven Panne 0997656913 Always use one-line messages with --output-format=clang
Apart from being easier to read by humans, this improves the cooperation
with other tools (e.g. Jenkins' warnings-ng plugin, various Emacs modes)
quite a bit. As an example, here the previous output:

    Foo.h:1:1: error: add the following line
    class Bar;
    Foo.h:18:1: error: remove the following line
    #include "Bar.h"
    Foo.cc:1:1: error: add the following line
    #include "Baz.h"          // for Huey, Dewey, Louie (ptr only)
    Foo.cc:19:1: error: remove the following line
    #include "Blah.h"

With this patch:

    Foo.h:1:1: error: add 'class Bar;'
    Foo.h:18:1: error: superfluous '#include "Bar.h"'
    Foo.cc:1:1: error: add '#include "Baz.h"' (for Huey, Dewey, Louie (ptr only))
    Foo.cc:19:1: error: superfluous '#include "Blah.h"'
2021-09-26 16:40:14 +02:00
Bolshakov d90dcaa1b7 C++11 type aliases should be treated similar to typedefs
TypedefDecl replaced by TypedefNameDecl (common base class for TypedefDecl and TypeAliasDecl)
where possible
2021-08-10 21:59:09 +02:00
Bolshakov fc5e3e8879 Maintenance: seemingly useless code removed
set_in_forward_declare_context should be called in VisitTypedefDecl anyway when it matters
2021-08-10 21:59:09 +02:00
Kim Gräsman 2d9c0c733d Add workaround for broken packaging
libclang-NN.so recently changed versioning schemes, and it doesn't look like the
Debian packages have caught up.

We don't use this file, so placate CMake by creating an empty placeholder.
2021-08-06 13:52:19 +02:00