Commit bd677b9
committed
[CIR][Test] Add divergence test for vtable constant issue
This test documents a divergence between CIR and CodeGen where CIR
incorrectly emits vtables as mutable globals instead of immutable constants.
**Issue:**
CIR emits vtables with 'global' linkage:
@_ZTV4Base = linkonce_odr global { [3 x ptr] } ...
CodeGen correctly emits them as 'constant':
@_ZTV4Base = linkonce_odr unnamed_addr constant { [3 x ptr] } ... comdat
**Root Cause:**
In CIRGenModule.cpp:4081, createOrReplaceCXXRuntimeVariable() calls
createGlobalOp() without passing isConstant=true parameter.
**Impact:**
1. Vtables placed in .data instead of .rodata section
2. Security vulnerability - writable vtables enable exploits
3. Missed optimization opportunities
4. Diverges from CodeGen without justification
**Additional Issues:**
CIR also misses 'unnamed_addr' and 'comdat' attributes that CodeGen emits.
The test is marked XFAIL until the fix is implemented.
Test Plan:
Build and verify test fails as expected (documenting divergence):
bin/llvm-lit -v ../../clang/test/CIR/CodeGen/vtable-constant-divergence.cpp1 parent 98a979e commit bd677b9
1 file changed
+31
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments