summaryrefslogtreecommitdiff
path: root/test/Instrumentation/BoundsChecking
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2012-07-20 22:39:33 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2012-07-20 22:39:33 +0000
commit78435f6bb7574d3d26f8c5151e2c140c525b7994 (patch)
treef78c9a1e38b094ab49d15ca3bd581805a9b23f58 /test/Instrumentation/BoundsChecking
parente288cd100f86631ec0ade2a85930397a4ea7b21e (diff)
downloadllvm-78435f6bb7574d3d26f8c5151e2c140c525b7994.tar.gz
llvm-78435f6bb7574d3d26f8c5151e2c140c525b7994.tar.bz2
llvm-78435f6bb7574d3d26f8c5151e2c140c525b7994.tar.xz
move the bounds checking pass to the instrumentation folder, where it belongs. I dunno why in the world I dropped it in the Scalar folder in the first place.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160587 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Instrumentation/BoundsChecking')
-rw-r--r--test/Instrumentation/BoundsChecking/lit.local.cfg1
-rw-r--r--test/Instrumentation/BoundsChecking/many-trap.ll16
-rw-r--r--test/Instrumentation/BoundsChecking/phi.ll52
-rw-r--r--test/Instrumentation/BoundsChecking/simple.ll118
4 files changed, 187 insertions, 0 deletions
diff --git a/test/Instrumentation/BoundsChecking/lit.local.cfg b/test/Instrumentation/BoundsChecking/lit.local.cfg
new file mode 100644
index 0000000000..19eebc0ac7
--- /dev/null
+++ b/test/Instrumentation/BoundsChecking/lit.local.cfg
@@ -0,0 +1 @@
+config.suffixes = ['.ll', '.c', '.cpp']
diff --git a/test/Instrumentation/BoundsChecking/many-trap.ll b/test/Instrumentation/BoundsChecking/many-trap.ll
new file mode 100644
index 0000000000..0bbb9592b0
--- /dev/null
+++ b/test/Instrumentation/BoundsChecking/many-trap.ll
@@ -0,0 +1,16 @@
+; RUN: opt < %s -bounds-checking -S | FileCheck %s
+; RUN: opt < %s -bounds-checking -bounds-checking-single-trap -S | FileCheck -check-prefix=SINGLE %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+; CHECK: @f1
+define void @f1(i64 %x) nounwind {
+ %1 = alloca i128, i64 %x
+ %2 = load i128* %1, align 4
+ %3 = load i128* %1, align 4
+ ret void
+; CHECK: call void @llvm.trap()
+; CHECK: call void @llvm.trap()
+; CHECK-NOT: call void @llvm.trap()
+; SINGLE: call void @llvm.trap()
+; SINGLE-NOT: call void @llvm.trap()
+}
diff --git a/test/Instrumentation/BoundsChecking/phi.ll b/test/Instrumentation/BoundsChecking/phi.ll
new file mode 100644
index 0000000000..86b5922270
--- /dev/null
+++ b/test/Instrumentation/BoundsChecking/phi.ll
@@ -0,0 +1,52 @@
+; RUN: opt < %s -bounds-checking -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+@global = private unnamed_addr constant [10 x i8] c"ola\00mundo\00", align 1
+
+; CHECK: f1
+; no checks are possible here
+; CHECK-NOT: trap
+define void @f1(i8* nocapture %c) {
+entry:
+ %0 = load i8* %c, align 1
+ %tobool1 = icmp eq i8 %0, 0
+ br i1 %tobool1, label %while.end, label %while.body
+
+while.body:
+ %c.addr.02 = phi i8* [ %incdec.ptr, %while.body ], [ %c, %entry ]
+ %incdec.ptr = getelementptr inbounds i8* %c.addr.02, i64 -1
+ store i8 100, i8* %c.addr.02, align 1
+ %1 = load i8* %incdec.ptr, align 1
+ %tobool = icmp eq i8 %1, 0
+ br i1 %tobool, label %while.end, label %while.body
+
+while.end:
+ ret void
+}
+
+
+; CHECK: f2
+define void @f2() {
+while.body.i.preheader:
+ %addr = getelementptr inbounds [10 x i8]* @global, i64 0, i64 9
+ br label %while.body.i
+
+while.body.i:
+; CHECK: phi
+; CHECK-NEXT: phi
+; CHECK-NOT: phi
+ %c.addr.02.i = phi i8* [ %incdec.ptr.i, %while.body.i ], [ %addr, %while.body.i.preheader ]
+ %incdec.ptr.i = getelementptr inbounds i8* %c.addr.02.i, i64 -1
+; CHECK: sub i64 10, %0
+; CHECK-NEXT: icmp ult i64 10, %0
+; CHECK-NEXT: icmp ult i64 {{.*}}, 1
+; CHECK-NEXT: or i1
+; CHECK-NEXT: br {{.*}}, label %trap
+ store i8 100, i8* %c.addr.02.i, align 1
+ %0 = load i8* %incdec.ptr.i, align 1
+ %tobool.i = icmp eq i8 %0, 0
+ br i1 %tobool.i, label %fn.exit, label %while.body.i
+
+fn.exit:
+ ret void
+}
diff --git a/test/Instrumentation/BoundsChecking/simple.ll b/test/Instrumentation/BoundsChecking/simple.ll
new file mode 100644
index 0000000000..3d532c3cf3
--- /dev/null
+++ b/test/Instrumentation/BoundsChecking/simple.ll
@@ -0,0 +1,118 @@
+; RUN: opt < %s -bounds-checking -S | FileCheck %s
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+
+@.str = private constant [8 x i8] c"abcdefg\00" ; <[8 x i8]*>
+
+declare noalias i8* @malloc(i64) nounwind
+declare noalias i8* @calloc(i64, i64) nounwind
+declare noalias i8* @realloc(i8* nocapture, i64) nounwind
+
+; CHECK: @f1
+define void @f1() nounwind {
+ %1 = tail call i8* @malloc(i64 32)
+ %2 = bitcast i8* %1 to i32*
+ %idx = getelementptr inbounds i32* %2, i64 2
+; CHECK-NOT: trap
+ store i32 3, i32* %idx, align 4
+ ret void
+}
+
+; CHECK: @f2
+define void @f2() nounwind {
+ %1 = tail call i8* @malloc(i64 32)
+ %2 = bitcast i8* %1 to i32*
+ %idx = getelementptr inbounds i32* %2, i64 8
+; CHECK: trap
+ store i32 3, i32* %idx, align 4
+ ret void
+}
+
+; CHECK: @f3
+define void @f3(i64 %x) nounwind {
+ %1 = tail call i8* @calloc(i64 4, i64 %x)
+ %2 = bitcast i8* %1 to i32*
+ %idx = getelementptr inbounds i32* %2, i64 8
+; CHECK: mul i64 4, %
+; CHECK: sub i64 {{.*}}, 32
+; CHECK-NEXT: icmp ult i64 {{.*}}, 32
+; CHECK-NEXT: icmp ult i64 {{.*}}, 4
+; CHECK-NEXT: or i1
+; CHECK: trap
+ store i32 3, i32* %idx, align 4
+ ret void
+}
+
+; CHECK: @f4
+define void @f4(i64 %x) nounwind {
+ %1 = tail call i8* @realloc(i8* null, i64 %x) nounwind
+ %2 = bitcast i8* %1 to i32*
+ %idx = getelementptr inbounds i32* %2, i64 8
+; CHECK: trap
+ %3 = load i32* %idx, align 4
+ ret void
+}
+
+; CHECK: @f5
+define void @f5(i64 %x) nounwind {
+ %idx = getelementptr inbounds [8 x i8]* @.str, i64 0, i64 %x
+; CHECK: trap
+ %1 = load i8* %idx, align 4
+ ret void
+}
+
+; CHECK: @f6
+define void @f6(i64 %x) nounwind {
+ %1 = alloca i128
+; CHECK-NOT: trap
+ %2 = load i128* %1, align 4
+ ret void
+}
+
+; CHECK: @f7
+define void @f7(i64 %x) nounwind {
+ %1 = alloca i128, i64 %x
+; CHECK: mul i64 16,
+; CHECK: trap
+ %2 = load i128* %1, align 4
+ ret void
+}
+
+; CHECK: @f8
+define void @f8() nounwind {
+ %1 = alloca i128
+ %2 = alloca i128
+ %3 = select i1 undef, i128* %1, i128* %2
+; CHECK-NOT: trap
+ %4 = load i128* %3, align 4
+ ret void
+}
+
+; CHECK: @f9
+define void @f9(i128* %arg) nounwind {
+ %1 = alloca i128
+ %2 = select i1 undef, i128* %arg, i128* %1
+; CHECK-NOT: trap
+ %3 = load i128* %2, align 4
+ ret void
+}
+
+; CHECK: @f10
+define void @f10(i64 %x, i64 %y) nounwind {
+ %1 = alloca i128, i64 %x
+ %2 = alloca i128, i64 %y
+ %3 = select i1 undef, i128* %1, i128* %2
+; CHECK: select
+; CHECK: select
+; CHECK: trap
+ %4 = load i128* %3, align 4
+ ret void
+}
+
+; CHECK: @f11
+define void @f11(i128* byval %x) nounwind {
+ %1 = bitcast i128* %x to i8*
+ %2 = getelementptr inbounds i8* %1, i64 16
+; CHECK: br label
+ %3 = load i8* %2, align 4
+ ret void
+}