aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Lex/ModuleMap.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-06-01[clang] NFCI: Use `FileEntryRef` in `ModuleMapCallbacks`Jan Svoboda1-1/+1
This patch removes path hackery from `ModuleMapCallbacks` by adopting `FileEntryRef`. No functional change intended. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D151852
2023-05-30[clang][modules] NFCI: Extract optionality out of ↵Jan Svoboda1-2/+2
`Module::{Header,DirectoryName}` Most users of `Module::Header` already assume its `Entry` is populated. Enforce this assumption in the type system and handle the only case where this is not the case by wrapping the whole struct in `std::optional`. Do the same for `Module::DirectoryName`. Depends on D151584. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D151586
2023-05-30[clang] NFCI: Use DirectoryEntryRef in Module::DirectoryJan Svoboda1-1/+1
This patch changes the type of `Module::Directory` from `const DirectoryEntry *` to (essentially) `Optional<DirectoryEntryRef>` in order to remove uses of the deprecated `DirectoryEntry::getName()`. Depends on D127651. Reviewed By: bnbarham Differential Revision: https://reviews.llvm.org/D127654
2023-05-30[clang][lex] NFCI: Use DirectoryEntryRef in ModuleMap::parseModuleMapFile()Jan Svoboda1-7/+7
This patch changes the argument type of `ModuleMap::parseModuleMapFile()` from `const DirectoryEntry *` to `DirectoryEntryRef` in order to remove the deprecated uses of `DirectoryEntry::getName()`. Depends on D127648. Reviewed By: bnbarham Differential Revision: https://reviews.llvm.org/D127651
2023-05-30[clang][lex] NFCI: Use DirectoryEntryRef in ModuleMap::inferFrameworkModule()Jan Svoboda1-8/+6
This patch changes the argument type of `ModuleMap::inferFrameworkModule()` from `const DirectoryEntry *` to `DirectoryEntryRef` in order to remove the deprecated uses of `DirectoryEntry::getName()`. Depends on D127647. Reviewed By: bnbarham Differential Revision: https://reviews.llvm.org/D127648
2023-05-30[clang][lex] NFCI: Use FileEntryRef in ModuleMap::{load,lookup}ModuleMap()Jan Svoboda1-3/+3
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-26[clang][modules] NFCI: Use `DirectoryEntryRef` for umbrella directoryJan Svoboda1-9/+7
This removes some deprecated uses of `DirectoryEntry::getName()`. Depends on D151581. Differential Revision: https://reviews.llvm.org/D151584
2023-05-26[clang][modules] NFCI: Distinguish as-written and effective umbrella directoriesJan Svoboda1-10/+13
For modules with umbrellas, we track how they were written in the module map. Unfortunately, the getter for the umbrella directory conflates the "as written" directory and the "effective" directory (either the written one or the parent of the written umbrella header). This patch makes the distinction between "as written" and "effective" umbrella directories clearer. No functional change intended. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D151581
2023-05-09[clang] Prevent creation of new submodules in ASTWriterBen Langmuir1-2/+2
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-29re-land [C++20][Modules] Introduce an implementation module.Iain Sandoe1-8/+39
We need to be able to distinguish individual TUs from the same module in cases where TU-local entities either need to be hidden (or, for some cases of ADL in template instantiation, need to be detected as exposures). This creates a module type for the implementation which implicitly imports its primary module interface per C++20: [module.unit/8] 'A module-declaration that contains neither an export-keyword nor a module-partition implicitly imports the primary module interface unit of the module as if by a module-import-declaration. Implementation modules are never serialized (-emit-module-interface for an implementation unit is diagnosed and rejected). Differential Revision: https://reviews.llvm.org/D126959
2023-03-27Revert "[C++20][Modules] Introduce an implementation module."Mitch Phillips1-34/+8
This reverts commit c6e9823724ef6bdfee262289ee34d162db436af0. Reason: Broke the ASan buildbots, see https://reviews.llvm.org/D126959 (the original phabricator review) for more info.
2023-03-27Revert "Silence unused variable warning in NDEBUG builds"Mitch Phillips1-1/+0
This reverts commit 8c7c1f11ffaacf762e612c65440fd2cbb58ee426. Reason: Dependent change https://reviews.llvm.org/D126959 broke the ASan buildbots. See that phabricator review for more comments.
2023-03-23Silence unused variable warning in NDEBUG buildsBenjamin Kramer1-0/+1
I usually would fold this into the assert, but the comment there suggests side effects. NFC. ModuleMap.cpp:938:9: error: unused variable 'MainFile' [-Werror,-Wunused-variable] auto *MainFile = SourceMgr.getFileEntryForID(SourceMgr.getMainFileID());
2023-03-23[C++20][Modules] Introduce an implementation module.Iain Sandoe1-8/+34
We need to be able to distinguish individual TUs from the same module in cases where TU-local entities either need to be hidden (or, for some cases of ADL in template instantiation, need to be detected as exposures). This creates a module type for the implementation which implicitly imports its primary module interface per C++20: [module.unit/8] 'A module-declaration that contains neither an export-keyword nor a module-partition implicitly imports the primary module interface unit of the module as if by a module-import-declaration. Implementation modules are never serialized (-emit-module-interface for an implementation unit is diagnosed and rejected). Differential Revision: https://reviews.llvm.org/D126959
2023-03-16[clang] Unconditionally add autolink hints for frameworks.Juergen Ributzka1-23/+7
Clang infers framework autolink hints when parsing a modulemap. In order to do so, it checks if the module is a framework and if there is a framework binary or TBD file in the SDK. Only when Clang finds the filei, then the autolink hint is added to the module metadata. During a project build many clang processes perform this check, which causes many stat calls - even for modules/frameworks that are not even used. The linker is already resilient to non-existing framework links that come from the autolink metadata, so there is no need for Clang to do this check. Instead the autolink hints are now added unconditionally and the linker only needs to do the check once. This reduces the overall number of stat calls. This fixes rdar://106578342. Differential Revision: https://reviews.llvm.org/D146255
2023-03-03[C++20] [Modules] Support to export declarations in language linkageChuanqi Xu1-1/+16
Close https://github.com/llvm/llvm-project/issues/60405 See the discussion in the above link for the background. What the patch does: - Rename `Module::ModuleKind::GlobalModuleFragment` to `Module::ModuleKind::ExplicitGlobalModuleFragment`. - Add another module kind `ImplicitGlobalModuleFragment` to `ModuleKind`. - Create an implicit global module fragment for the language linkage declarations inside a module purview. - If the language linkage lives inside the scope of an export decl, the created modules is marked as exported to outer modules. - In fact, Sema will only create at most 2 implicit global module fragments to avoid creating a lot of unnecessary modules in the edging case. Reviewed By: iains Differential Revision: https://reviews.llvm.org/D144367
2023-01-31[Clang] Improve error message for violations of -fmodules-decluse.James Y Knight1-2/+3
Now it reports the name of the indirectly-used module which is missing. Reviewed By: ChuanqiXu Differential Revision: https://reviews.llvm.org/D142925
2023-01-20[clang][nfc] refactor Module::Header to use OptionalFileEntryRefRichard Howell1-7/+7
Refactor the `Module::Header` class to use an `OptionalFileEntryRef` instead of a `FileEntry*`. This is preparation for refactoring the `TopHeaderNames` to use `FileEntryRef` so that we preserve the lookup path of the headers when serializing. This is mostly based on https://reviews.llvm.org/D90497 Reviewed By: jansvoboda11 Differential Revision: https://reviews.llvm.org/D142113
2023-01-14[clang] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata1-2/+2
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". 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
2023-01-14[clang] Add #include <optional> (NFC)Kazu Hirata1-0/+1
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with 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-12-20[Clang] Prepare for llvm::Optional becoming std::optional.Benjamin Kramer1-6/+6
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-3/+2
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-2/+3
2022-12-17llvm::Optional::value => operator*/operator->Fangrui Song1-2/+2
std::optional::value() has undesired exception checking semantics and is unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The call sites block std::optional migration. This makes `ninja clang` work in the absence of llvm::Optional::value.
2022-12-10Don't include None.h (NFC)Kazu Hirata1-1/+0
I've converted all known uses of None to std::nullopt, so we no longer need to include None.h. 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-6/+6
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-12-01[clang][deps][lex] Avoid canonicalization of remapped framework directoriesJan Svoboda1-3/+10
In D134923, the scanner introduced canonicalization of framework directories when reporting module map paths in order to increase module sharing. However, if we canonicalize framework directory that plays a role in a VFS remapping, and later try to use that module map to build the module, header lookup can fail. This happens when the module headers are remapped using the original framework path. This patch fixes that. The implementation relies on the fact that the chain of directories in VFS remapping are assigned `DirectoryEntry` objects distinct from their on-disk counterparts. If we detect that case, we avoid the canonicalization. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D135841
2022-11-18[C++20] [Modules] Remove unmaintained Header ModuleChuanqi Xu1-23/+0
Currently there is a -emit-header-module mode, which can combine several headers together as a module interface. However, this breaks our assumption (for standard c++ modules) about module interface. The module interface should come from a module interface unit. And if it is a header, it should be a header unit. And currently we have no ideas to combine several headers together. So I think this mode is an experimental one and it is not maintained and it is not used. So it will be better to remove them. Reviewed By: Bigcheese, dblaikie, bruno Differential Revision: https://reviews.llvm.org/D137609
2022-11-15[NFC] [C++20] [Modules] Remove unused Global Module Fragment variables/argumentsChuanqi Xu1-2/+1
2022-10-06[clang][modules] Fix handling of `ModuleHeaderRole::ExcludedHeader`Jan Svoboda1-23/+28
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-0/+36
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-10/+14
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/+10
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-30[clang][modules] Don't hard code [no_undeclared_includes] for the Darwin moduleIan Anderson1-2/+1
The Darwin module has specified [no_undeclared_includes] for at least five years now, there's no need to hard code it in the compiler. Reviewed By: ributzka, Bigcheese Differential Revision: https://reviews.llvm.org/D132971
2022-08-08[clang] LLVM_FALLTHROUGH => [[fallthrough]]. NFCFangrui Song1-1/+1
With C++17 there is no Clang pedantic warning or MSVC C5051. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D131346
2022-07-22Use any_of (NFC)Kazu Hirata1-4/+2
2022-07-13[clang] Use value instead of getValue (NFC)Kazu Hirata1-2/+2
2022-06-25Revert "Don't use Optional::hasValue (NFC)"Kazu Hirata1-2/+2
This reverts commit aa8feeefd3ac6c78ee8f67bf033976fc7d68bc6d.
2022-06-25Don't use Optional::hasValue (NFC)Kazu Hirata1-2/+2
2022-04-20[clang][lex] NFCI: Use FileEntryRef in ModuleMap::diagnoseHeaderInclusion()Jan Svoboda1-3/+2
This patch removes uses of the deprecated `DirectoryEntry::getName()` from the `ModuleMap::diagnoseHeaderInclusion()` function by using `{File,Directory}EntryRef` instead. Reviewed By: bnbarham Differential Revision: https://reviews.llvm.org/D123856
2022-03-25[C++20][Modules][HU 1/5] Introduce header units as a module type.Iain Sandoe1-0/+13
This is the first in a series of patches that introduce C++20 importable header units. These differ from clang header modules in that: (a) they are identifiable by an internal name (b) they represent the top level source for a single header - although that might include or import other headers. We name importable header units with the path by which they are specified (although that need not be the absolute path for the file). So "foo/bar.h" would have a name "foo/bar.h". Header units are made a separate module type so that we can deal with diagnosing places where they are permitted but a named module is not. Differential Revision: https://reviews.llvm.org/D121095
2022-03-02[NFC][Lexer] Remove getLangOpts function from LexerDawid Jurczak1-1/+1
Given that there is only one external user of Lexer::getLangOpts we can remove getter entirely without much pain. Differential Revision: https://reviews.llvm.org/D120404
2022-03-01[clang] Improve laziness of resolving module map headers.Adam Czachorowski1-9/+19
clang has support for lazy headers in module maps - if size and/or modtime and provided in the cppmap file, headers are only resolved when an include directive for a file with that size/modtime is encoutered. Before this change, the lazy resolution was all-or-nothing per module. That means as soon as even one file in that module potentially matched an include, all lazy files in that module were resolved. With this change, only files with matching size/modtime will be resolved. The goal is to avoid unnecessary stat() calls on non-included files, which is especially valuable on networked file systems, with higher latency. Differential Revision: https://reviews.llvm.org/D120569
2021-12-08[C++20] [Module] Support extern C/C++ semanticsChuanqi Xu1-6/+10
According to [module.unit]p7.2.3, a declaration within a linkage-specification should be attached to the global module. This let user to forward declare types across modules. Reviewed by: rsmith, aaron.ballman Differential Revision: https://reviews.llvm.org/D110215
2021-11-07[clang] Use llvm::reverse. NFCI.Benjamin Kramer1-8/+7
2021-10-24Use llvm::is_contained (NFC)Kazu Hirata1-3/+2
2021-10-15[modules] Make a module map referenced by a system map a system one too.Volodymyr Sapsai1-1/+1
Mimic the behavior of including headers where a system includer makes an includee a system header too. rdar://84049469 Differential Revision: https://reviews.llvm.org/D111476
2021-10-13[clang] Use llvm::is_contained (NFC)Kazu Hirata1-3/+2
2021-09-14Cleanup identifier parsing; NFCCorentin Jabot1-2/+2
Rename methods to clearly signal when they only deal with ASCII, simplify the parsing of identifier, and use start/continue instead of head/body for consistency with Unicode terminology.
2021-07-21[clang] Introduce SourceLocation::[U]IntTy typedefs.Simon Tatham1-1/+1
This is part of a patch series working towards the ability to make SourceLocation into a 64-bit type to handle larger translation units. NFC: this patch introduces typedefs for the integer type used by SourceLocation and makes all the boring changes to use the typedefs everywhere, but for the moment, they are unconditionally defined to uint32_t. Patch originally by Mikhail Maltsev. Reviewed By: tmatheson Differential Revision: https://reviews.llvm.org/D105492