[clang][lex] Remark on search path usage
authorJan Svoboda <jan_svoboda@apple.com>
Tue, 12 Oct 2021 07:34:43 +0000 (09:34 +0200)
committerJan Svoboda <jan_svoboda@apple.com>
Tue, 12 Oct 2021 10:20:55 +0000 (12:20 +0200)
commit444513510999e4c1ea23253654196793834d53bf
tree0533b14af4e4901deaa22b6ebbc3c4c94942d4b8
parentf4c1258d5633fcf06385ff3fd1f4bf57ab971964
[clang][lex] Remark on search path usage

For dependency scanning, it would be useful to collect header search paths (provided on command-line via `-I` and friends) that were actually used during preprocessing. This patch adds that feature to `HeaderSearch` along with a new remark that reports such paths as they get used.

Previous version of this patch tried to use the existing `LookupFileCache` to report used paths via `HitIdx`. That doesn't work for `ComputeUserEntryUsage` (which is intended to be called *after* preprocessing), because it indexes used search paths by the file name. This means the values get overwritten when the code contains `#include_next`.

Note that `HeaderSearch` doesn't use `HeaderSearchOptions::UserEntries` directly. Instead, `InitHeaderSearch` pre-processes them (adds platform-specific paths, removes duplicates, removes paths that don't exist) and creates `DirectoryLookup` instances. This means we need a mechanism for translating between those two. It's not possible to go from `DirectoryLookup` back to the original `HeaderSearch`, so `InitHeaderSearch` now tracks the relationships explicitly.

Depends on D111557.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D102923
18 files changed:
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/include/clang/Lex/HeaderMap.h
clang/include/clang/Lex/HeaderSearch.h
clang/lib/Frontend/InitHeaderSearch.cpp
clang/lib/Lex/HeaderMap.cpp
clang/lib/Lex/HeaderSearch.cpp
clang/test/Preprocessor/Inputs/search-path-usage/FwA/FrameworkA.framework/Headers/FrameworkA.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/search-path-usage/FwA/FrameworkA.framework/Modules/module.modulemap [new file with mode: 0644]
clang/test/Preprocessor/Inputs/search-path-usage/FwB/FrameworkB.framework/Headers/FrameworkB.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/search-path-usage/FwB/FrameworkB.framework/Modules/module.modulemap [new file with mode: 0644]
clang/test/Preprocessor/Inputs/search-path-usage/a/a.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/search-path-usage/a_next/a.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/search-path-usage/b.hmap.json.template [new file with mode: 0644]
clang/test/Preprocessor/Inputs/search-path-usage/b/b.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/search-path-usage/d/d.h [new file with mode: 0644]
clang/test/Preprocessor/Inputs/search-path-usage/modulemap_abs/module.modulemap.template [new file with mode: 0644]
clang/test/Preprocessor/search-path-usage.m [new file with mode: 0644]