summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenModule.cpp
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2023-10-02 18:30:18 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2023-10-02 18:31:54 +0800
commit3f0927368285505ead516ba7572baaa7f52b01a9 (patch)
treefc12718215f986a0999eef69a59fe4a91de67726 /clang/lib/CodeGen/CodeGenModule.cpp
parent7bc09a471fbc274d8632d1379d4134bec63fecc4 (diff)
[C++20] [Modules] Fix crash when emitting module inits for duplicated modules
Close https://github.com/llvm/llvm-project/issues/67893 The root cause of the crash is an oversight that we missed the point that the same module can be imported multiple times. And we should use `SmallSetVector` instead of `SmallVector` to filter the case.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index c96523c52562..925f5114e910 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -2938,6 +2938,9 @@ void CodeGenModule::EmitModuleInitializers(clang::Module *Primary) {
// Third any associated with the Privat eMOdule Fragment, if present.
if (auto PMF = Primary->getPrivateModuleFragment()) {
for (Decl *D : getContext().getModuleInitializers(PMF)) {
+ // Skip import decls, the inits for those are called explicitly.
+ if (isa<ImportDecl>(D))
+ continue;
assert(isa<VarDecl>(D) && "PMF initializer decl is not a var?");
EmitTopLevelDecl(D);
}