<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/80949>80949</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [clang][C++20][Modules] Duplicated static local vars when function is exported from module interface unit
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Lancern
      </td>
    </tr>
</table>

<pre>
    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.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVMuO4zYQ_Br60liBomw9Djqsx3EuCbDYJOcBRbWtzlCkQLbmka8PSM9jx5id0wKGDatbXVXNYukY6ewQe7Hbi91ho1eefOj_0M5gcJvBj0_973SPDnhCOHlr_QO5M0Rk8CfgoF20msk7WB1xFNVXIQ9CvnzX8vIxy3J5go-LDwyzH1eLoEW1_7H_uUqO4fZWMwcaVsbbW6FaoVptH_RTvCVnyaFQnVAdnLzPxQ5E8zwKILJmMnnM4ysCQEBegwOh9kLt3wqiOVyx_VwCzZnkNfeExhi5fOPzgvhKUlR7-MVw6hfDCVWRM3YdEUR1Qz5yQD2L6rdPtL5SuyL17vmsyX10VGPyTPXV-JUToqhuPhz9885rsM8V_z0hLMGfg57Br7ysHEHUsixFLYFcZNRjtvaEgI8LGsYRAsbVcu5TopYFHFdnsutFLS9sawnajXC6KqhcMAZjhJEikzN5zjuL1hL88C8ajvAwkZlAB4SZIus7dPYJLo4fU7dPxCjA4EfCWPyo7J8F2IOx2p2hbApZlELdAE8UYcBJ35MPYLSDSS8LOsB0q-mUyCTDJPURnE8HFe5whAfiKRXf37paglBtrvmFaab_8u2PgE4PFkehugL-QpwjWLrDC_wS_GBxTgCLDkza2ic40SOOMDzBt-8gVNWUsiohMR5Wztv_9j3tIGL8kMXLomOxGftq7KpOb7AvG9moruwqtZn6AcdubNWpkp1qd7rEejcq05pWV9XWmHpDvZJqK5VsZLPdVapQraoNbmtZdm2DTSW2EmdNtrD2fi58OG8oxhX7VnbbbmP1gDbm6FQq710olVI09Kn_y7Ceo9hKS5Hj2wQmtjlvL2_sDmK3v7lkkpKXv3_mdIxid4DDulgyOpnw2TLWG23hXodkFnRvjqMIl_zEEU7Bzy8hS44xnLTBHNGbNdh-Yl5yVqujUMcz8bQOhfGzUMfE8_nnyxJ8cqVQxyw7CnXMyv8PAAD__4Yw3A0">