| Issue |
240258
|
| Summary |
[FatLTO][VFE] Native-code partition has zeroed virtual function slots
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
zjy-dev
|
The native-code partition of a fat LTO compilation contains zeroed virtual-function slots, while the generated call sites still call through those slots.
Reproduced on x86_64 Linux with Clang 23.1.2 (`85ac560262434c9ccfc0c183ec22d4138ed647fb`) and Compiler Explorer's `clang_trunk` on 2026-11-09.
### Reproducer
Save as `trigger.cpp`:
```cpp
namespace {
struct Base {
virtual int f() { return 7; }
virtual int g() { return 9; }
};
struct Derived : Base {
int f() override { return 11; }
int g() override { return 13; }
};
}
void *make_obj(int k) {
return k ? static_cast<Base *>(new Derived()) : new Base();
}
int call_obj(void *p) {
Base *b = static_cast<Base *>(p);
return b->f() + b->g();
}
```
```sh
clang++ --target=x86_64-unknown-linux-gnu -O2 -flto -ffat-lto-objects \
-fvisibility=hidden -fsanitize=cfi-icall -fwhole-program-vtables \
-fvirtual-function-elimination -S trigger.cpp -o trigger.s
```
Relevant output:
```asm
_Z8call_objPv:
# prologue omitted
movq %rdi, %rbx
movq (%rdi), %rax
callq *(%rax)
movl %eax, %ebp
movq (%rbx), %rax
movq %rbx, %rdi
callq *8(%rax)
# remaining instructions omitted
_ZTVN12_GLOBAL__N_17DerivedE:
.quad 0
.quad _ZTIN12_GLOBAL__N_17DerivedE
.quad 0
.quad 0
_ZTVN12_GLOBAL__N_14BaseE:
.quad 0
.quad _ZTIN12_GLOBAL__N_14BaseE
.quad 0
.quad 0
```
Both live virtual method slots should point to their implementations in the native-code partition. The expected results of `call_obj(make_obj(0))` and `call_obj(make_obj(1))` are 16 and 24. The evidence above is from compilation and assembly inspection; no runtime result is claimed.
### Possible cause
`buildFatLTODefaultPipeline` runs `FatLtoCleanup`, `DropTypeTestsPass(DropTestKind::All)`, and the module optimization pipeline.
For this translation unit, VFE introduces `llvm.type.checked.load`, but there are no `llvm.type.test` or `llvm.public.type.test` declarations. `FatLtoCleanup` replaces the checked loads with ordinary vtable loads. In `LowerTypeTestsModule::dropTypeTests`, removal of `!vcall_visibility` is inside `if (TypeTestFunc || PublicTypeTestFunc)`. Consequently the metadata survives even though the checked loads are gone. Later `GlobalDCEPass` treats the virtual functions as unused and replaces their vtable slots with zero.
Relevant files: `llvm/lib/Transforms/IPO/FatLTOCleanup.cpp`, `llvm/lib/Transforms/IPO/LowerTypeTests.cpp`, and `llvm/lib/Passes/PassBuilderPipelines.cpp`.
Please ensure the fat-LTO native-code cleanup also removes the vcall visibility assumptions when dropping the checked-load intrinsics, including modules with no type-test declaration.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs