aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaModule.cpp
AgeCommit message (Collapse)AuthorFilesLines
2023-02-20[NFC] Remove the unused parameter in Sema::PushGlobalModuleFragmentChuanqi Xu1-5/+3
The `IsImplicit` parameter should be removed since it is not used now.
2023-02-20[NFC] Remove unused Sema::DirectModuleImportsChuanqi Xu1-5/+0
Sema::DirectModuleImports is not used now. Remove it for clearness.
2023-02-16[Modules] Code cleanup after removing ModulesTSChuanqi Xu1-7/+1
Some codes become unused after we remove ModulesTS.
2023-02-16[Modules] Remove -fmodules-tsChuanqi Xu1-19/+7
As the diagnostic message shows, we should remove -fmodules-ts flag in clang/llvm17. Since clang/llvm16 is already branched. We can remove the depreacared flag now.
2023-02-13[NFC] Set C++20 Named Modules for CodeGen in ASTContext in the early placeChuanqi Xu1-0/+2
Previously we'll set the named modules for ASTContext in ParseAST. But this is not intuitive and we need comments to tell the intuition. This patch moves the code the right the place, where the corrresponding module is first created/loaded. Now it is more intuitive and we can use the value in the earlier places.
2023-02-08[C++20] [Modules] Allow -fmodule-file=<module-name>=<BMI-Path> for ↵Chuanqi Xu1-2/+11
implementation unit and document the behavior Close https://github.com/llvm/llvm-project/issues/57293. Previsouly we can't use `-fmodule-file=<module-name>=<BMI-Path>` for implementation units, it is a bug. Also the behavior of the above option is not tested nor documented for C++20 Modules. This patch addresses the 2 problems.
2023-01-22[C++20][Modules] Fix named module import diagnostics.Iain Sandoe1-3/+0
We have been incorrectly disallowing imports of named modules in the global and private module fragments. This addresses: https://github.com/llvm/llvm-project/issues/59688 Differential Revision: https://reviews.llvm.org/D140927
2023-01-20[clang][modules] Disallow importing private framework in the implementationJan Svoboda1-1/+1
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-20[clang][nfc] refactor Module::Header to use OptionalFileEntryRefRichard Howell1-2/+2
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-1/+1
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-1/+1
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-2/+1
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-1/+2
2022-12-03[Sema] Use std::nullopt instead of None (NFC)Kazu Hirata1-1/+1
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-18[NFC] Remove unused codes after 4a7be42d922afChuanqi Xu1-2/+1
There are still some unused codes remained after 4a7be42d922af. And this patch tries to remove them.
2022-11-15[NFC] [C++20] [Modules] Remove unused Global Module Fragment variables/argumentsChuanqi Xu1-14/+5
2022-11-03Remove an unused local variable, NFC.Haojian Wu1-1/+0
2022-11-03[C++20] Diagnose invalid and reserved module namesAaron Ballman1-0/+57
[module.unit]p1 specifies that module and import are invalid components of a module name, that module names cannot contain reserved identifiers, and that std followed by zero or more digits is reserved. The first issue (module and import pseudo-keywords) requires a diagnostic, the second issue (use of reserved identifiers) does not require a diagnostic. We diagnose both the same -- the code is ill- formed unless the module declaration is in a system "header". This allows STL implementations to use the reserved module names while preventing users from stealing them out from under us. Differential Revision: https://reviews.llvm.org/D136953
2022-10-08[C++20] [Modules] Remove assertion of current module when acting on importChuanqi Xu1-5/+0
Closes https://github.com/llvm/llvm-project/issues/58199 Previously, when we act on a import statement, we'll assume there is a module declaration in the current TU if the command line tells us we're compiling a module unit. This makes since on valid codes. However, for invalid codes, it is possible. See https://github.com/llvm/llvm-project/issues/58199 for example. This patch removes the assertion. And the assertion is a noop and it should be safe to remove it.
2022-08-21[C++20][Modules] Improve handing of Private Module Fragment diagnostics.Iain Sandoe1-0/+11
This adds a check for exported inline functions, that there is a definition in the definition domain (which, in practice, can only be the module purview but before any PMF starts) since the PMF definition domain cannot contain exports. This is: [dcl.inline]/7 If an inline function or variable that is attached to a named module is declared in a definition domain, it shall be defined in that domain. The patch also amends diagnostic output by excluding the PMF sub-module from the set considered as sources of missing decls. There is no point in telling the user that the import of a PMF object is missing - since such objects are never reachable to an importer. We still show the definition (as unreachable), to help point out this. Differential Revision: https://reviews.llvm.org/D128328
2022-07-27[NFC] [C++20] [Modules] Use Sema::isCurrentModulePurview() to simplify the codesChuanqi Xu1-3/+2
2022-07-22re-land [C++20][Modules] Build module static initializers per P1874R1.Iain Sandoe1-0/+10
The re-land fixes module map module dependencies seen on Greendragon, but not in the clang test suite. --- Currently we only implement this for the Itanium ABI since the correct mangling for the initializers in other ABIs is not yet known. Intended result: For a module interface [which includes partition interface and implementation units] (instead of the generic CXX initializer) we emit a module init that: - wraps the contained initializations in a control variable to ensure that the inits only happen once, even if a module is imported many times by imports of the main unit. - calls module initializers for imported modules first. Note that the order of module import is not significant, and therefore neither is the order of imported module initializers. - We then call initializers for the Global Module Fragment (if present) - We then call initializers for the current module. - We then call initializers for the Private Module Fragment (if present) For a module implementation unit, or a non-module TU that imports at least one module we emit a regular CXX init that: - Calls the initializers for any imported modules first. - Then proceeds as normal with remaining inits. For all module unit kinds we include a global constructor entry, this allows for the (in most cases unusual) possibility that a module object could be included in a final binary without a specific call to its initializer. Implementation: - We provide the module pointer in the AST Context so that CodeGen can act on it and its sub-modules. - We need to account for module build lines like this: ` clang -cc1 -std=c++20 Foo.pcm -emit-obj -o Foo.o` or ` clang -cc1 -std=c++20 -xc++-module Foo.cpp -emit-obj -o Foo.o` - in order to do this, we add to ParseAST to set the module pointer in the ASTContext, once we establish that this is a module build and we know the module pointer. To be able to do this, we make the query for current module public in Sema. - In CodeGen, we determine if the current build requires a CXX20-style module init and, if so, we defer any module initializers during the "Eagerly Emitted" phase. - We then walk the module initializers at the end of the TU but before emitting deferred inits (which adds any hidden and static ones, fixing https://github.com/llvm/llvm-project/issues/51873 ). - We then proceed to emit the deferred inits and continue to emit the CXX init function. Differential Revision: https://reviews.llvm.org/D126189
2022-07-11Revert "[C++20][Modules] Build module static initializers per P1874R1."Iain Sandoe1-10/+0
This reverts commit ac507102d258b6fc0cb57eb60c9dfabd57ff562f. reverting while we figuere out why one of the green dragon lldb test fails.
2022-07-09[C++20][Modules] Build module static initializers per P1874R1.Iain Sandoe1-0/+10
Currently we only implement this for the Itanium ABI since the correct mangling for the initializers in other ABIs is not yet known. Intended result: For a module interface [which includes partition interface and implementation units] (instead of the generic CXX initializer) we emit a module init that: - wraps the contained initializations in a control variable to ensure that the inits only happen once, even if a module is imported many times by imports of the main unit. - calls module initializers for imported modules first. Note that the order of module import is not significant, and therefore neither is the order of imported module initializers. - We then call initializers for the Global Module Fragment (if present) - We then call initializers for the current module. - We then call initializers for the Private Module Fragment (if present) For a module implementation unit, or a non-module TU that imports at least one module we emit a regular CXX init that: - Calls the initializers for any imported modules first. - Then proceeds as normal with remaining inits. For all module unit kinds we include a global constructor entry, this allows for the (in most cases unusual) possibility that a module object could be included in a final binary without a specific call to its initializer. Implementation: - We provide the module pointer in the AST Context so that CodeGen can act on it and its sub-modules. - We need to account for module build lines like this: ` clang -cc1 -std=c++20 Foo.pcm -emit-obj -o Foo.o` or ` clang -cc1 -std=c++20 -xc++-module Foo.cpp -emit-obj -o Foo.o` - in order to do this, we add to ParseAST to set the module pointer in the ASTContext, once we establish that this is a module build and we know the module pointer. To be able to do this, we make the query for current module public in Sema. - In CodeGen, we determine if the current build requires a CXX20-style module init and, if so, we defer any module initializers during the "Eagerly Emitted" phase. - We then walk the module initializers at the end of the TU but before emitting deferred inits (which adds any hidden and static ones, fixing https://github.com/llvm/llvm-project/issues/51873 ). - We then proceed to emit the deferred inits and continue to emit the CXX init function. Differential Revision: https://reviews.llvm.org/D126189
2022-07-08[C++20] [Modules] Don't complain about duplicated default template argument ↵Chuanqi Xu1-0/+13
across modules See https://github.com/cplusplus/draft/pull/5204 for a detailed background. Simply, the test redundant-template-default-arg.cpp attached to this patch should be accepted instead of being complained about the redefinition. Reviewed By: urnathan, rsmith, ChuanqiXu Differential Revision: https://reviews.llvm.org/D118034
2022-06-29[C++20] [Module] Support reachable definition initially/partiallyChuanqi Xu1-3/+12
This patch introduces a new kind of ModuleOwnershipKind as ReachableWhenImported. This intended the status for reachable described at: https://eel.is/c++draft/module.reach#3. Note that this patch is not intended to support all semantics about reachable semantics. For example, this patch didn't implement discarded declarations in GMF. (https://eel.is/c++draft/module.global.frag#3). This fixes: https://bugs.llvm.org/show_bug.cgi?id=52281 and https://godbolt.org/z/81f3ocjfW. Reviewed By: rsmith, iains Differential Revision: https://reviews.llvm.org/D113545
2022-06-29Revert "[C++20] [Modules] Implement Reachable initiallly"Chuanqi Xu1-12/+3
This reverts commit a223ba0a697c1598b434cf2495c9cd9ec5640fc7. The previous commit don't contain additional information, which is bad.
2022-06-29[C++20] [Modules] Implement Reachable initialllyChuanqi Xu1-3/+12
2022-04-11[C++20][Modules] Remove an empty statement [NFC].Iain Sandoe1-2/+1
This addresses a post commit review comment by removing an unused and empty 'else' (replaced with a comment).
2022-04-08[C++20][Modules] Adjust handling of exports of namespaces and using-decls.Iain Sandoe1-6/+23
This adjusts the handling for: export module M; export namespace {}; export namespace N {}; export using namespace N; In the first case, we were allowing empty anonymous namespaces as part of an extension allowing empty top-level entities, but that seems inappropriate in this case, since the linkage would be internal for the anonymous namespace. We now report an error for this. The second case was producing a warning diagnostic that this was accepted as an extension - however the C++20 standard does allow this as well-formed. In the third case we keep the current practice that this is accepted with a warning (as an extension). The C++20 standard says it's an error. We also ensure that using decls are only applied to items with external linkage. This adjusts error messages for exports involving redeclarations in modules to be more specific about the reason that the decl has been rejected. Differential Revision: https://reviews.llvm.org/D122119
2022-03-27[C++20][Modules][HU 4/5] Handle pre-processed header units.Iain Sandoe1-3/+11
We wish to support emitting a pre-processed output for an importable header unit, that can be consumed to produce the same header units as the original source. This means that ee need to find the original filename used to produce the re-preprocessed output, so that it can be assigned as the module name. This is peeked from the first line of the pre-processed source when the action sets up the files. Differential Revision: https://reviews.llvm.org/D121098
2022-03-25[C++20][Modules] Correct an assert for modules-ts.Iain Sandoe1-1/+1
When adding the support for modules partitions we added an assert that the actual status of Global Module Fragments matches the state machine that is driven by the module; keyword. That does not apply to the modules-ts case, where there is an implicit GMF. Differential Revision: https://reviews.llvm.org/D122394
2022-03-25[C++20][Modules][HU 1/5] Introduce header units as a module type.Iain Sandoe1-1/+41
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-09[clang] Sema::ActOnModuleImport - remove superfluous nullptr testSimon Pilgrim1-1/+1
Mod has already been dereferenced
2022-03-02[NFC] [C++20] [Modules] Simplify ActOnModuleImport by merging Path and ParitionChuanqi Xu1-11/+6
Reviewed By: iains Differential Revision: https://reviews.llvm.org/D120793
2022-02-28[C++20][Modules][7/8] Find the primary interface name for a module.Iain Sandoe1-11/+4
When we are building modules, there are cases where the only way to determine validity of access is by comparing primary interface names. This is because we need to be able to associate a primary interface name with an imported partition, but before the primary interface module is complete - so that textual comparison is necessary. If this turns out to be needed many times, we could cache the result, but it seems unlikely to be significant (at this time); cases with very many imported partitions would seem unusual. Differential Revision: https://reviews.llvm.org/D118598
2022-02-27[C++20][Modules][6/8] Record direct module imports.Iain Sandoe1-0/+5
This is a small cache to avoid having to check both Exports and Imports. Differential Revision: https://reviews.llvm.org/D118589
2022-02-26[C++20][Modules][5/8] Diagnose wrong import/export for partition CMIs.Iain Sandoe1-6/+18
We cannot export partition implementation CMIs, but we can export the content of partition interface CMIs. Differential Revision: https://reviews.llvm.org/D118588
2022-02-25[C++20][Modules][4/8] Handle generation of partition implementation CMIs.Iain Sandoe1-28/+42
Partition implementations are special, they generate a CMI, but it does not have an 'export' line, and we cannot export anything from the it [that is it can only make decls available to other members of the owning module, not to importers of that]. Add initial testcases for partition handling, derived from the examples in Section 10 of the C++20 standard, which identifies what should be accepted and/or rejected. Differential Revision: https://reviews.llvm.org/D118587
2022-02-24[Sema] Silence unused variable warning in Release builds. NFC.Benjamin Kramer1-0/+2
2022-02-24[C++20][Modules][3/8] Initial handling for module partitions.Iain Sandoe1-47/+119
This implements the parsing and recognition of module partition CMIs and removes the FIXMEs in the parser. Module partitions are recognised in the base computation of visibility, however additional amendments to visibility follow in subsequent patches. Differential Revision: https://reviews.llvm.org/D118586
2022-02-22[C++20][Modules][2/8] Add enumerations for partition modules and stream them.Iain Sandoe1-0/+2
This is an initial enabling patch for module partition support. We add enumerations for partition interfaces/implementations. This means that the module kind enumeration now occupies three bits, so the AST streamer is adjusted for this. Adding one bit there seems preferable to trying to overload the meanings of existing kinds (and we will also want to add a C++20 header unit case later). Differential Revision: https://reviews.llvm.org/D114714
2022-02-21[C++20][Modules][1/8] Track valid import state.Iain Sandoe1-12/+34
In C++20 modules imports must be together and at the start of the module. Rather than growing more ad-hoc flags to test state, this keeps track of the phase of of a valid module TU (first decl, global module frag, module, private module frag). If the phasing is broken (with some diagnostic) the pattern does not conform to a valid C++20 module, and we set the state accordingly. We can thus issue diagnostics when imports appear in the wrong places and decouple the C++20 modules state from other module variants (modules-ts and clang modules). Additionally, we attempt to diagnose wrong imports before trying to find the module where possible (the latter will generally emit an unhelpful diagnostic about the module not being available). Although this generally simplifies the handling of C++20 module import diagnostics, the motivation was that, in particular, it allows detecting invalid imports like: import module A; int some_decl(); import module B; where being in a module purview is insufficient to identify them. Differential Revision: https://reviews.llvm.org/D118893
2022-02-20Revert "[C++20][Modules][1/8] Track valid import state."Iain Sandoe1-34/+12
This reverts commit 8a3f9a584ad43369cf6a034dc875ebfca76d9033. need to investigate build failures that do not show on CI or local testing.
2022-02-20[C++20][Modules][1/8] Track valid import state.Iain Sandoe1-12/+34
In C++20 modules imports must be together and at the start of the module. Rather than growing more ad-hoc flags to test state, this keeps track of the phase of of a valid module TU (first decl, global module frag, module, private module frag). If the phasing is broken (with some diagnostic) the pattern does not conform to a valid C++20 module, and we set the state accordingly. We can thus issue diagnostics when imports appear in the wrong places and decouple the C++20 modules state from other module variants (modules-ts and clang modules). Additionally, we attempt to diagnose wrong imports before trying to find the module where possible (the latter will generally emit an unhelpful diagnostic about the module not being available). Although this generally simplifies the handling of C++20 module import diagnostics, the motivation was that, in particular, it allows detecting invalid imports like: import module A; int some_decl(); import module B; where being in a module purview is insufficient to identify them. Differential Revision: https://reviews.llvm.org/D118893
2022-02-08[C++20] [Modules] Don't create multiple global module fragmentChuanqi Xu1-8/+13
Since the serialization code would recognize modules by names and the name of all global module fragment is <global>, so that the serialization code would complain for the same module. This patch fixes this by using a unique global module fragment in Sema. Before this patch, the compiler would fail on an assertion complaining the duplicated modules. Reviewed By: urnathan, rsmith Differential Revision: https://reviews.llvm.org/D115610
2022-01-24[clang][sema] Add missing diagnostic parameterTimm Bäder1-1/+1
The test case otherwise fails an assertion in Diagnostic::getArgKind(). Differential Revision: https://reviews.llvm.org/D116595
2022-01-14[C++20] [Modules] Exit early if export decl is not validChuanqi Xu1-3/+12
This patch fixes a crash due to following simple program: > export struct Unit { > bool operator<(const Unit&); > }; It would crash since the compiler would set the module ownership for Unit. And the declaration with a module ownership is assumed to own a module. But here isn't one. So here is the crash. This patch fixes this by exiting early if it finds the export decl is already invalid. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D117093
2021-12-23[C++20] [Modules] Mark imported module as imported if not exportedChuanqi Xu1-1/+8
In C++20 Modules, imported module which doesn't get exported wouldn't be recorded. This patch would record such modules to avoid possible incorrect visibility problems. Reviewed By: urnathan Differential Revision: https://reviews.llvm.org/D116098