• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -bounds-checking -S | FileCheck %s
2target datalayout = "e-p:64:64:64-p1:16:16:16-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"
3
4@global = private unnamed_addr constant [10 x i8] c"ola\00mundo\00", align 1
5
6; CHECK: f1
7; no checks are possible here
8; CHECK-NOT: trap
9define void @f1(i8* nocapture %c) {
10entry:
11  %0 = load i8, i8* %c, align 1
12  %tobool1 = icmp eq i8 %0, 0
13  br i1 %tobool1, label %while.end, label %while.body
14
15while.body:
16  %c.addr.02 = phi i8* [ %incdec.ptr, %while.body ], [ %c, %entry ]
17  %incdec.ptr = getelementptr inbounds i8, i8* %c.addr.02, i64 -1
18  store i8 100, i8* %c.addr.02, align 1
19  %1 = load i8, i8* %incdec.ptr, align 1
20  %tobool = icmp eq i8 %1, 0
21  br i1 %tobool, label %while.end, label %while.body
22
23while.end:
24  ret void
25}
26
27
28; CHECK: f2
29define void @f2() {
30while.body.i.preheader:
31  %addr = getelementptr inbounds [10 x i8], [10 x i8]* @global, i64 0, i64 9
32  br label %while.body.i
33
34while.body.i:
35; CHECK: phi
36; CHECK-NEXT: phi
37; CHECK-NOT: phi
38  %c.addr.02.i = phi i8* [ %incdec.ptr.i, %while.body.i ], [ %addr, %while.body.i.preheader ]
39  %incdec.ptr.i = getelementptr inbounds i8, i8* %c.addr.02.i, i64 -1
40; CHECK: sub i64 10, %0
41; CHECK-NEXT: icmp ult i64 10, %0
42; CHECK-NEXT: icmp ult i64 {{.*}}, 1
43; CHECK-NEXT: or i1
44; CHECK-NEXT: br {{.*}}, label %trap
45  store i8 100, i8* %c.addr.02.i, align 1
46  %0 = load i8, i8* %incdec.ptr.i, align 1
47  %tobool.i = icmp eq i8 %0, 0
48  br i1 %tobool.i, label %fn.exit, label %while.body.i
49
50fn.exit:
51  ret void
52}
53
54
55@global_as1 = private unnamed_addr addrspace(1) constant [10 x i8] c"ola\00mundo\00", align 1
56
57define void @f1_as1(i8 addrspace(1)* nocapture %c) {
58; CHECK: @f1_as1
59; no checks are possible here
60; CHECK-NOT: trap
61; CHECK: add i16 undef, -1
62; CHECK-NOT: trap
63entry:
64  %0 = load i8, i8 addrspace(1)* %c, align 1
65  %tobool1 = icmp eq i8 %0, 0
66  br i1 %tobool1, label %while.end, label %while.body
67
68while.body:
69  %c.addr.02 = phi i8 addrspace(1)* [ %incdec.ptr, %while.body ], [ %c, %entry ]
70  %incdec.ptr = getelementptr inbounds i8, i8 addrspace(1)* %c.addr.02, i64 -1
71  store i8 100, i8 addrspace(1)* %c.addr.02, align 1
72  %1 = load i8, i8 addrspace(1)* %incdec.ptr, align 1
73  %tobool = icmp eq i8 %1, 0
74  br i1 %tobool, label %while.end, label %while.body
75
76while.end:
77  ret void
78}
79
80
81define void @f2_as1() {
82; CHECK: @f2_as1
83while.body.i.preheader:
84  %addr = getelementptr inbounds [10 x i8], [10 x i8] addrspace(1)* @global_as1, i16 0, i16 9
85  br label %while.body.i
86
87while.body.i:
88; CHECK: phi
89; CHECK-NEXT: phi
90; CHECK-NOT: phi
91  %c.addr.02.i = phi i8 addrspace(1)* [ %incdec.ptr.i, %while.body.i ], [ %addr, %while.body.i.preheader ]
92  %incdec.ptr.i = getelementptr inbounds i8, i8 addrspace(1)* %c.addr.02.i, i16 -1
93; CHECK: sub i16 10, %0
94; CHECK-NEXT: icmp ult i16 10, %0
95; CHECK-NEXT: icmp ult i16 {{.*}}, 1
96; CHECK-NEXT: or i1
97; CHECK-NEXT: br {{.*}}, label %trap
98  store i8 100, i8 addrspace(1)* %c.addr.02.i, align 1
99  %0 = load i8, i8 addrspace(1)* %incdec.ptr.i, align 1
100  %tobool.i = icmp eq i8 %0, 0
101  br i1 %tobool.i, label %fn.exit, label %while.body.i
102
103fn.exit:
104  ret void
105}
106