aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/HeaderSearch.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-06-15[clang] Use `{File,Directory}EntryRef` in modular header search (part 2/2)Jan Svoboda1-4/+4
This patch removes some deprecated uses of `{File,Directory}Entry::getName()`. No functional change intended. Depends on D151854. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D151855
2023-06-01[clang] Use `FileEntryRef` in modular header search (part 1/2)Jan Svoboda1-20/+19
This patch removes some deprecated uses of `{File,Directory}Entry::getName()`. No functional change indended. Depends on D151853. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D151854
2023-06-01[clang] NFCI: Split `HeaderSearch::findAllModulesForHeader()`Jan Svoboda1-3/+12
This mimics the `ModuleMap` API and enables D151854, where the `AllowCreation = true` function needs `FileEntryRef` but `AllowCreation = false` functions is happy with plain `FileEntry`. No functional change intended. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D151853
2023-06-01[clang] NFC, make more HeaderSearch methods const.Haojian Wu1-1/+1
2023-06-01[clang][NFC] Make HeaderSearch::suggestPathToFileForDiagnostics method const.Haojian Wu1-2/+2
2023-05-31[clang] NFCI: Use `DirectoryEntryRef` in framework lookupJan Svoboda1-1/+1
This removes one use of the deprecated `DirectoryEntry::getName()`.
2023-05-31[clang] NFCI: Use the `*Ref()` variant on search pathsJan Svoboda1-9/+8
This removes some uses of the deprecated `DirectoryEntry::getName()`.
2023-05-30[clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::LookupFileJan Svoboda1-5/+5
This patch changes the argument type to `HeaderSearch::LookupFile()` from `const DirectoryEntry *` to `DirectoryEntryRef` in order to remove some calls to the deprecated `DirectoryEntry::getName()`. Depends on D127660. Reviewed By: bnbarham, benlangmuir Differential Revision: https://reviews.llvm.org/D127663
2023-05-30[clang][lex] NFCI: Use FileEntryRef in ModuleMap::{load,lookup}ModuleMap()Jan Svoboda1-18/+15
This patch changes the return/argument types of `ModuleMap::{load,lookup}ModuleMap()` from `const FileEntry *` to `FileEntryRef` in order to remove uses of the deprecated `DirectoryEntry::getName()`. Reviewed By: bnbarham Differential Revision: https://reviews.llvm.org/D127647
2023-05-28[clang][HeaderSearch] Fix implicit module when using header mapsIvan Murashko1-3/+9
Previously, if a header was found via in a header map, and not just remapped. we wouldn't also find the module it maps to when using implicit modules (for module maps that were explicitly loaded). This diff just updates these code paths to also locate the owning module via `findUsableModuleForHeader`. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D103930
2023-05-09[clang] Prevent creation of new submodules in ASTWriterBen Langmuir1-2/+3
Avoid inferring new submodules for headers in ASTWriter's collection of affecting modulemap files, since we don't want to pick up dependencies that didn't actually exist during parsing. rdar://109112624 Differential Revision: https://reviews.llvm.org/D150151
2023-03-16[clang][Lexer] Fix crash/assert clang::HeaderSearch::search_dir_nthDmitry Polukhin1-7/+6
The issue was introduced in D135801. When there are only header maps in the SearchDirs, the out of bounds value is assigned to FirstNonHeaderMapSearchDirIdx. Test Plan: check-clang Differential Revision: https://reviews.llvm.org/D146156
2022-12-20[Clang] Prepare for llvm::Optional becoming std::optional.Benjamin Kramer1-14/+14
The needed tweaks are mostly trivial, the one nasty bit is Clang's usage of OptionalStorage. To keep this working old Optional stays around as clang::CustomizableOptional, with the default Storage removed. Optional<File/DirectoryEntryRef> is replaced with a typedef. I tested this with GCC 7.5, the oldest supported GCC I had around. Differential Revision: https://reviews.llvm.org/D140332
2022-12-18Revert "[clang] Convert OptionalFileEntryRefDegradesToFileEntryPtr to ↵Krzysztof Parzyszek1-13/+12
std::optional" This reverts commit 8f0df9f3bbc6d7f3d5cbfd955c5ee4404c53a75d. The Optional*RefDegradesTo*EntryPtr types want to keep the same size as the underlying type, which std::optional doesn't guarantee. For use with llvm::Optional, they define their own storage class, and there is no way to do that in std::optional. On top of that, that commit broke builds with older GCCs, where std::optional was not trivially copyable (static_assert in the clang sources was failing).
2022-12-17[clang] Convert OptionalFileEntryRefDegradesToFileEntryPtr to std::optionalKrzysztof Parzyszek1-12/+13
2022-12-04[clang] Use std::nullopt instead of None in comments (NFC)Kazu Hirata1-1/+2
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03[clang] Use std::nullopt instead of None (NFC)Kazu Hirata1-18/+18
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-28Reland "[Lex] Fix suggested spelling of /usr/bin/../include/foo"Sam McCall1-17/+13
This reverts commit 1dc0a1e5d220b83c1074204bd3afd54f3bac4270. Failures were caused by unintentional conversion to native slashes by remove_dots, so undo that: we always suggest posix slashes for includes. This could potentially be a change in behavior on windows if people were spelling headers with backslashes and headermaps contained backslashes, but that's all underspecified and I don't think anyone uses headermaps on windows. Differential Revision: https://reviews.llvm.org/D138709
2022-11-25Revert "[Lex] Fix suggested spelling of /usr/bin/../include/foo"Sam McCall1-9/+17
This reverts commit 8bed59c7e7da2fea41a9167e15c15a8f58a5ede7. Breaks bots e.g. https://lab.llvm.org/buildbot/#/builders/216/builds/13282
2022-11-25[Lex] Fix suggested spelling of /usr/bin/../include/fooSam McCall1-17/+9
Since D60873 we remove dotdots from the search path entries, but not the filenames we're matching against, so do the latter too. Since this also removes (single) dots, drop the logic to skip over them. (Some of this was already dead, some is newly dead). See D138676 for motivation. Differential Revision: https://reviews.llvm.org/D138677
2022-11-01[clang][Lex] Header map search case insensitivityTroy Johnson1-2/+4
Correct D135801 to be case insensitive. Differential Revision: https://reviews.llvm.org/D137179
2022-10-27[NFC] [Modules] Rename modules related things in Preprocessor and ↵Chuanqi Xu1-1/+1
AffectingModules Rename module related things according to the consensus in https://discourse.llvm.org/t/rfc-unifying-the-terminology-about-modules-in-clang/66054/ to reduce further confusings. This only renames things I can make sure. It doesn't mean all the names in Preprocessor are correct now.
2022-10-20[clang][lex] Avoid `DirectoryLookup` copiesJan Svoboda1-1/+1
This patch fixes a performance regression introduced in D121685 that was caused by copying `DirectoryLookup`. rdar://101206790 Reviewed By: ributzka Differential Revision: https://reviews.llvm.org/D136019
2022-10-18[clang][Lexer] Speed up HeaderSearch when there are many HeaderMapsTroy Johnson1-16/+53
HeaderSearch already uses a caching system to avoid duplicate searches, but the initial cold miss can take a long time if a build system has supplied thousands of HeaderMaps. For this case, the SearchDirs vector begins with those HeaderMaps, so a cache miss requires testing if the sought filename is present in each of those maps. Instead, we can consolidate the keys of those HeaderMaps into one StringMap and then each cache miss can skip directly to the correct HeaderMap or continue its search beyond the initial sequence of HeaderMaps. In testing on TUs with ~15000 SearchDirs where the initial 99% are HeaderMaps, time spent in Clang was reduced by 15%. This patch is expected to be neutral for SearchDir vectors that do not begin with HeaderMaps. Differential Revision: https://reviews.llvm.org/D135801
2022-10-06[clang][modules] Fix handling of `ModuleHeaderRole::ExcludedHeader`Jan Svoboda1-1/+1
This is a follow-up to D134224. The original patch added new `ExcludedHeader` enumerator to `ModuleMap::ModuleHeaderRole` and started associating headers with the modules they were excluded from. This was necessary to consider their module maps as "affecting" in certain situations and in turn serialize them into the PCM. The association of the header and module needs to be handled when deserializing the PCM as well, though. This patch fixes a potential assertion failure and a regression. This essentially reverts parts of feb54b6ded123f8118fdc20620d3f657dfeab485. Reviewed By: Bigcheese Differential Revision: https://reviews.llvm.org/D135381
2022-10-05[clang][deps] Canonicalize module map pathBen Langmuir1-10/+3
When dep-scanning, canonicalize the module map path as much as we can. This avoids unnecessarily needing to build multiple versions of a module due to symlinks or case-insensitive file paths. Despite the name `tryGetRealPathName`, the previous implementation did not actually return the realpath most of the time, and indeed it would be incorrect to do so since the realpath could be outside the module directory, which would have broken finding headers relative to the module. Instead, use a canonicalization that is specific to the needs of modulemap files (canonicalize the directory separately from the filename). Differential Revision: https://reviews.llvm.org/D134923
2022-10-05[clang] Update ModuleMap::getModuleMapFile* to use FileEntryRefBen Langmuir1-3/+3
Update SourceManager::ContentCache::OrigEntry to keep the original FileEntryRef, and use that to enable ModuleMap::getModuleMapFile* to return the original FileEntryRef. This change should be NFC for most users of SourceManager::ContentCache, but it could affect behaviour for users of getNameAsRequested such as in compileModuleImpl. I have not found a way to detect that difference without additional functional changes, other than incidental cases like changes from / to \ on Windows so there is no new test. Differential Revision: https://reviews.llvm.org/D135220
2022-09-22[clang][modules][deps] Report modulemaps describing excluded headersJan Svoboda1-3/+3
Module map files describing excluded headers do affect compilation. Track them in the compiler, serialize them into the PCM file and report them in the scanner. Depends on D134222. Reviewed By: Bigcheese Differential Revision: https://reviews.llvm.org/D134224
2022-08-24[clang][modules] Track affecting modulesJan Svoboda1-0/+2
When compiling a module, its semantics and Clang's behavior are affected by other modules. These modules are typically the **imported** ones. However, during implicit build, some modules end up being compiled and read without being actually imported. This patch starts tracking such modules and serializing them into `.pcm` files. This enables the dependency scanner to construct explicit compilations that mimic implicit build. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D132430
2022-08-06[Clang][Lex] Extend HeaderSearch::LookupFile to control OpenFile behavior.Jun Zhang1-11/+14
In the case of static compilation the file system is pretty much read-only and taking a snapshot of it usually is sufficient. In the interactive C++ case the compilation is longer and people can create and include files, etc. In that case we often do not want to open files or cache failures unless is absolutely necessary. This patch extends the original API call by forwarding some optional flags, so we can continue use it in the previous way with no breakage. Signed-off-by: Jun Zhang <jun@junz.org> Differential Revision: https://reviews.llvm.org/D131241
2022-06-20Don't use Optional::hasValue (NFC)Kazu Hirata1-1/+1
2022-06-13Reapply "[clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::load*()"Jan Svoboda1-35/+36
This reverts commit 340654e0f246cddb3fb6ebddb843ade9bfcff0a5, essentially reapplying 1d3ba05e4a288b49287fe997763e90234b8c62db. The test VFS/real-path-found-first.m that was failing on Windows is now passing with a workaround.
2022-06-11fix comment typo to cycle botsNico Weber1-1/+1
2022-05-04[clang] Track how headers get included generally during lookup timeCyndy Ishida1-1/+11
tapi & clang-extractapi both attempt to construct then check against how a header was included to determine api information when working against multiple search paths, headermap, and vfsoverlay mechanisms. Validating this against what the preprocessor sees during lookup time makes this check more reliable. Reviewed By: zixuw, jansvoboda11 Differential Revision: https://reviews.llvm.org/D124638
2022-04-20Revert "[clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::load*()"Jan Svoboda1-34/+35
This reverts commit 1d3ba05e4a288b49287fe997763e90234b8c62db which caused failures of the VFS/real-path-found-first.m test on Windows build bots.
2022-04-20[clang][lex] NFCI: Use DirectoryEntryRef in FrameworkCacheEntryJan Svoboda1-5/+5
This patch changes the member of `FrameworkCacheEntry` from `const DirectoryEntry *` to `Optional<DirectoryEntryRef>` in order to remove uses of the deprecated `DirectoryEntry::getName()`. Reviewed By: bnbarham Differential Revision: https://reviews.llvm.org/D123854
2022-04-20[clang][lex] NFCI: Use DirectoryEntryRef in HeaderSearch::load*()Jan Svoboda1-35/+34
This patch removes uses of the deprecated `DirectoryEntry::getName()` from `HeaderSearch::load*()` functions by using `DirectoryEntryRef` instead. Note that we bail out in one case and use the also deprecated `FileEntry::getLastRef()`. That's to prevent this patch from growing, and is addressed in a follow-up. Reviewed By: bnbarham Differential Revision: https://reviews.llvm.org/D123771
2022-04-08[clang][deps] Ensure deterministic filename caseJan Svoboda1-2/+2
The dependency scanner can reuse single FileManager instance across multiple translation units. This may lead to non-deterministic output depending on which TU gets processed first. One of the problems is that Clang uses DirectoryEntry::getName in the header search algorithm. This function returns the path that was first used to construct the (shared) entry in FileManager. Using DirectoryEntryRef::getName instead preserves the case as it was spelled out for the current "get directory entry" request. rdar://90647508 Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D123229
2022-03-31[C++20] [Modules] Use '-' as the separator of partitions when searchingChuanqi Xu1-1/+10
in filesystems It is simpler to search for module unit by -fprebuilt-module-path option. However, the separator ':' of partitions is not friendly. According to the discussion in https://reviews.llvm.org/D118586, I think we get consensus to use '-' as the separator instead. The '-' is the choice of GCC too. Previously I thought it would be better to add an option. But I feel it is over-engineering now. Another reason here is that there are too many options for modules (for clang module mainly) now. Given it is not bad to use '-' when searching, I think it is acceptable to not add an option. Reviewed By: iains Differential Revision: https://reviews.llvm.org/D120874
2022-03-23[clang][lex] Fix failures with Microsoft header search rulesJan Svoboda1-1/+2
`HeaderSearch` currently assumes `LookupFileCache` is eventually populated in `LookupFile`. However, that's not always the case with `-fms-compatibility` and its early returns. This patch adds a defensive check that the iterator pulled out of the cache is actually valid before using it. (This bug was introduced in D119721. Before that, the cache was initialized to `0` - essentially the `search_dir_begin()` iterator.) Reviewed By: dexonsmith, erichkeane Differential Revision: https://reviews.llvm.org/D122237
2022-03-16[clang][deps] NFC: Use range-based for loop instead of iteratorsJan Svoboda1-11/+10
The iterator is not needed after the loop body anymore, meaning we can use more terse range-based for loop. Depends on D121295. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D121685
2022-03-16[clang][deps] Modules don't contribute to search path usageJan Svoboda1-3/+0
To reduce the number of modules we build in explicit builds (which use strict context hash), we prune unused header search paths. This essentially merges parts of the dependency graph. Determining whether a search path was used to discover a module (through implicit module maps) proved to be somewhat complicated. Initial support landed in D102923, while D113676 attempts to fix some bugs. However, now that we don't use implicit module maps in explicit builds (since D120465), we don't need to consider such search paths as used anymore. Modules are no longer discovered through the header search mechanism, so we can drop such search paths (provided they are not needed for other reasons). This patch removes whatever support for detecting such usage we had, since it's buggy and not required anymore. Depends on D120465. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D121295
2022-02-15[clang][lex] Use `SearchDirIterator` types in for loopsJan Svoboda1-49/+36
This patch replaces a lot of index-based loops with iterators and ranges. Depends on D117566. Reviewed By: ahoppen Differential Revision: https://reviews.llvm.org/D119722
2022-02-15[clang][lex] Use `ConstSearchDirIterator` in lookup cacheJan Svoboda1-14/+18
This patch starts using the new iterator type in `LookupFileCacheInfo`. Depends on D117566. Reviewed By: ahoppen Differential Revision: https://reviews.llvm.org/D119721
2022-02-15[clang][lex] Introduce `ConstSearchDirIterator`Jan Svoboda1-5/+10
The `const DirectoryLookup *` out-parameter of `{HeaderSearch,Preprocessor}::LookupFile()` is assigned the most recently used search directory, which callers use to implement `#include_next`. From the function signature it's not obvious the `const DirectoryLookup *` is being used as an iterator. This patch introduces `ConstSearchDirIterator` to make that affordance obvious. This would've prevented a bug that occurred after initially landing D116750. Reviewed By: ahoppen Differential Revision: https://reviews.llvm.org/D117566
2022-02-11[C++20] [Modules] Check if modulemap exists to avoid crash in implicit used ↵ZezhengLi1-0/+4
C++ module An impilt used of C++ module without prebuild path may cause crash. For example: ``` // ./dir1/C.cppm export module C; // ./dir2/B.cppm export module B; import C; // ./A.cpp import B; import C; ``` When we compile A.cpp without the prebuild path of C.pcm, the compiler will crash. ``` clang++ -std=c++20 --precompile -c ./dir1/C.cppm -o ./dir1/C.pcm clang++ -std=c++20 --precompile -fprebuilt-module-path=./dir2 -c ./dir2/B.cppm -o ./dir2/B.pcm clang++ -std=c++20 -fprebuilt-module-path=./dir2 A.cpp ``` The prebuilt path of module C is cached when import module B, and in the function HeaderSearch::getCachedModuleFileName, the compiler try to get the filename by modulemap without check if modulemap exists, and there is no modulemap in C++ module. Reviewed By: ChuanqiXu Differential review: https://reviews.llvm.org/D119426
2022-02-04[HeaderSearch] Track framework name in LookupFileDavid Goldman1-2/+8
Previously, the Framework name was only set if the file came from a header mapped framework; now we'll always set the framework name if the file is in a framework. Differential Revision: https://reviews.llvm.org/D117830
2022-01-26[clang][lex] Include tracking: simplify and move to preprocessorJan Svoboda1-15/+5
This patch replaces the exact include count of each file in `HeaderFileInfo` with a set of included files in `Preprocessor`. The number of includes isn't a property of a header file but rather a preprocessor state. The exact number of includes is not used anywhere except statistic tracking. Reviewed By: vsapsai Differential Revision: https://reviews.llvm.org/D114095
2022-01-18[clang][lex] NFC: Simplify calls to `LookupFile`Jan Svoboda1-2/+5
The `{HeaderSearch,Preprocessor}::LookupFile()` functions take an out-parameter `const DirectoryLookup *&`. Most callers end up creating a `const DirectoryLookup *` variable that's otherwise unused. This patch changes the out-parameter from reference to a pointer, making it possible to simply pass `nullptr` to the function without the ceremony. Reviewed By: ahoppen Differential Revision: https://reviews.llvm.org/D117312
2022-01-13Revert "[clang][lex] Keep references to `DirectoryLookup` objects up-to-date"Jan Svoboda1-60/+53
This reverts commit 8503c688. This patch causes some issues with `#include_next`: https://github.com/llvm/llvm-project/issues/53161