[cfi] Fix LowerBitSets on 32-bit targets.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Mon, 21 Dec 2015 22:14:04 +0000 (22:14 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Mon, 21 Dec 2015 22:14:04 +0000 (22:14 +0000)
This code attempts to truncate IntPtrTy to i32, which may be the same
type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256205 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/LowerBitSets.cpp
test/Transforms/LowerBitSets/pr25902.ll [new file with mode: 0644]

index 65d082b27a8460606c6cc7c3ad863b0d2d755a7d..7b515745c31224b51c58bd2b7634ef6ae8811624 100644 (file)
@@ -683,7 +683,7 @@ Constant *LowerBitSets::createJumpTableEntry(GlobalObject *Src, Function *Dest,
   ConstantInt *DispOffset =
       ConstantInt::get(IntPtrTy, Distance * kX86JumpTableEntrySize + 5);
   Constant *OffsetedDisp = ConstantExpr::getSub(Disp, DispOffset);
-  OffsetedDisp = ConstantExpr::getTrunc(OffsetedDisp, Int32Ty);
+  OffsetedDisp = ConstantExpr::getTruncOrBitCast(OffsetedDisp, Int32Ty);
 
   ConstantInt *Int3 = ConstantInt::get(Int8Ty, kInt3Code);
 
diff --git a/test/Transforms/LowerBitSets/pr25902.ll b/test/Transforms/LowerBitSets/pr25902.ll
new file mode 100644 (file)
index 0000000..b9a1203
--- /dev/null
@@ -0,0 +1,21 @@
+; PR25902: gold plugin crash.
+; RUN: opt -mtriple=i686-pc -S -lowerbitsets < %s
+
+define void @f(void ()* %p) {
+entry:
+  %a = bitcast void ()* %p to i8*, !nosanitize !1
+  %b = call i1 @llvm.bitset.test(i8* %a, metadata !"_ZTSFvvE"), !nosanitize !1
+  ret void
+}
+
+define void @g() {
+entry:
+  ret void
+}
+
+declare i1 @llvm.bitset.test(i8*, metadata)
+
+!llvm.bitsets = !{!0}
+
+!0 = !{!"_ZTSFvvE", void ()* @g, i64 0}
+!1 = !{}