[llvm-commits] [llvm] r162098 - in /llvm/trunk: lib/Analysis/MemoryBuiltins.cpp test/Transforms/InstCombine/objsize.ll
Benjamin Kramer
benny.kra at googlemail.com
Fri Aug 17 07:16:37 PDT 2012
Author: d0k
Date: Fri Aug 17 09:16:37 2012
New Revision: 162098
URL: http://llvm.org/viewvc/llvm-project?rev=162098&view=rev
Log:
Guard MemoryBuiltins against self-looping GEPs, which can occur in unreachable code due to constant propagation.
Fixes PR13621.
Modified:
llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
llvm/trunk/test/Transforms/InstCombine/objsize.ll
Modified: llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryBuiltins.cpp?rev=162098&r1=162097&r2=162098&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryBuiltins.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryBuiltins.cpp Fri Aug 17 09:16:37 2012
@@ -473,6 +473,10 @@
}
SizeOffsetType ObjectSizeOffsetVisitor::visitGEPOperator(GEPOperator &GEP) {
+ // Ignore self-referencing GEPs, they can occur in unreachable code.
+ if (&GEP == GEP.getPointerOperand())
+ return unknown();
+
SizeOffsetType PtrData = compute(GEP.getPointerOperand());
if (!bothKnown(PtrData) || !GEP.hasAllConstantIndices())
return unknown();
Modified: llvm/trunk/test/Transforms/InstCombine/objsize.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/objsize.ll?rev=162098&r1=162097&r2=162098&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/objsize.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/objsize.ll Fri Aug 17 09:16:37 2012
@@ -238,3 +238,20 @@
return:
ret i32 42
}
+
+; CHECK: @PR13621
+define i32 @PR13621(i1 %bool) nounwind {
+entry:
+ %cond = or i1 %bool, true
+ br i1 %cond, label %return, label %xpto
+
+; technically reachable, but this malformed IR may appear as a result of constant propagation
+xpto:
+ %gep = getelementptr i8* %gep, i32 1
+ %o = call i32 @llvm.objectsize.i32(i8* %gep, i1 true)
+; CHECK: ret i32 undef
+ ret i32 %o
+
+return:
+ ret i32 7
+}
More information about the llvm-commits
mailing list