Issue |
117899
|
Summary |
[C++20][Modules] clang++ not inlining tiny function exported in module
|
Labels |
clang
|
Assignees |
|
Reporter |
aleck099
|
**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
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs