From 3f0927368285505ead516ba7572baaa7f52b01a9 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Mon, 2 Oct 2023 18:30:18 +0800 Subject: [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. --- clang/lib/CodeGen/CodeGenModule.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') 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(D)) + continue; assert(isa(D) && "PMF initializer decl is not a var?"); EmitTopLevelDecl(D); } -- cgit v1.2.3