Issue |
80949
|
Summary |
[clang][C++20][Modules] Duplicated static local vars when function is exported from module interface unit
|
Labels |
clang
|
Assignees |
|
Reporter |
Lancern
|
Given the following set of translation units:
```cpp
export module a;
export int __attribute__((always_inline)) foo() {
static int x;
return ++x;
}
```
```cpp
import a;
int test1() { return foo(); }
```
```cpp
import a;
int test2() { return foo(); }
```
```cpp
#include <iostream>
int test1();
int test2();
int main() {
std::cout << test1();
std::cout << test2();
}
```
The program outputs `11` instead of the expected result `12`. Function `test1` and function `test2` access distinct `static int x` objects which are mistakenly inlined into their bodies.
Up to clang 17.0.1, this behavior can happen even if `foo` is not marked with `always_inline` (with optimizations enabled). Seems like this problem is partially fixed by PR #71031 , but the PR misses `always_inline` functions.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs