aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Basic/Module.cpp
AgeCommit message (Collapse)AuthorFilesLines
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
2020-02-27Forward declare FileEntry and DirectoryEntry in Module.hReid Kleckner1-2/+7
FileManager.h is an expensive header (~350ms for me in isolation), so try to do without it. Notably, we need to avoid checking the alignment of FileEntry, which happens for DenseMap<FileEntry*> and PointerUnion<FileEntry*>. I adjusted the code to avoid PointerUnion, and moved the DenseMap insertion to the .cpp file. Globally, this only saved about ~17 includes of the related headers because SourceManager.h still includes FileManager.h, and it is more popular than Module.h.
2020-01-29Fix conversions in clang and examplesBenjamin Kramer1-1/+1
2019-08-01[clang] Adopt new FileManager error-returning APIsHarlan Haskins1-2/+2
Update the callers of FileManager::getFile and FileManager::getDirectory to handle the new llvm::ErrorOr-returning methods. Signed-off-by: Harlan Haskins <harlan@apple.com> llvm-svn: 367616
2019-05-07-frewrite-imports: Add support for wildcard rules in umbrella modules withDavid Blaikie1-0/+15
This trips over a few other limitations, but in the interests of incremental development I'm starting here & I'll look at the issues with -verify and filesystem checks (the fact that the behavior depends on the existence of a 'foo' directory even though it shouldn't need it), etc. Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D61656 llvm-svn: 360195
2019-02-23Enable coroutines under -std=c++2a.Richard Smith1-1/+1
llvm-svn: 354736
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-10-30NFC: Remove the ObjC1/ObjC2 distinction from clang (and related projects)Erik Pilkington1-1/+1
We haven't supported compiling ObjC1 for a long time (and never will again), so there isn't any reason to keep these separate. This patch replaces LangOpts::ObjC1 and LangOpts::ObjC2 with LangOpts::ObjC. Differential revision: https://reviews.llvm.org/D53547 llvm-svn: 345637
2018-09-18[Modules] Add platform and environment features to requires clauseBruno Cardoso Lopes1-1/+33
Allows module map writers to add build requirements based on platform/os. This helps when target features and language dialects aren't enough to conditionalize building a module, among other things, it allow module maps for different platforms to live in the same file. rdar://problem/43909745 Differential Revision: https://reviews.llvm.org/D51910 llvm-svn: 342499
2018-09-12When we leave a module header, make that header visible in itsRichard Smith1-6/+5
includer's context, even if its overall module is unavailable. llvm-svn: 342096
2018-07-30Remove trailing spaceFangrui Song1-14/+14
sed -Ei 's/[[:space:]]+$//' include/**/*.{def,h,td} lib/**/*.{cpp,h} llvm-svn: 338291
2018-05-09Remove \brief commands from doxygen comments.Adrian Prantl1-1/+1
This is similar to the LLVM change https://reviews.llvm.org/D46290. We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\@brief'); do perl -pi -e 's/\@brief //g' $i & done for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done Differential Revision: https://reviews.llvm.org/D46320 llvm-svn: 331834
2018-04-20Record whether a module came from a private module mapJordan Rose1-1/+4
Right now we only use this information in one place, immediately after we calculate it, but it's still nice information to have. The Swift project is going to use this to tidy up its "API notes" feature (see past discussion on cfe-dev that never quite converged). Reviewed by Bruno Cardoso Lopes. llvm-svn: 330452
2018-02-14[Modules] Add more language features to be used with requires-declarationBruno Cardoso Lopes1-0/+5
Features added: c99, c11, c17, cplusplus14 and cplusplus17. rdar://problem/36328787 rdar://problem/36668431 llvm-svn: 325154
2018-01-05Reapply r321781: [Modules] Allow modules specified by -fmodule-map-file to ↵Bruno Cardoso Lopes1-1/+6
shadow implicitly found ones When modules come from module map files explicitly specified by -fmodule-map-file= arguments, allow those to override/shadow modules with the same name that are found implicitly by header search. If such a module is looked up by name (e.g. @import), we will always find the one from -fmodule-map-file. If we try to use a shadowed module by including one of its headers report an error. This enables developers to force use of a specific copy of their module to be used if there are multiple copies that would otherwise be visible, for example if they develop modules that are installed in the default search paths. Patch originally by Ben Langmuir, http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20151116/143425.html Based on cfe-dev discussion: http://lists.llvm.org/pipermail/cfe-dev/2015-November/046164.html Differential Revision: https://reviews.llvm.org/D31269 rdar://problem/23612102 llvm-svn: 321855
2018-01-04Revert "[Modules] Allow modules specified by -fmodule-map-file to shadow ↵Bruno Cardoso Lopes1-6/+1
implicitly found ones" This reverts r321781 until I fix the leaks pointed out by bots: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/12146 http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-bootstrap/builds/3741 llvm-svn: 321786
2018-01-04[Modules] Allow modules specified by -fmodule-map-file to shadow implicitly ↵Bruno Cardoso Lopes1-1/+6
found ones When modules come from module map files explicitly specified by -fmodule-map-file= arguments, allow those to override/shadow modules with the same name that are found implicitly by header search. If such a module is looked up by name (e.g. @import), we will always find the one from -fmodule-map-file. If we try to use a shadowed module by including one of its headers report an error. This enables developers to force use of a specific copy of their module to be used if there are multiple copies that would otherwise be visible, for example if they develop modules that are installed in the default search paths. Patch originally by Ben Langmuir, http://lists.llvm.org/pipermail/cfe-commits/Week-of-Mon-20151116/143425.html Based on cfe-dev discussion: http://lists.llvm.org/pipermail/cfe-dev/2015-November/046164.html Differential Revision: https://reviews.llvm.org/D31269 rdar://problem/23612102 llvm-svn: 321781
2017-11-03[Basic] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko1-7/+18
other minor fixes (NFC). llvm-svn: 317381
2017-09-14[Module map] Introduce a private module re-export directive.Douglas Gregor1-0/+5
Introduce a new "export_as" directive for top-level modules, which indicates that the current module is a "private" module whose symbols will eventually be exported through the named "public" module. This is in support of a common pattern in the Darwin ecosystem where a single public framework is constructed of several private frameworks, with (currently) header duplication and some support from the linker. Addresses rdar://problem/34438420. llvm-svn: 313316
2017-06-19Support non-identifier module names when preprocessing modules.Richard Smith1-22/+41
llvm-svn: 305758
2017-06-02Support lazy stat'ing of files referenced by module maps.Richard Smith1-1/+20
This patch adds support for a `header` declaration in a module map to specify certain `stat` information (currently, size and mtime) about that header file. This has two purposes: - It removes the need to eagerly `stat` every file referenced by a module map. Instead, we track a list of unresolved header files with each size / mtime (actually, for simplicity, we track submodules with such headers), and when attempting to look up a header file based on a `FileEntry`, we check if there are any unresolved header directives with that `FileEntry`'s size / mtime and perform deferred `stat`s if so. - It permits a preprocessed module to be compiled without the original files being present on disk. The only reason we used to need those files was to get the `stat` information in order to do header -> module lookups when using the module. If we're provided with the `stat` information in the preprocessed module, we can avoid requiring the files to exist. Unlike most `header` directives, if a `header` directive with `stat` information has no corresponding on-disk file the enclosing module is *not* marked unavailable (so that behavior is consistent regardless of whether we've resolved a header directive, and so that preprocessed modules don't get marked unavailable). We could actually do this for all `header` directives: the only reason we mark the module unavailable if headers are missing is to give a diagnostic slightly earlier (rather than waiting until we actually try to build the module / load and validate its .pcm file). Differential Revision: https://reviews.llvm.org/D33703 llvm-svn: 304515
2017-05-28[coroutines] Support "coroutines" feature in module map requires clauseEric Fiselier1-0/+1
Summary: In order for libc++ to add `<experimental/coroutine>` to its module map, there has to be a feature that can be used to detect if coroutines support is enabled in Clang. Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33538 llvm-svn: 304107
2017-05-27Revert "[coroutines] Support "coroutines" feature in module map requires clause"Eric Fiselier1-1/+0
This reverts commit r304054. llvm-svn: 304057
2017-05-27[coroutines] Support "coroutines" feature in module map requires clauseEric Fiselier1-0/+1
Summary: In order for libc++ to add `<experimental/coroutine>` to its module map, there has to be a feature that can be used to detect if coroutines support is enabled in Clang. Reviewers: rsmith Reviewed By: rsmith Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D33538 llvm-svn: 304054
2017-04-11Modular Codegen: Add/use a bit in serialized function definitions to track ↵David Blaikie1-1/+1
whether they are the subject of modular codegen Some decls are created not where they are written, but in other module files/users (implicit special members and function template implicit specializations). To correctly identify them, use a bit next to the definition to track the modular codegen property. Discussed whether the module file bit could be omitted in favor of reconstituting from the modular codegen decls list - best guess today is that the efficiency improvement of not having to deserialize the whole list whenever any function is queried by a module user is worth it for the small size increase of this redundant (list + bit-on-def) representation. Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D29901 llvm-svn: 299982
2017-03-13Modules: Use hash of PCM content for SIGNATUREDuncan P. N. Exon Smith1-1/+1
Change ASTFileSignature from a random 32-bit number to the hash of the PCM content. - Move definition ASTFileSignature to Basic/Module.h so Module and ASTSourceDescriptor can use it. - Change the signature from uint64_t to std::array<uint32_t,5>. - Stop using (saving/reading) the size and modification time of PCM files when there is a valid SIGNATURE. - Add UNHASHED_CONTROL_BLOCK, and use it to store the SIGNATURE record and other records that shouldn't affect the hash. Because implicit modules reuses the same file for multiple levels of -Werror, this includes DIAGNOSTIC_OPTIONS and DIAG_PRAGMA_MAPPINGS. This helps to solve a PCH + implicit Modules dependency issue: PCH files are handled by the external build system, whereas implicit modules are handled by internal compiler build system. This prevents invalidating a PCH when the compiler overwrites a PCM file with the same content (modulo the diagnostic differences). Design and original patch by Manman Ren! llvm-svn: 297655
2017-01-30Prototype of modules codegenDavid Blaikie1-1/+1
First pass at generating weak definitions of inline functions from module files (& skipping (-O0) or emitting available_externally (optimizations) definitions where those modules are used). External functions defined in modules are emitted into the modular object file as well (this may turn an existing ODR violation (if that module were imported into multiple translations) into valid/linkable code). Internal symbols (static functions, for example) are not correctly supported yet. The symbol will be produced, internal, in the modular object - unreferenceable from the users. Reviewers: rsmith Differential Revision: https://reviews.llvm.org/D28845 llvm-svn: 293456
2016-10-21[Modules] Add 'no_undeclared_includes' module map attributeBruno Cardoso Lopes1-1/+8
The 'no_undeclared_includes' attribute should be used in a module to tell that only non-modular headers and headers from used modules are accepted. The main motivation behind this is to prevent dep cycles between system libraries (such as darwin) and libc++. Patch by Richard Smith! llvm-svn: 284797
2016-09-04[Modules] Add 'freestanding' to the 'requires-declaration' feature-list.Elad Cohen1-0/+1
This adds support for modules that require (non-)freestanding environment, such as the compiler builtin mm_malloc submodule. Differential Revision: https://reviews.llvm.org/D23871 llvm-svn: 280613
2016-08-30[Modules] Add 'gnuinlineasm' to the 'requires-declaration' feature-list.Bruno Cardoso Lopes1-0/+1
This adds support for modules that require (no-)gnu-inline-asm environment, such as the compiler builtin cpuid submodule. This is the gnu-inline-asm variant of https://reviews.llvm.org/D23871 Differential Revision: https://reviews.llvm.org/D23905 rdar://problem/26931199 llvm-svn: 280159
2016-03-09[modules] Simplify code logic. NFC.Davide Italiano1-6/+2
llvm-svn: 263060
2016-02-11[Modules] Don't infinite recurse on implicit import of circular modules in ↵Ben Langmuir1-0/+1
preamble Update the Preprocessor's VisibleModuleSet when typo-correction creates an implicit module import so that we won't accidentally write an invalid SourceLocation into the preamble AST. This would later lead to infinite recursion when loading the preamble AST because we use the value in ImportLocs to prevent visiting a module twice. rdar://problem/24440990 llvm-svn: 260543