Skip to content

[C++20][Modules] Incorrectly distincted static local vars  #80949

Closed
@Lancern

Description

@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 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.

Metadata

Metadata

Assignees

Labels

clang:modulesC++20 modules and Clang Header Modules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions