aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/Module.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-05-31[Basic] Remove unused includes (NFC) (#142295)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-04-19[clang] Use llvm::SmallVector::pop_back_val (NFC) (#136451)Kazu Hirata1-2/+1
2025-02-21[clang][modules] Fix local submodule visibility of macros from transitive ↵Ben Langmuir1-7/+10
import (#122955) When we mark a module visible, we normally mark all of its non-explicit submodules and other exports as visible. However, when we first enter a submodule we should not make them visible to the submodule itself until they are actually imported. Marking exports visible before import would cause bizarre behaviour with local submodule visibility, because it happened before we discovered the submodule's transitive imports and could fail to make them visible in the parent module depending on whether the submodules involved were explicitly defined (module X) or implicitly defined from an umbrella (module *). rdar://136524433
2024-10-28[clang][modules] Optimize construction and usage of the submodule index ↵Jan Svoboda1-5/+7
(#113391) This patch avoids eagerly populating the submodule index on `Module` construction. The `StringMap` allocation shows up in my profiles of `clang-scan-deps`, while the index is not necessary most of the time. We still construct it on-demand. Moreover, this patch avoids performing qualified submodule lookup in `ASTReader` whenever we're serializing a module graph whose top-level module is unknown. This is pointless, since that's guaranteed to never find any existing submodules anyway. This speeds up `clang-scan-deps` by ~0.5% on my workload.
2024-10-25[clang][modules] Shrink the size of `Module::Headers` (#113395)Jan Svoboda1-1/+1
This patch shrinks the size of the `Module` class from 2112B to 1624B. I wasn't able to get a good data on the actual impact on memory usage, but given my `clang-scan-deps` workload at hand (with tens of thousands of instances), I think there should be some win here. This also speeds up my benchmark by under 0.1%.
2024-10-22[clang] Allocate `Module` instances in `BumpPtrAllocator` (#112795)Jan Svoboda1-22/+4
In `clang-scan-deps`, we're creating lots of `Module` instances. Allocating them all in a bump-pointer allocator reduces the number of retired instructions by 1-1.5% on my workload.
2024-09-19[clang] Don't call raw_string_ostream::flush() (NFC)Youngsuk Kim1-1/+0
Don't call raw_string_ostream::flush(), which is essentially a no-op. As specified in the docs, raw_string_ostream is always unbuffered
2024-06-03[clang][Modules] Move `ASTSourceDescriptor` into its own file (#67930)David Stone1-15/+0
2024-05-05[clang][Modules] Make `Module::Requirement` a struct (NFC) (#67900)David Stone1-5/+5
`Module::Requirement` was defined as a `std::pair<std::string, bool>`. This required a comment to explain what the data members mean and makes the usage harder to understand. Replace this with a struct with two members, `FeatureName` and `RequiredState`. --------- Co-authored-by: cor3ntin <corentinjabot@gmail.com>
2024-04-12[modules] allow use of ptrauth module from no_undeclared_includes system ↵Ian Anderson1-0/+4
modules (#88432) Co-authored-by: Alex Lorenz <arphaman@gmail.com>
2024-03-13[clang][modules] giving the __stddef_ headers their own modules can cause ↵Ian Anderson1-4/+3
redeclaration errors with -fbuiltin-headers-in-system-modules (#84127) On Apple platforms, some of the stddef.h types are also declared in system headers. In particular NULL has a conflicting declaration in <sys/_types/_null.h>. When that's in a different module from <__stddef_null.h>, redeclaration errors can occur. Make the \_\_stddef_ headers be non-modular in -fbuiltin-headers-in-system-modules and restore them back to not respecting their header guards. Still define the header guards though. __stddef_max_align_t.h was in _Builtin_stddef_max_align_t prior to the addition of _Builtin_stddef, and it needs to stay in a module because struct's can't be type merged. __stddef_wint_t.h didn't used to have a module, but leave it in it current module since it doesn't really belong to stddef.h.
2024-03-06[C++20] [Modules] Handle transitive import in the module properlyChuanqi Xu1-8/+0
Close https://github.com/llvm/llvm-project/issues/84002 Per [module.import]p7: > Additionally, when a module-import-declaration in a module unit of > some module M imports another module unit U of M, it also imports all > translation units imported by non-exported module-import-declarations > in the module unit purview of U. However, we only tried to implement it during the implicit import of primary module interface for module implementation unit. Also we didn't implement the last sentence from [module.import]p7 completely: > These rules can in turn lead to the importation of yet more > translation units. This patch tries to care the both issues.
2024-02-11[NFC] Correct C++ standard names (#81421)Danny Mösch1-2/+2
2023-12-13[clang] Use StringRef::{starts,ends}_with (NFC) (#75149)Kazu Hirata1-1/+2
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-12-09[ADT] Rename SmallString::{starts,ends}with to {starts,ends}_with (#74916)Kazu Hirata1-1/+1
This patch renames {starts,ends}with to {starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. Since there are only a handful of occurrences, this patch skips the deprecation phase and simply renames them.
2023-11-01[clang][modules] Don't prevent translation of FW_Private includes when ↵Jan Svoboda1-3/+4
explicitly building FW (#70714) We prevent translating `#include <FW/PrivateHeader.h>` into an import of FW_Private when compiling the implementation of FW or FW_Private. This is specified via `-fmodule-name=` on the TU command line (used to be `-fmodule-implementation-of`). This logic is supposed to only kick in when imported directly from a TU, but it currently also kicks in when compiling the public FW module explicitly (since it also has `-fmodule-name=` on the command line). This patch makes sure this logic only kicks in for the case that used to be `-fmodule-implementation-of` (for the TU), and not for all `-fmodule-name=` cases (especially for the explicit compile of a module). rdar://101051277; related: rdar://37500098&38434694
2023-10-20[clang][modules] Use file name as requested (#68957)Jan Svoboda1-4/+4
This prevents redefinition errors due to having multiple paths for the same module map. (rdar://24116019) Originally implemented and tested downstream by @bcardosolopes, I just made use of `FileEntryRef::getNameAsRequested()`.
2023-10-04[Modules] no_undeclared_includes modules (Apple Darwin) don't work the clang ↵Ian Anderson1-1/+2
modules (#68241) All of the _Builtin_stdarg and _Builtin_stddef submodules need to be allowed from [no_undeclared_includes] modules. Split the builtin headers tests out from the compiler_builtins test so that the testing modules can be modified without affecting the other many tests that use Inputs/System/usr/include.
2023-10-03[Modules] Make clang modules for the C standard library headersIan Anderson1-2/+3
Make top level modules for all the C standard library headers. The `__stddef` implementation headers need header guards now that they're all modular. stdarg.h and stddef.h will be textual headers in the builtin modules, and so need to be repeatedly included in both the system and builtin module case. Define their header guards for consistency, but ignore them when building with modules. `__stddef_null.h` needs to ignore its header guard when modules aren't being used to fulfill its redefinition obligation. `__stddef_nullptr_t.h` needs to add a guard for C23 so that `_Builtin_stddef` can compile in C17 and earlier modes. `_Builtin_stddef.nullptr_t` can't require C23 because it also needs to be usable from C++. Reviewed By: Bigcheese Differential Revision: https://reviews.llvm.org/D159064
2023-09-29[NFC] [C++20] [Modules] Rename NamedModuleHasInit to NamedModuleHasInitChuanqi Xu1-1/+1
Address comments in https://github.com/llvm/llvm-project/pull/67638/files#r1340342453 to rename the field variable.
2023-09-28[C++20] [Modules] Don't generate call to an imported module that dont init ↵Chuanqi Xu1-1/+1
anything (#67638) Close https://github.com/llvm/llvm-project/issues/56794 And see https://github.com/llvm/llvm-project/issues/67582 for a detailed backgrond for the issue. As required by the Itanium ABI, the module units have to generate the initialization function. However, the importers are allowed to elide the call to the initialization function if they are sure the initialization function doesn't do anything. This patch implemented this semantics.
2023-09-28[NFC] [C++20] [Modules] Refactor Module::getGlobalModuleFragment and ↵Chuanqi Xu1-0/+22
Module::getPrivateModuleFragment The original implementation of `Module::getGlobalModuleFragment` and `Module::getPrivateModuleFragment` tried to find the global module fragment and the private module fragment by comparing strings, which smells bad. This patch tries to improve this.
2023-08-29[clang][modules] Add a c23 module featureIan Anderson1-0/+1
Add a c23 module feature for `requires`. Reviewed By: ChuanqiXu, v.g.vassilev, aaron.ballman Differential Revision: https://reviews.llvm.org/D159018
2023-07-11[clang] Implement `PointerLikeTraits` for `{File,Directory}EntryRef`Jan Svoboda1-4/+4
This patch implements `llvm::PointerLikeTraits<FileEntryRef>` and `llvm::PointerLikeTraits<DirectoryEntryRef>`, allowing some simplifications around umbrella header/directory code. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D154905
2023-06-25[C++20][Modules] Complete implementation of module.import p7.Iain Sandoe1-0/+8
The following test fails to compile TU b.cpp because we are not making the transitively imported modules visible (per [module.import]/p7) ``` a.cppm: export module a; export int foo() { return 42; } b.cppm: export module b; import a; export int bar(); b.cpp: module b; int bar() { return foo(); } clang++ -c -std=c++2b -fmodule-output a.cppm clang++ -c -std=c++2b -fmodule-output -fprebuilt-module-path=. b.cppm clang++ -c -std=c++2b -fprebuilt-module-path=. b.cpp b.cpp:4:12: error: declaration of 'foo' must be imported from module 'a' before it is required return foo(); ``` This is fixed by the following patch (which also addresses a FIXME in basic.def.odr/p6.cppm). Differential Revision: https://reviews.llvm.org/D152746
2023-06-15[clang][index] NFCI: Make `CXFile` a `FileEntryRef`Jan Svoboda1-6/+4
This patch swaps out the `void *` behind `CXFile` from `FileEntry *` to `FileEntryRef::MapEntry *`. This allows us to remove some deprecated uses of `FileEntry::getName()`. Depends on D151854. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D151938
2023-05-30[clang][modules] NFCI: Extract optionality out of ↵Jan Svoboda1-6/+6
`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-26[clang][modules] NFCI: Use `DirectoryEntryRef` for umbrella directoryJan Svoboda1-4/+4
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-8/+8
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-17[clang][modules] Add features for recent C++ versionsJonas Hahnfeld1-0/+3
Add cplusplus20, cplusplus23, and cplusplus26 (but don't document the latter, following the current policy). Differential Revision: https://reviews.llvm.org/D150773
2023-04-24[clang] Make access to submodules via `iterator_range`Stoorx1-12/+8
In file `clang/lib/Basic/Module.cpp` the `Module` class had `submodule_begin()` and `submodule_end()` functions to retrieve corresponding iterators for private vector of Modules. This commit removes mentioned functions, and replaces all of theirs usages with `submodules()` function and range-based for-loops. Differential Revision: https://reviews.llvm.org/D148954
2023-01-20[clang][modules] Disallow importing private framework in the implementationJan Svoboda1-0/+20
Whenever we are compiling implementation of a framework (with the `-fmodule-name=FW` option), we never translate `#import <FW/Header.h>` to an import, regardless of whether "Header.h" belongs to "FW" or "FW_Private". For the same reasons, we also disallow `@import FW`. However, we still allow `@import FW_Private`. This patch disallows that a well, to be consistent with the rest of the rules. Reviewed By: benlangmuir Differential Revision: https://reviews.llvm.org/D142167
2023-01-09Move from llvm::makeArrayRef to ArrayRef deduction guides - clang/ partserge-sans-paille1-1/+1
This is a follow-up to https://reviews.llvm.org/D140896, split into several parts as it touches a lot of files. Differential Revision: https://reviews.llvm.org/D141139
2022-11-15[C++20] [Modules] Attach implicitly declared allocation funcitons toChuanqi Xu1-1/+3
global module fragment [basic.stc.dynamic.general]p2 says: > The library provides default definitions for the global allocation > and deallocation functions. Some global allocation and > deallocation > functions are replaceable ([new.delete]); these are attached to > the global module ([module.unit]). But we didn't take this before and the implicitly generated functions will live in the module purview if we're compiling a module unit. This is bad since the owning module will affect the linkage of the declarations. This patch addresses this. Closes https://github.com/llvm/llvm-project/issues/58560
2022-10-17[modules] Fix callback argument thinkoNathan Sidwell1-1/+1
VisbleModuleSet::setVisible takes a callback, to inform of modules being made (transitively) visible. However, we were calling it as 'Vis(M)' from a recursive lambda, where 'M' is a capture of setVisible's M, module parameter. Thus we can invoke the callback multiple times, passing the same value to it each time. Everywhere else in the lambda, we refer to V.M of the lambda's Visiting parameter. We should be doing so for the callback. Thus we'll pass the outermost module on the outermost recursive call, and as we descend the imports, we'll pass each import to the callback. Reviewed By: iains Differential Revision: https://reviews.llvm.org/D135958
2022-03-07[clang][modules] Report module maps affecting `no_undeclared_includes` modulesJan Svoboda1-1/+4
Since D106876, PCM files don't report module maps as input files unless they contributed to the compilation. Reporting only module maps of (transitively) imported modules is not enough, though. For modules marked with `[no_undeclared_includes]`, other module maps affect the compilation by introducing anti-dependencies. This patch makes sure such module maps are being reported as input files. Depends on D120463. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D120464
2021-10-10[Basic] Use llvm::is_contained (NFC)Kazu Hirata1-3/+1
2021-09-14Cleanup identifier parsing; NFCCorentin Jabot1-1/+1
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-05-17[clang][modules] Build inferred modulesMichael Spencer1-2/+3
This patch enables explicitly building inferred modules. Effectively a cherry-pick of https://github.com/apple/llvm-project/pull/699 authored by @Bigcheese with libclang and dependency scanner changes omitted. Contains the following changes: 1. [Clang] Fix the header paths in clang::Module for inferred modules. * The UmbrellaAsWritten and NameAsWritten fields in clang::Module are a lie for framework modules. For those they actually are the path to the header or umbrella relative to the clang::Module::Directory. * The exception to this case is for inferred modules. Here it actually is the name as written, because we print out the module and read it back in when implicitly building modules. This causes a problem when explicitly building an inferred module, as we skip the printing out step. * In order to fix this issue this patch adds a new field for the path we want to use in getInputBufferForModule. It also makes NameAsWritten actually be the name written in the module map file (or that would be, in the case of an inferred module). 2. [Clang] Allow explicitly building an inferred module. * Building the actual module still fails, but make sure it fails for the right reason. Split from D100934. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D102491
2021-03-22Improve module dumping for debugging.Richard Smith1-3/+10
* List inferred lists of imports in `#pragma clang __debug module_map`. * Add `#pragma clang __debug modules {all,visible,building}` to dump lists of known / visible module names or the building modules stack.
2021-02-23Revert "Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, Header, ↵Duncan P. N. Exon Smith1-4/+1
and DirectoryName, NFC" This (mostly) reverts 32c501dd88b62787d3a5ffda7aabcf4650dbe3cd. Hit a case where this causes a behaviour change, perhaps the same root cause that triggered the revert of a40db5502b2515a6f2f1676b5d7a655ae0f41179 in 7799ef7121aa7d59f4bd95cdf70035de724ead6f. (The API changes in DirectoryEntry.h have NOT been reverted as a number of subsequent commits depend on those.) https://reviews.llvm.org/D90497#2582166
2020-12-16Use basic_string::find(char) instead of basic_string::find(const char *s, ↵Fangrui Song1-1/+1
size_type pos=0) Many (StringRef) cannot be detected by clang-tidy performance-faster-string-find.
2020-12-02Module: Use FileEntryRef and DirectoryEntryRef in Umbrella, Header, and ↵Duncan P. N. Exon Smith1-1/+4
DirectoryName, NFC Push `FileEntryRef` and `DirectoryEntryRef` further, using it them `Module::Umbrella`, `Module::Header::Entry`, and `Module::DirectoryName::Entry`. - Add `DirectoryEntryRef::operator const DirectoryEntry *` and `OptionalDirectoryEntryRefDegradesToDirectoryEntryPtr`, to get the same "degrades to `DirectoryEntry*` behaviour `FileEntryRef` enjoys (this avoids a bunch of churn in various clang tools). - Fix the `DirectoryEntryRef` constructor from `MapEntry` to take it by `const&`. Note that we cannot get rid of the `...AsWritten` names leveraging the new classes, since these need to be as written in the `ModuleMap` file and the module directory path is preprended for the lookup in the `FileManager`. Differential Revision: https://reviews.llvm.org/D90497
2020-11-04Basic: Change Module::Umbrella to a PointerUnion, NFCDuncan P. N. Exon Smith1-2/+2
Change `Module::Umbrella` from a `const void *` to a `PointerUnion` of `FileEntry` and `DirectoryEntry`. We can drop the `HasUmbrellaDir` bit (since `PointerUnion` includes that). This change makes it safer to update to `FileEntryRef` and `DirectoryEntryRef` in a future patch. Differential Revision: https://reviews.llvm.org/D90481
2020-11-02Change Module::ASTFile and ModuleFile::File => Optional<FileEntryRef>, NFCDuncan P. N. Exon Smith1-1/+1
Change `Module::ASTFile` and `ModuleFile::File` to use `Optional<FileEntryRef>` instead of `const FileEntry *`. One of many steps toward removing `FileEntry::getName`. Differential Revision: https://reviews.llvm.org/D89836
2020-07-21[NFC] Clean up doc comment and implementation for Module::isSubModuleOf.Adrian Prantl1-7/+3
Patch by Varun Gandhi! Differential Revision: https://reviews.llvm.org/D84087
2020-04-17When making modules transitively visible, don't take into accountRichard Smith1-2/+2
whether they have missing header files. Whether a module's headers happen to be present on the local file system should make no difference to whether we make its contents visible when importing another module that re-exports it. If we have an up-to-date AST file that we can load, that's all that matters. This fixes the ability to header syntax checking for modular headers in C++20 mode (or in prior modes where -fmodules-local-submodule-visibility is enabled but -fmodules is not).
2020-04-17Rename IsMissingRequirement to IsUnimportable and set it for shadowedRichard Smith1-25/+37
modules too. This more accurately reflects the semantics of this flag, as distinct from "IsAvailable", which (in an explicit modules world) only describes whether a module is buildable, not whether it's importable.
2020-04-01Remove const qualifier from Modules returned by ExternalASTSource. (NFC)Adrian Prantl1-1/+1
This API is used by LLDB to attach owning module information to Declarations deserialized from DWARF. Differential Revision: https://reviews.llvm.org/D75561
2020-03-11Avoid including Module.h from ExternalASTSource.hReid Kleckner1-0/+15
Module.h takes 86ms to parse, mostly parsing the class itself. Avoid it if possible. ASTContext.h depends on ExternalASTSource.h. A few NFC changes were needed to make this possible: - Move ASTSourceDescriptor to Module.h. This needs Module to be complete, and seems more related to modules and AST files than external AST sources. - Move "import complete" bit from Module* pointer int pair to NextLocalImport pointer. Required because PointerIntPair<Module*,...> requires Module to be complete, and now it may not be. Reviewed By: aaron.ballman, hans Differential Revision: https://reviews.llvm.org/D75784