diff options
author | Petar Jovanovic <petar.jovanovic@imgtec.com> | 2016-03-09 14:12:47 +0000 |
---|---|---|
committer | Petar Jovanovic <petar.jovanovic@imgtec.com> | 2016-03-09 14:12:47 +0000 |
commit | 6ed4786900a930f16c25a7e2698dad753c603b29 (patch) | |
tree | 4c455cacc93908e5bb4f301c425ba41b805019a0 /test | |
parent | 2438757d1dce84fe1d68a89b0c118a1e49d605c9 (diff) |
Reland r262337 "calculate builtin_object_size if arg is a removable pointer"
Original commit message:
calculate builtin_object_size if argument is a removable pointer
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.
Patch by Strahinja Petrovic.
Differential Revision: http://reviews.llvm.org/D17337
Reland the original change with a small modification (first do a null check
and then do the cast) to satisfy ubsan.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263011 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r-- | test/Transforms/InstCombine/builtin-object-size-ptr.ll | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test/Transforms/InstCombine/builtin-object-size-ptr.ll b/test/Transforms/InstCombine/builtin-object-size-ptr.ll new file mode 100644 index 00000000000..b38513999dc --- /dev/null +++ b/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 |