Currently each test source file `{dir}/{name}.{ext}` creates a test case
with `{name}` name. Files in different root `{dir}`s but with same {name}s
can end up with a name collision, so test runner just adds suffix '2'
to the name of test suite to avoid collisions. If a developer wants to
only run a specific test using `run_iwyu_tests.py {name}` it might be
difficult to figure out which exactly test failed.
This change adds extra layer of hierarchy (scoping) for tests.
Having 'C' and 'Cxx' tests this change introduces 'c' and 'cxx' TestCase
classes. As before, test runner walks down the `tests/` subtree, and
populates test case classes with `test_{filename}` methods automatically.
Test name examples before and after this change:
+---------------------+---------------+-----------------------
| File Name | Test Before | Test After
+---------------------+---------------+-----------------------
| c/keep_includes.c | keep_includes | c.test_keep_includes
| cxx/using_unused.cc | using_unused | cxx.test_using_unused
It also becomes possible to run C or Cxx tests only:
```
run_iwyu_tests.py c
run_iwyu_tests.py cxx
```
Some of source files require extra Clang or IWYU arguments like
`-std=c++17` or `--mapping_file=...`.
Before this change all these args were stored in `run_iwyu_tests.py`.
This change adds the concept of "ARGS lines" so the launch arguments
could be specified directly in a source file that represents a test case.
Inspired by RUN lines of `lit` in LLVM:
https://llvm.org/docs/TestingGuide.html, "Writing new regression tests".
LLVM and Clang have been in Git for a while now, so avoid 'trunk' in
favor of the actual branch name 'main'.
Update cmake command example for local build tree to use something more
akin to a real directory path.
`CK_FloatingToFixedPoint` and `CK_FixedPointToFloating` added in `9fa7f48`;
`CK_IntegralToFixedPoint` and `CK_FixedPointToIntegral` added in `8f7caae`;
`CK_LValueToRValueBitCast` added in `74ce711`.
The map range iterator returns a `const pair<const string, ...>&`, not the
expected `const pair<string, ...>&`, and the compiler helpfully converts
to a temporary. Make the types match.
Found by Clang's -Wrange-loop-construct
QtCore header is a global header that should be included only if no
other solution is available to fix symbol definition. So move this
mapping at the end of list and use it only as a last resort
Move the responsibility for cracking the headername into module/class
and parsing headers looking for private includes into a helper class.
This makes the main flow much more obvious.
No functional change.
Rather than formatting mapping strings as they are traversed, parse
directory tree and generate an in-memory structure, and then render
that to .imp format using the json module.
This cuts down on quote escaping, and makes the major flow cleaner.
No functional change, but formatting is a little more packed.
Microsoft's _snprintf was never a drop-in replacement for snprintf (it
could leave resulting string un-terminated if it wouldn't fit).
As of Visual Studio 2015, the Microsoft C runtime ships with an actual
C99-compliant snprintf. LLVM requires VS2017, so we can just assume it
exists.
LLVM added a second boolean argument to
isReplaceableGlobalAllocationFunction() with 3dd5a298bfff ("[clang]
Annotating C++'s `operator new` with more attributes"). However both
parameters define a default argument. Hence there is no need to
explicitly state the argument, if it is already the default argument,
which is nullptr is isReplaceableGlobalAllocationFunction() case. This
also increases readability.
This makes <time.h> a valid provider of CLOCKS_PER_SEC and other symbols
declared in <bits/time.h>.
Not entirely sure how this fares with older glibc versions, but my
suspicion is <time.h> is a better candidate than <sys/time.h> in the
general case.
LLVM_INSTALL_PREFIX is only set for the packaged LLVM.
When there's a local build dir, LLVM_LIBRARY_DIR points to the same
place (give or take some library suffix stuff that I will ignore for
now).
Using the latter makes the synthetic 'clang-headers' cmake target work
when the prefix path points to a local LLVM build tree.
ASTNode was consistently instantiated using GlobalSourceManager(). The
passed-in source manager was only used in ASTNode::GetLocation().
Use GlobalSourceManager() there directly instead to keep the constructor
interface simpler.
No functional change.
Now that shouldVisitImplicitCode is on, implicit constructors are properly
visited and we don't need to instantiate them explicitly.
No functional change.
RecursiveASTVisitor::shouldVisitImplicitCode was added to Clang after
IWYU introduced workarounds for implicit code. Using it makes it possible
to remove some boilerplate code.
There are still a few places where special handling is necessary:
* VisitTagDecl needs to explicitly ignore the injected class name
* TraverseCXXDestructorDecl still needs to invoke
TraverseImplicitDestructorCall, which reports usage of fields and bases
for classes with destructors.
* TraverseCXXRecordDecl still needs to call InstantiateImplicitMethods
because Clang does not instantiate _unused_ methods, and so otherwise there
will be nothing to visit.
No high-level functional change.
The Clang API changed in commit 473fbc90d1fbf17e so that Stmt::dump
takes an ASTContext instead of a SourceManager.
Rather than wire a global ASTContext, reimplement PrintableStmt and
PrintStmt to duplicate the most trivial implementations not requiring
ASTContext.
No functional change.