[include-cleaner] Include-cleaner library structure, and simplistic AST walking.Include-cleaner is a library that uses the clang AST and preprocessor todetermine which headers are used. It will be
[include-cleaner] Include-cleaner library structure, and simplistic AST walking.Include-cleaner is a library that uses the clang AST and preprocessor todetermine which headers are used. It will be used in clang-tidy, inclangd, in a standalone tool at least for testing, and in out-of-tree tools.Roughly, it walks the AST, finds referenced decls, maps these toused sourcelocations, then to FileEntrys, then matching these against #includes.However there are many wrinkles: dealing with macros, standard librarysymbols, umbrella headers, IWYU directives etc.It is not built on the C++20 modules concept of usage, to allow: - use with existing non-modules codebases - a flexible API embeddable in clang-tidy, clangd, and other tools - avoiding a chicken-and-egg problem where include cleanups are needed before modules can be adoptedThis library is based on existing functionality in clangd that providesan unused-include warning. However it has design changes: - it accommodates diagnosing missing includes too (this means tracking where references come from, not just the set of targets) - it more clearly separates the different mappings (symbol => location => header => include) for better testing - it handles special cases like standard library symbols and IWYU directives more elegantly by adding unified Location and Header types instead of side-tables - it will support some customization of policy where necessary (e.g. for style questions of what constitutes a use, or to allow both missing-include and unused-include modes to be conservative)This patch adds the basic directory structure under clang-tools-extraand a skeleton version of the AST traversal, which will be the centralpiece.A more end-to-end prototype is in https://reviews.llvm.org/D122677RFC: https://discourse.llvm.org/t/rfc-lifting-include-cleaner-missing-unused-include-detection-out-of-clangd/61228Differential Revision: https://reviews.llvm.org/D124164
show more ...
[fixup] Handle enum constant `Lang_OBJC` introduced in 4604db94.
[ASTStructuralEquivalence] Add support for comparing ObjCCategoryDecl.Differential Revision: https://reviews.llvm.org/D121176
[Testing] Fix the shared build. NFC.
[Testing] Fix standalone builds after a7691dee2d3c0ea3f9f4d1
[Testing] fix shared lib build after a7691dee2d3c0ea3f9f4d1We still want clang_target_link_libraries for the clang deps.
[Testing] TestAST, a helper for writing straight-line AST testsTests that need ASTs have to deal with the awkward control flow ofFrontendAction in some way. There are a few idioms used: - don't b
[Testing] TestAST, a helper for writing straight-line AST testsTests that need ASTs have to deal with the awkward control flow ofFrontendAction in some way. There are a few idioms used: - don't bother with unit tests, use clang -dump-ast - create an ASTConsumer by hand, which is bulky - use ASTMatchFinder - works pretty well if matchers are actually needed, very strange if they are not - use ASTUnit - this yields nice straight-line code, but ASTUnit is a terrifically complicated library not designed for this purposeTestAST provides a very simple way to write straight-line tests: specifythe code/flags and it provides an AST that is kept alive until theobject is destroyed.It's loosely modeled after TestTU in clangd, which we've successfullyused for a variety of tests.I've updated a couple of clang tests to use this helper, IMO they're clearer.Differential Revision: https://reviews.llvm.org/D123668
[Testing] Drop clangTesting from clang's public library interfaceThis was probably not particularly intended to be public, and disallows depson gtest which are useful in test helpers.https://dis
[Testing] Drop clangTesting from clang's public library interfaceThis was probably not particularly intended to be public, and disallows depson gtest which are useful in test helpers.https://discourse.llvm.org/t/stop-exporting-clangtesting-library/61672Differential Revision: https://reviews.llvm.org/D123610
Fix MSVC "not all control paths return a value" warning. NFC.Add llvm_unreachable after switch statement for TestLanguage enum
Use libClangTesting in the unittest for AST matchersSummary:The unittest for AST matchers has its own way to specify languagestandards. I unified it with the shared infrastructure fromlibClangTe
Use libClangTesting in the unittest for AST matchersSummary:The unittest for AST matchers has its own way to specify languagestandards. I unified it with the shared infrastructure fromlibClangTesting.Reviewers: jdoerfert, hlopkoReviewed By: hlopkoSubscribers: mgorny, sstefan1, cfe-commitsTags: #clangDifferential Revision: https://reviews.llvm.org/D81150
Renamed Lang_C to Lang_C99, Lang_CXX to Lang_CXX03, and 2a to 20Summary:I think we would be better off with tests explicitly specifying thelanguage mode. Right now Lang_C means C99, but reads as
Renamed Lang_C to Lang_C99, Lang_CXX to Lang_CXX03, and 2a to 20Summary:I think we would be better off with tests explicitly specifying thelanguage mode. Right now Lang_C means C99, but reads as "any C version",or as "unspecified C version".I also changed '-std=c++98' to '-std=c++03' because they are aliases (sothere is no difference in practice), because Clang implements C++03rules in practice, and because 03 makes a nice sortable progressionbetween 03, 11, 14, 17, 20.Reviewers: shafik, hlopkoReviewed By: hlopkoSubscribers: jfb, martong, cfe-commitsTags: #clangDifferential Revision: https://reviews.llvm.org/D81000
Move unittest helpers to a shared locationSummary:unittests/AST/Language.h defines some helpers that we would like toreuse in other tests, for example, in tests for syntax trees.Reviewers: samm
Move unittest helpers to a shared locationSummary:unittests/AST/Language.h defines some helpers that we would like toreuse in other tests, for example, in tests for syntax trees.Reviewers: sammccallReviewed By: sammccallSubscribers: mgorny, martong, cfe-commitsTags: #clangDifferential Revision: https://reviews.llvm.org/D80792