Skip to content

Commit

Permalink
[ValueTracking] Properly handle non-sized types in isAligned function.
Browse files Browse the repository at this point in the history
Reviewers: apilipenko, reames, sanjoy, hfinkel

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D15597

llvm-svn: 256192
  • Loading branch information
Michael Zolotukhin committed Dec 21, 2015
1 parent 51a62f1 commit 0c97988
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
20 changes: 20 additions & 0 deletions llvm/test/Analysis/ValueTracking/memory-dereferenceable.ll
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

target datalayout = "e"

%TypeOpaque = type opaque

declare zeroext i1 @return_i1()

declare i32* @foo()
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 0c97988

Please sign in to comment.