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

    <tr>
        <th>Summary</th>
        <td>
            [C++20][Modules][ABI] Silent bad codegen in module with TU-local exposure
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    consider:

mod1.cppm
```c++
export module mod1;

static int func1_internal() { return 4;}
export inline int func2_external() { return func1_internal(); }
```

main.cpp
```c++
import mod1;
static int func1_internal() {
 return 5;
}
int main() {
        return func2_external() + func1_internal();
}
```

this program returns "8" when compiled with clang.

This code is ill-formed, because `func2_external()` exposes the TU-local `func1_internal()`, but clang doesn't diagnose it.

Instead of diagnosing clang instead generates bad code, emitting code for the definition of func1_internal inside mod1.cppm when compiling the main.cpp TU and emitting no code for "func1_internal()" inside main.

Sidenote: right now it seems like just adding inline is enough to cause func2_external() to be emitted as a weak symbol in importing TUs, which isn't really ideal, it could just as well still be a strong extern symbol emitted inside mod1's associated object file.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMlEGPmzwTxz-NcxltBAZCcuCQ7CpSD--pu-fK2ANMa-zIY5ru--kfGUh2-zSVHmQJWfb85_-zx6OYqXeIjahOonrZqCkOPjStCnpQQQf1_03rzXujvWMyGERxFFkaozf5Vl8uY5rusmVoIU9pZEf8dfEhwujNZDH9clGclkiOKpIGchG6yen8G7mIwSkr5F7IA4j6BAHjFByUKah--dAjZ8nhPVZ-w19_i32kLYoTLHp3yyuNIpdoHsPQeINZKf4DgsiONyfVij4nTjEp2-871--T9T_R5OlvTHfxf1HFgRguwfdBjas2g5ApTMJ1QAfajxeyaOBKcQBtleu3S-xritXeIBADWfvU-TCiEfIZWtRqYgSxyx45FbsM0nUxMsQB4fXtyXqt7G3_HwC7bFad4mIAjEd2QtYRDKneeUaguNr64jiiMuC72yK5fo2jda1Hh0FFZGiVmRmSPo4U47w5QXU-zOYMduQokndJ8nd7SZDMUr1zqX8-s6SUBG6VA69voJz5SOP8RyYh5UNyKe85ksyC-JUMOh9RFEcI1A8RnL8CRWDEkcHSD4TvE0dQxtCMvbwJBnR-6geIHpYLelhH0UOLi000oBgUXFH9AH4fW5-YYSn3JP36xunorgPpAWi9lIDK2ncgg0nzOTnTfrJmNcVwRWuBI1mbMingGLzrYfFxy3Mz8OmMhawZFLPXpNKSb7-jjtCRxe3GNIU5FAe1wSavq7zc78u82AxNp4wpK62q8nDIiz12RdnutdzpXakK3JsNNTKTVVZnUmZFURTbquvyqsp2dZYdysO-FGWGoyK7tfbnuPWh3xDzhE1e7uo631jVouW5P0rp8ArzqpAytcvQpKCndupZlJkljvwhEynaubE-L51EZqJ6EdXpf3NT5GVyPH0R1Qt8JYsu3gu2R5duYm2f8-O8P6P5bU0BN1OwzRDjhVNTlmchzz3FYWq32o9CnpOP9fd0CT6dpZDn2T0LeV7xfjbynwAAAP__hfbxHQ">