Commit 863b2e5
[C++20] [Modules] Fix the duplicated static initializer problem (llvm#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.
(cherry picked from commit 259eaa6)1 parent c9e8540 commit 863b2e5
File tree
2 files changed
+20
-2
lines changed- clang
- lib/CodeGen
- test/Modules
2 files changed
+20
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7080 | 7080 | | |
7081 | 7081 | | |
7082 | 7082 | | |
7083 | | - | |
7084 | | - | |
| 7083 | + | |
| 7084 | + | |
7085 | 7085 | | |
7086 | 7086 | | |
7087 | 7087 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
0 commit comments