-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[C++20][Modules] Incorrectly distincted static local vars #80949
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-modules Author: Sirui Mu (Lancern)
Given the following set of translation units:
export module a;
export int __attribute__((always_inline)) foo() {
static int x;
return ++x;
} import a;
int test1() { return foo(); } import a;
int test2() { return foo(); } #include <iostream>
int test1();
int test2();
int main() {
std::cout << test1();
std::cout << test2();
} The program outputs Up to clang 17.0.1, this behavior can happen even if |
Although we may fix the issue by treating the imported static locals as available externally, it looks more consistency to not import non-inline function bodies at all no matter if it is always_inline or not. Since we already decided to not import the non-inline function bodies: https://isocpp.org/files/papers/P3092R0.html |
The previous solution gets some complaints so we probably need some workaround here. |
Given the following set of translation units:
The program outputs
11
instead of the expected result12
. Functiontest1
and functiontest2
access distinctstatic 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 withalways_inline
(with optimizations enabled). Seems like this problem is partially fixed by PR #71031 , but the PR missesalways_inline
functions.The text was updated successfully, but these errors were encountered: