summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Zolotukhin <mzolotukhin@apple.com>2015-12-21 20:38:18 +0000
committerMichael Zolotukhin <mzolotukhin@apple.com>2015-12-21 20:38:18 +0000
commit4c1d77039a5566842aaf9624c1c22a4bca968f41 (patch)
tree0f337a53e1bc29870055f5eebc13afe27bf8248b
parent9e02fe5b4a2d21e864f582f54a95a488e041e2e7 (diff)
[ValueTracking] Properly handle non-sized types in isAligned function.
Reviewers: apilipenko, reames, sanjoy, hfinkel Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D15597 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@256192 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Analysis/ValueTracking.cpp6
-rw-r--r--test/Analysis/ValueTracking/memory-dereferenceable.ll20
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index 358aa8ed895..314ec9c1886 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -3179,6 +3179,8 @@ static bool isAligned(const Value *Base, APInt Offset, unsigned Align,
if (!BaseAlign) {
Type *Ty = Base->getType()->getPointerElementType();
+ if (!Ty->isSized())
+ return false;
BaseAlign = DL.getABITypeAlignment(Ty);
}
@@ -3189,7 +3191,9 @@ static bool isAligned(const Value *Base, APInt Offset, unsigned Align,
}
static bool isAligned(const Value *Base, unsigned Align, const DataLayout &DL) {
- APInt Offset(DL.getTypeStoreSizeInBits(Base->getType()), 0);
+ Type *Ty = Base->getType();
+ assert(Ty->isSized() && "must be sized");
+ APInt Offset(DL.getTypeStoreSizeInBits(Ty), 0);
return isAligned(Base, Offset, Align, DL);
}
diff --git a/test/Analysis/ValueTracking/memory-dereferenceable.ll b/test/Analysis/ValueTracking/memory-dereferenceable.ll
index c7ca21ab061..c77d47413b9 100644
--- a/test/Analysis/ValueTracking/memory-dereferenceable.ll
+++ b/test/Analysis/ValueTracking/memory-dereferenceable.ll
@@ -5,6 +5,8 @@
target datalayout = "e"
+%TypeOpaque = type opaque
+
declare zeroext i1 @return_i1()
declare i32* @foo()
@@ -17,6 +19,7 @@ declare i32* @foo()
@globalptr.align1 = external global i8, align 1
@globalptr.align16 = external global i8, align 16
+; CHECK-LABEL: 'test'
define void @test(i32 addrspace(1)* dereferenceable(8) %dparam,
i8 addrspace(1)* dereferenceable(32) align 1 %dparam.align1,
i8 addrspace(1)* dereferenceable(32) align 16 %dparam.align16)
@@ -133,6 +136,23 @@ entry:
ret void
}
+; Just check that we don't crash.
+; CHECK-LABEL: 'opaque_type_crasher'
+define void @opaque_type_crasher(%TypeOpaque* dereferenceable(16) %a) {
+entry:
+ %bc = bitcast %TypeOpaque* %a to i8*
+ %ptr8 = getelementptr inbounds i8, i8* %bc, i32 8
+ %ptr32 = bitcast i8* %ptr8 to i32*
+ br i1 undef, label %if.then, label %if.end
+
+if.then:
+ %res = load i32, i32* %ptr32, align 4
+ br label %if.end
+
+if.end:
+ ret void
+}
+
declare i32 @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32, i32, i32)