summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/CodeGenPrepare/builtin-condition.ll
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2016-12-20 23:46:36 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2016-12-20 23:46:36 +0000
commit3f08914e7e58d195818f38f396b9550a7d896ea9 (patch)
treea727a581aaa563a7a076f66cf3bab96ed61e18c9 /llvm/test/Transforms/CodeGenPrepare/builtin-condition.ll
parente52614b5c7c25d4b674aa304b6a6e18c1d201c2e (diff)
downloadbcm5719-llvm-3f08914e7e58d195818f38f396b9550a7d896ea9.tar.gz
bcm5719-llvm-3f08914e7e58d195818f38f396b9550a7d896ea9.zip
[Analysis] Centralize objectsize lowering logic.
We're currently doing nearly the same thing for @llvm.objectsize in three different places: two of them are missing checks for overflow, and one of them could subtly break if InstCombine gets much smarter about removing alloc sites. Seems like a good idea to not do that. llvm-svn: 290214
Diffstat (limited to 'llvm/test/Transforms/CodeGenPrepare/builtin-condition.ll')
-rw-r--r--llvm/test/Transforms/CodeGenPrepare/builtin-condition.ll35
1 files changed, 34 insertions, 1 deletions
diff --git a/llvm/test/Transforms/CodeGenPrepare/builtin-condition.ll b/llvm/test/Transforms/CodeGenPrepare/builtin-condition.ll
index e18d1b0fc0e..0d41e9e1edd 100644
--- a/llvm/test/Transforms/CodeGenPrepare/builtin-condition.ll
+++ b/llvm/test/Transforms/CodeGenPrepare/builtin-condition.ll
@@ -1,5 +1,38 @@
; RUN: opt -codegenprepare -S < %s | FileCheck %s
+; Ensure we act sanely on overflow.
+; CHECK-LABEL: define i32 @bar
+define i32 @bar() {
+entry:
+ ; CHECK: ret i32 -1
+ %az = alloca [2147483649 x i32], align 16
+ %a = alloca i8*, align 8
+ %arraydecay = getelementptr inbounds [2147483649 x i32], [2147483649 x i32]* %az, i32 0, i32 0
+ %0 = bitcast i32* %arraydecay to i8*
+ store i8* %0, i8** %a, align 8
+ %1 = load i8*, i8** %a, align 8
+ %2 = call i32 @llvm.objectsize.i32.p0i8(i8* %1, i1 false)
+ ret i32 %2
+}
+
+; CHECK-LABEL: define i32 @baz
+define i32 @baz(i32 %n) {
+entry:
+ ; CHECK: ret i32 -1
+ %az = alloca [1 x i32], align 16
+ %bz = alloca [4294967297 x i32], align 16
+ %tobool = icmp ne i32 %n, 0
+ %arraydecay = getelementptr inbounds [1 x i32], [1 x i32]* %az, i64 0, i64 0
+ %arraydecay1 = getelementptr inbounds [4294967297 x i32], [4294967297 x i32]* %bz, i64 0, i64 0
+ %cond = select i1 %tobool, i32* %arraydecay, i32* %arraydecay1
+ %0 = bitcast i32* %cond to i8*
+ %1 = call i32 @llvm.objectsize.i32.p0i8(i8* %0, i1 false)
+ ret i32 %1
+}
+
+declare i32 @llvm.objectsize.i32.p0i8(i8*, i1)
+
+; The following tests were generated by:
; #include<stdlib.h>
; #define STATIC_BUF_SIZE 10
; #define LARGER_BUF_SIZE 30
@@ -87,4 +120,4 @@ entry:
ret void
}
-declare i32 @printf(i8* nocapture readonly, ...) \ No newline at end of file
+declare i32 @printf(i8* nocapture readonly, ...)
OpenPOWER on IntegriCloud