[PATCH] D17337: __builtin_object_size problem with pointer as argument
Strahinja Petrovic via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 17 09:02:24 PST 2016
spetrovic created this revision.
spetrovic added reviewers: davidxl, george.burgess.iv, petarj.
spetrovic added a subscriber: llvm-commits.
spetrovic set the repository for this revision to rL LLVM.
This patch fixes calculating correct value for __builtin_object_size function when pointer is used only in __builtin_object_size function call and never after that.
Repository:
rL LLVM
http://reviews.llvm.org/D17337
Files:
lib/Transforms/InstCombine/InstructionCombining.cpp
test/Transforms/InstCombine/builtin-object-size-ptr.ll
Index: test/Transforms/InstCombine/builtin-object-size-ptr.ll
===================================================================
--- test/Transforms/InstCombine/builtin-object-size-ptr.ll
+++ test/Transforms/InstCombine/builtin-object-size-ptr.ll
@@ -0,0 +1,34 @@
+; RUN: opt -instcombine -S < %s | FileCheck %s
+
+; int foo() {
+; struct V { char buf1[10];
+; int b;
+; char buf2[10];
+; } var;
+;
+; char *p = &var.buf1[1];
+; return __builtin_object_size (p, 0);
+; }
+
+%struct.V = type { [10 x i8], i32, [10 x i8] }
+
+define i32 @foo() #0 {
+entry:
+ %var = alloca %struct.V, align 4
+ %0 = bitcast %struct.V* %var to i8*
+ call void @llvm.lifetime.start(i64 28, i8* %0) #3
+ %buf1 = getelementptr inbounds %struct.V, %struct.V* %var, i32 0, i32 0
+ %arrayidx = getelementptr inbounds [10 x i8], [10 x i8]* %buf1, i64 0, i64 1
+ %1 = call i64 @llvm.objectsize.i64.p0i8(i8* %arrayidx, i1 false)
+ %conv = trunc i64 %1 to i32
+ call void @llvm.lifetime.end(i64 28, i8* %0) #3
+ ret i32 %conv
+; CHECK: ret i32 27
+; CHECK-NOT: ret i32 -1
+}
+
+declare void @llvm.lifetime.start(i64, i8* nocapture) #1
+
+declare i64 @llvm.objectsize.i64.p0i8(i8*, i1) #2
+
+declare void @llvm.lifetime.end(i64, i8* nocapture) #1
Index: lib/Transforms/InstCombine/InstructionCombining.cpp
===================================================================
--- lib/Transforms/InstCombine/InstructionCombining.cpp
+++ lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1907,7 +1907,6 @@
case Intrinsic::invariant_end:
case Intrinsic::lifetime_start:
case Intrinsic::lifetime_end:
- case Intrinsic::objectsize:
Users.emplace_back(I);
continue;
}
@@ -1949,12 +1948,6 @@
C->isFalseWhenEqual()));
} else if (isa<BitCastInst>(I) || isa<GetElementPtrInst>(I)) {
replaceInstUsesWith(*I, UndefValue::get(I->getType()));
- } else if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
- if (II->getIntrinsicID() == Intrinsic::objectsize) {
- ConstantInt *CI = cast<ConstantInt>(II->getArgOperand(1));
- uint64_t DontKnow = CI->isZero() ? -1ULL : 0;
- replaceInstUsesWith(*I, ConstantInt::get(I->getType(), DontKnow));
- }
}
eraseInstFromFunction(*I);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17337.48197.patch
Type: text/x-patch
Size: 2401 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160217/cb7bd481/attachment.bin>
More information about the llvm-commits
mailing list