OSDN Git Service

InstCombine: Turn _chk functions into the "unsafe" variant if length and max langth...
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 6 Jan 2011 14:22:52 +0000 (14:22 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 6 Jan 2011 14:22:52 +0000 (14:22 +0000)
This happens when we take the (non-constant) length from a malloc.

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

lib/Transforms/InstCombine/InstCombineCalls.cpp
test/Transforms/InstCombine/objsize.ll

index 603a010..ecd2243 100644 (file)
@@ -722,6 +722,8 @@ protected:
     NewInstruction = IC->ReplaceInstUsesWith(*CI, With);
   }
   bool isFoldable(unsigned SizeCIOp, unsigned SizeArgOp, bool isString) const {
+    if (CI->getArgOperand(SizeCIOp) == CI->getArgOperand(SizeArgOp))
+      return true;
     if (ConstantInt *SizeCI =
                            dyn_cast<ConstantInt>(CI->getArgOperand(SizeCIOp))) {
       if (SizeCI->isAllOnesValue())
index 9950e5f..4154ea0 100644 (file)
@@ -176,3 +176,14 @@ define i32 @test9(i32 %x) {
 ; CHECK-NOT: ret i32 %x
   ret i32 %objsize
 }
+
+define i8* @test10(i32 %x) {
+; CHECK: @test10
+  %alloc = call noalias i8* @malloc(i32 %x) nounwind
+  %objsize = call i32 @llvm.objectsize.i32(i8* %alloc, i1 false) nounwind readonly
+  tail call i8* @__memset_chk(i8* %alloc, i32 0, i32 %x, i32 %objsize) nounwind
+; CHECK-NOT: @llvm.objectsize
+; CHECK: @llvm.memset
+  ret i8* %alloc
+; CHECK: ret i8*
+}