<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/117899>117899</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C++20][Modules] clang++ not inlining tiny function exported in module
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
aleck099
</td>
</tr>
</table>
<pre>
**f1.cpp**:
```cpp
module;
extern "C" int puts(const char* s);
export module f1;
export void foo() {
puts("Hello World");
}
```
**main.cpp**:
```cpp
import f1;
int main() {
foo();
}
```
compile with:
```sh
clang++ -std=c++23 -fprebuilt-module-path=. -O3 --precompile -x c++-module f1.cpp
clang++ -std=c++23 -fprebuilt-module-path=. -O3 -c f1.pcm
clang++ -std=c++23 -fprebuilt-module-path=. -O3 -c main.cpp
clang++ -fuse-ld=lld *.o
```
And `objdump` the output, the function `foo()` is not inlined:
```
0000000000001710 <foo@f1()>:
1710: 48 8d 3d 65 ee ff ff lea rdi,[rip+0xffffffffffffee65] # 57c <_IO_stdin_used+0x4>
1717: e9 64 00 00 00 jmp 1780 <puts@plt>
171c: cc int3
171d: cc int3
171e: cc int3
171f: cc int3
0000000000001720 <initializer for module f1>:
1720: c3 ret
1721: cc int3
1722: cc int3
1723: cc int3
1724: cc int3
1725: cc int3
1726: cc int3
1727: cc int3
1728: cc int3
1729: cc int3
172a: cc int3
172b: cc int3
172c: cc int3
172d: cc int3
172e: cc int3
172f: cc int3
0000000000001730 <main>:
1730: 50 push rax
1731: e8 da ff ff ff call 1710 <foo@f1()>
1736: 31 c0 xor eax,eax
1738: 59 pop rcx
1739: c3 ret
```
This is different behavior from what we did without modules
Before c++20 we write **main2.cpp**:
```cpp
extern "C" int puts(const char* s);
void foo() {
puts("Hello World");
}
int main() {
foo();
}
```
Compile with `clang++ -O3 main2.cpp`, and we get:
```
0000000000001140 <foo()>:
1140: 48 8d 3d bd 0e 00 00 lea rdi,[rip+0xebd] # 2004 <_IO_stdin_used+0x4>
1147: e9 e4 fe ff ff jmp 1030 <puts@plt>
114c: 0f 1f 40 00 nop DWORD PTR [rax+0x0]
0000000000001150 <main>:
1150: 50 push rax
1151: 48 8d 3d ac 0e 00 00 lea rdi,[rip+0xeac] # 2004 <_IO_stdin_used+0x4>
1158: e8 d3 fe ff ff call 1030 <puts@plt>
115d: 31 c0 xor eax,eax
115f: 59 pop rcx
1160: c3 ret
```
There is no call to `foo()` in `main()`
# Version Info
```
clang version 20.0.0git (https://github.com/llvm/llvm-project.git 74392bde2e603c8ca3f0956d4c55ba181fe9989b)
Target: x86_64-unknown-linux-gnu
Thread model: posix
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykV02P4jgT_jXmUgryR5yQAwc-3tY7h1WvRqOdYyuJK-CZEEeO083sr185ARJomgZ1hATB9lPf9ZTTptGbCnFO5JLI9SRt3dbYeVpi_psmySQz6s-c8AXhi4JN87rufxOxIHRBItp__P90sTOqLZGIJaEL3Du0FRDOV4Rz0JWDunUN4bPcVI2DfJtawhfQEJ4cT9TGOuhBoGD9v8PCq9EKCmMInxGeAIn98hGUcP5_LEsDP40tFeH8BEvi9VjTHrI3Ypfq6hOT9K6TPdLGW-IPnqsBMKh2Q25udrUuEd60217Ia7Z-vUyrDeFLwpcQNE4Rsc77Vy4gKGqLWatLF_ROCurUw6ynEDwLCILa4lFAsIfDweDk0Glv0pdk5B6nzndfxzk5_wKpaBsMSo9WlgoIX0zNhR8XlQISUZP9Uu2uJhEFt0UwratbR_iqeyvaKnfaVH7jEJiIgm6gMg50VeoK1UUMCF3Q0cNiRoGIlQcIacGO4f1ff8wH3W8hovsJAOEMZgqEgkgCIhSF_wBAian_skoTviJyaXVN-JLui9GDGEki1wckIFyAjHMv_uXb80vjlK5e2gZVdzD0Spw0iAcNMIEoBEoPn9Pza1f3m2edRV3VhLQu3RlQPgDlOVx9dOXEcECdHThfw_vBWMyKu3e_CxLvTN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