[llvm] r297236 - Fix one-after-the-end type metadata handling in globalsplit.

Evgeniy Stepanov via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 7 14:18:48 PST 2017


Author: eugenis
Date: Tue Mar  7 16:18:48 2017
New Revision: 297236

URL: http://llvm.org/viewvc/llvm-project?rev=297236&view=rev
Log:
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

Modified:
    llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp
    llvm/trunk/test/Transforms/GlobalSplit/basic.ll

Modified: llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp?rev=297236&r1=297235&r2=297236&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/GlobalSplit.cpp Tue Mar  7 16:18:48 2017
@@ -85,7 +85,16 @@ bool splitGlobal(GlobalVariable &GV) {
       uint64_t ByteOffset = cast<ConstantInt>(
               cast<ConstantAsMetadata>(Type->getOperand(0))->getValue())
               ->getZExtValue();
-      if (ByteOffset < SplitBegin || ByteOffset >= SplitEnd)
+      // Type metadata may be attached one byte after the end of the vtable, for
+      // classes without virtual methods in Itanium ABI. AFAIK, it is never
+      // attached to the first byte of a vtable. Subtract one to get the right
+      // slice.
+      // This is making an assumption that vtable groups are the only kinds of
+      // global variables that !type metadata can be attached to, and that they
+      // are either Itanium ABI vtable groups or contain a single vtable (i.e.
+      // Microsoft ABI vtables).
+      uint64_t AttachedTo = (ByteOffset == 0) ? ByteOffset : ByteOffset - 1;
+      if (AttachedTo < SplitBegin || AttachedTo >= SplitEnd)
         continue;
       SplitGV->addMetadata(
           LLVMContext::MD_type,

Modified: llvm/trunk/test/Transforms/GlobalSplit/basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/GlobalSplit/basic.ll?rev=297236&r1=297235&r2=297236&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/GlobalSplit/basic.ll (original)
+++ llvm/trunk/test/Transforms/GlobalSplit/basic.ll Tue Mar  7 16:18:48 2017
@@ -12,13 +12,13 @@ target triple = "x86_64-unknown-linux-gn
 ]
 
 ; CHECK-NOT: @global =
-; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+$]]
-; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T2:![0-9]+$]]
+; CHECK: @global.0 = private constant [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2], !type [[T1:![0-9]+]], !type [[T2:![0-9]+]], !type [[T3:![0-9]+$]]
+; CHECK: @global.1 = private constant [1 x i8* ()*] [i8* ()* @f3], !type [[T4:![0-9]+]], !type [[T5:![0-9]+$]]
 ; CHECK-NOT: @global =
 @global = internal constant { [2 x i8* ()*], [1 x i8* ()*] } {
   [2 x i8* ()*] [i8* ()* @f1, i8* ()* @f2],
   [1 x i8* ()*] [i8* ()* @f3]
-}, !type !0, !type !1
+}, !type !0, !type !1, !type !2, !type !3, !type !4
 
 ; CHECK: define i8* @f1()
 define i8* @f1() {
@@ -51,7 +51,13 @@ define void @foo() {
 
 declare i1 @llvm.type.test(i8*, metadata) nounwind readnone
 
-; CHECK: [[T1]] = !{i32 8, !"foo"}
-; CHECK: [[T2]] = !{i32 0, !"bar"}
-!0 = !{i32 8, !"foo"}
-!1 = !{i32 16, !"bar"}
+; CHECK: [[T1]] = !{i32 0, !"foo"}
+; CHECK: [[T2]] = !{i32 15, !"bar"}
+; CHECK: [[T3]] = !{i32 16, !"a"}
+; CHECK: [[T4]] = !{i32 1, !"b"}
+; CHECK: [[T5]] = !{i32 8, !"c"}
+!0 = !{i32 0, !"foo"}
+!1 = !{i32 15, !"bar"}
+!2 = !{i32 16, !"a"}
+!3 = !{i32 17, !"b"}
+!4 = !{i32 24, !"c"}




More information about the llvm-commits mailing list