aboutsummaryrefslogtreecommitdiff
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/AST/ASTContext.h9
-rw-r--r--clang/lib/AST/ASTContext.cpp9
-rw-r--r--clang/lib/CodeGen/CGDeclCXX.cpp6
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp2
-rw-r--r--clang/lib/Frontend/ASTUnit.cpp2
-rw-r--r--clang/lib/Sema/SemaModule.cpp2
6 files changed, 18 insertions, 12 deletions
diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h
index b08eb52..8f0a82a7 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -447,9 +447,8 @@ class ASTContext : public RefCountedBase<ASTContext> {
};
llvm::DenseMap<Module*, PerModuleInitializers*> ModuleInitializers;
- /// For module code-gen cases, this is the top-level (C++20) Named module
- /// we are building.
- Module *TopLevelCXXNamedModule = nullptr;
+ /// This is the top-level (C++20) Named module we are building.
+ Module *CurrentCXXNamedModule = nullptr;
static constexpr unsigned ConstantArrayTypesLog2InitSize = 8;
static constexpr unsigned GeneralTypesLog2InitSize = 9;
@@ -1052,10 +1051,10 @@ public:
ArrayRef<Decl*> getModuleInitializers(Module *M);
/// Set the (C++20) module we are building.
- void setNamedModuleForCodeGen(Module *M) { TopLevelCXXNamedModule = M; }
+ void setCurrentNamedModule(Module *M);
/// Get module under construction, nullptr if this is not a C++20 module.
- Module *getNamedModuleForCodeGen() const { return TopLevelCXXNamedModule; }
+ Module *getCurrentNamedModule() const { return CurrentCXXNamedModule; }
TranslationUnitDecl *getTranslationUnitDecl() const {
return TUDecl->getMostRecentDecl();
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 7fdbf4d..3d44f1c 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -1153,6 +1153,13 @@ ArrayRef<Decl *> ASTContext::getModuleInitializers(Module *M) {
return Inits->Initializers;
}
+void ASTContext::setCurrentNamedModule(Module *M) {
+ assert(M->isModulePurview());
+ assert(!CurrentCXXNamedModule &&
+ "We should set named module for ASTContext for only once");
+ CurrentCXXNamedModule = M;
+}
+
ExternCContextDecl *ASTContext::getExternCContextDecl() const {
if (!ExternCContext)
ExternCContext = ExternCContextDecl::Create(*this, getTranslationUnitDecl());
@@ -11922,7 +11929,7 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
// Variables in other module units shouldn't be forced to be emitted.
auto *VM = VD->getOwningModule();
if (VM && VM->getTopLevelModule()->isModulePurview() &&
- VM->getTopLevelModule() != getNamedModuleForCodeGen())
+ VM->getTopLevelModule() != getCurrentNamedModule())
return false;
// Variables that can be needed in other TUs are required.
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 9d7284c..04e4215 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -883,12 +883,12 @@ CodeGenModule::EmitCXXGlobalInitFunc() {
// with priority emitted above. Module implementation units behave the same
// way as a non-modular TU with imports.
llvm::Function *Fn;
- if (CXX20ModuleInits && getContext().getNamedModuleForCodeGen() &&
- !getContext().getNamedModuleForCodeGen()->isModuleImplementation()) {
+ if (CXX20ModuleInits && getContext().getCurrentNamedModule() &&
+ !getContext().getCurrentNamedModule()->isModuleImplementation()) {
SmallString<256> InitFnName;
llvm::raw_svector_ostream Out(InitFnName);
cast<ItaniumMangleContext>(getCXXABI().getMangleContext())
- .mangleModuleInitializer(getContext().getNamedModuleForCodeGen(), Out);
+ .mangleModuleInitializer(getContext().getCurrentNamedModule(), Out);
Fn = CreateGlobalInitOrCleanUpFunction(
FTy, llvm::Twine(InitFnName), FI, SourceLocation(), false,
llvm::GlobalVariable::ExternalLinkage);
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 7534304..d3cde11 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -529,7 +529,7 @@ static void setVisibilityFromDLLStorageClass(const clang::LangOptions &LO,
}
void CodeGenModule::Release() {
- Module *Primary = getContext().getNamedModuleForCodeGen();
+ Module *Primary = getContext().getCurrentNamedModule();
if (CXX20ModuleInits && Primary && !Primary->isHeaderLikeModule())
EmitModuleInitializers(Primary);
EmitDeferred();
diff --git a/clang/lib/Frontend/ASTUnit.cpp b/clang/lib/Frontend/ASTUnit.cpp
index bda49fb..b1e7db1 100644
--- a/clang/lib/Frontend/ASTUnit.cpp
+++ b/clang/lib/Frontend/ASTUnit.cpp
@@ -879,7 +879,7 @@ std::unique_ptr<ASTUnit> ASTUnit::LoadFromASTFile(
Module *M = HeaderInfo.lookupModule(AST->getLangOpts().CurrentModule);
if (M && AST->getLangOpts().isCompilingModule() && M->isModulePurview())
- AST->Ctx->setNamedModuleForCodeGen(M);
+ AST->Ctx->setCurrentNamedModule(M);
// Create an AST consumer, even though it isn't used.
if (ToLoad >= LoadASTOnly)
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 53e453b..e1d7c29 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -389,7 +389,7 @@ Sema::ActOnModuleDecl(SourceLocation StartLoc, SourceLocation ModuleLoc,
// statements, so imports are allowed.
ImportState = ModuleImportState::ImportAllowed;
- getASTContext().setNamedModuleForCodeGen(Mod);
+ getASTContext().setCurrentNamedModule(Mod);
// We already potentially made an implicit import (in the case of a module
// implementation unit importing its interface). Make this module visible