Commit 0255897
committed
[CIR][Test] Add divergence tests for vtable emission issues
This commit adds three tests documenting divergences between CIR and CodeGen
in vtable emission. All tests verify that CIR should emit the same attributes
as CodeGen but currently fails to do so.
**Tests Added:**
1. vtable-constant-divergence.cpp - Documents missing 'constant' attribute
2. vtable-unnamed-addr-divergence.cpp - Documents missing 'unnamed_addr' attribute
3. vtable-comdat-divergence.cpp - Documents missing 'comdat' attribute
**Issue:**
CIR emits vtables with 'global' linkage:
@_ZTV4Base = linkonce_odr global { [3 x ptr] } ...
CodeGen correctly emits them as 'constant' with additional attributes:
@_ZTV4Base = linkonce_odr unnamed_addr constant { [3 x ptr] } ... comdat
**Root Cause:**
In CIRGenModule.cpp:4081, createOrReplaceCXXRuntimeVariable() calls
createGlobalOp() without passing isConstant=true parameter. Additionally,
the unnamed_addr and comdat attributes are not being set.
**Impact:**
1. Vtables placed in .data instead of .rodata section
2. Security vulnerability - writable vtables enable exploits
3. Missed optimization opportunities from unnamed_addr merging
4. Incorrect linker behavior without comdat groups
5. Diverges from CodeGen without justification
All tests are marked XFAIL until the fixes are implemented. Each test uses
FileCheck to verify both CIR and CodeGen outputs, with the CIR check failing
due to the missing attributes.
Test Plan:
Build and verify tests fail as expected (documenting divergence):
bin/llvm-lit -v ../../clang/test/CIR/CodeGen/vtable-*-divergence.cpp1 parent 26199f0 commit 0255897
File tree
3 files changed
+108
-0
lines changed- clang/test/CIR/CodeGen
3 files changed
+108
-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 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 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 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
Lines changed: 36 additions & 0 deletions
| 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 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
0 commit comments