llvm.org GIT mirror llvm / 9616c18
Fix one-after-the-end type metadata handling in globalsplit. Itanium ABI may have an address point one byte after the end of a vtable. When such vtable global is split, the !type metadata needs to follow the right vtable. Differential Revision: https://reviews.llvm.org/D30716 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297236 91177308-0d34-0410-b5e6-96231b3b80d8 Evgeniy Stepanov 2 years ago
2 changed file(s) with 23 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
8484 uint64_t ByteOffset = cast(
8585 cast(Type->getOperand(0))->getValue())
8686 ->getZExtValue();
87 if (ByteOffset < SplitBegin || ByteOffset >= SplitEnd)
87 // Type metadata may be attached one byte after the end of the vtable, for
88 // classes without virtual methods in Itanium ABI. AFAIK, it is never
89 // attached to the first byte of a vtable. Subtract one to get the right
90 // slice.
91 // This is making an assumption that vtable groups are the only kinds of
92 // global variables that !type metadata can be attached to, and that they
93 // are either Itanium ABI vtable groups or contain a single vtable (i.e.
94 // Microsoft ABI vtables).
95 uint64_t AttachedTo = (ByteOffset == 0) ? ByteOffset : ByteOffset - 1;
96 if (AttachedTo < SplitBegin || AttachedTo >= SplitEnd)
8897 continue;
8998 SplitGV->addMetadata(
9099 LLVMContext::MD_type,
1111 ]
1212
1313 ; CHECK-NOT: @global =
14 ; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+$]]
15 ; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T2:![0-9]+$]]
14 ; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+]], !type [[T2:![0-9]+]], !type [[T3:![0-9]+$]]
15 ; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T4:![0-9]+]], !type [[T5:![0-9]+$]]
1616 ; CHECK-NOT: @global =
1717 @global = internal constant { [2 x i8* ()*], [1 x i8* ()*] } {
1818 [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2],
1919 [1 x i8* ()*] [i8* ()* @f3]
20 }, !type !0, !type !1
20 }, !type !0, !type !1, !type !2, !type !3, !type !4
2121
2222 ; CHECK: define i8* @f1()
2323 define i8* @f1() {
5050
5151 declare i1 @llvm.type.test(i8*, metadata) nounwind readnone
5252
53 ; CHECK: [[T1]] = !{i32 8, !"foo"}
54 ; CHECK: [[T2]] = !{i32 0, !"bar"}
55 !0 = !{i32 8, !"foo"}
56 !1 = !{i32 16, !"bar"}
53 ; CHECK: [[T1]] = !{i32 0, !"foo"}
54 ; CHECK: [[T2]] = !{i32 15, !"bar"}
55 ; CHECK: [[T3]] = !{i32 16, !"a"}
56 ; CHECK: [[T4]] = !{i32 1, !"b"}
57 ; CHECK: [[T5]] = !{i32 8, !"c"}
58 !0 = !{i32 0, !"foo"}
59 !1 = !{i32 15, !"bar"}
60 !2 = !{i32 16, !"a"}
61 !3 = !{i32 17, !"b"}
62 !4 = !{i32 24, !"c"}