diff options
author | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2024-10-30 17:27:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-30 17:27:04 +0800 |
commit | 259eaa6878ead1e2e7ef572a874dc3d885c1899b (patch) | |
tree | 6938a09f0c49ee7fc9f9f888cb3a83f0e0f0ade3 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | e61a7dc256bd530a0b9551e2732e5b5b77e2cd1e (diff) | |
download | llvm-259eaa6878ead1e2e7ef572a874dc3d885c1899b.zip llvm-259eaa6878ead1e2e7ef572a874dc3d885c1899b.tar.gz llvm-259eaa6878ead1e2e7ef572a874dc3d885c1899b.tar.bz2 |
[C++20] [Modules] Fix the duplicated static initializer problem (#114193)
Reproducer:
```
//--- a.cppm
export module a;
int func();
static int a = func();
//--- a.cpp
import a;
```
The `func()` should only execute once. However, before this patch we
will somehow import `static int a` from a.cppm incorrectly and
initialize that again.
This is super bad and can introduce serious runtime behaviors.
And also surprisingly, it looks like the root cause of the problem is
simply some oversight choosing APIs.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 2bcca5e..ba376f9 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -7146,8 +7146,8 @@ void CodeGenModule::EmitTopLevelDecl(Decl *D) { // For C++ standard modules we are done - we will call the module // initializer for imported modules, and that will likewise call those for // any imports it has. - if (CXX20ModuleInits && Import->getImportedOwningModule() && - !Import->getImportedOwningModule()->isModuleMapModule()) + if (CXX20ModuleInits && Import->getImportedModule() && + Import->getImportedModule()->isNamedModule()) break; // For clang C++ module map modules the initializers for sub-modules are |