• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -basicaa -lint -disable-output < %s 2>&1 | FileCheck %s
2target datalayout = "e-p:64:64:64"
3
4declare fastcc void @bar()
5declare void @llvm.stackrestore(i8*)
6declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
7declare void @has_sret(i8* sret %p)
8declare void @has_noaliases(i32* noalias %p, i32* %q)
9declare void @one_arg(i32)
10
11@CG = constant i32 7
12@E = external global i8
13
14define i32 @foo() noreturn {
15  %buf = alloca i8
16  %buf2 = alloca {i8, i8}, align 2
17; CHECK: Caller and callee calling convention differ
18  call void @bar()
19; CHECK: Null pointer dereference
20  store i32 0, i32* null
21; CHECK: Null pointer dereference
22  %t = load i32* null
23; CHECK: Undef pointer dereference
24  store i32 0, i32* undef
25; CHECK: Undef pointer dereference
26  %u = load i32* undef
27; CHECK: All-ones pointer dereference
28  store i32 0, i32* inttoptr (i64 -1 to i32*)
29; CHECK: Address one pointer dereference
30  store i32 0, i32* inttoptr (i64 1 to i32*)
31; CHECK: Memory reference address is misaligned
32  store i8 0, i8* %buf, align 2
33; CHECK: Memory reference address is misaligned
34  %gep = getelementptr {i8, i8}* %buf2, i32 0, i32 1
35  store i8 0, i8* %gep, align 2
36; CHECK: Division by zero
37  %sd = sdiv i32 2, 0
38; CHECK: Division by zero
39  %ud = udiv i32 2, 0
40; CHECK: Division by zero
41  %sr = srem i32 2, 0
42; CHECK: Division by zero
43  %ur = urem i32 2, 0
44; CHECK: extractelement index out of range
45  %ee = extractelement <4 x i32> zeroinitializer, i32 4
46; CHECK: insertelement index out of range
47  %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
48; CHECK: Shift count out of range
49  %r = lshr i32 0, 32
50; CHECK: Shift count out of range
51  %q = ashr i32 0, 32
52; CHECK: Shift count out of range
53  %l = shl i32 0, 32
54; CHECK: xor(undef, undef)
55  %xx = xor i32 undef, undef
56; CHECK: sub(undef, undef)
57  %xs = sub i32 undef, undef
58
59; CHECK: Write to read-only memory
60  store i32 8, i32* @CG
61; CHECK: Write to text section
62  store i32 8, i32* bitcast (i32()* @foo to i32*)
63; CHECK: Load from block address
64  %lb = load i32* bitcast (i8* blockaddress(@foo, %next) to i32*)
65; CHECK: Call to block address
66  call void()* bitcast (i8* blockaddress(@foo, %next) to void()*)()
67; CHECK: Undefined behavior: Null pointer dereference
68  call void @llvm.stackrestore(i8* null)
69; CHECK: Undefined behavior: Null pointer dereference
70  call void @has_sret(i8* null)
71; CHECK: Unusual: noalias argument aliases another argument
72  call void @has_noaliases(i32* @CG, i32* @CG)
73; CHECK: Call argument count mismatches callee argument count
74  call void (i32, i32)* bitcast (void (i32)* @one_arg to void (i32, i32)*)(i32 0, i32 0)
75; CHECK: Call argument count mismatches callee argument count
76  call void ()* bitcast (void (i32)* @one_arg to void ()*)()
77; CHECK: Call argument type mismatches callee parameter type
78  call void (float)* bitcast (void (i32)* @one_arg to void (float)*)(float 0.0)
79
80; CHECK: Write to read-only memory
81  call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (i32* @CG to i8*), i8* bitcast (i32* @CG to i8*), i64 1, i32 1, i1 0)
82
83; CHECK: Undefined behavior: Buffer overflow
84  %wider = bitcast i8* %buf to i16*
85  store i16 0, i16* %wider
86; CHECK: Undefined behavior: Buffer overflow
87  %inner = getelementptr {i8, i8}* %buf2, i32 0, i32 1
88  %wider2 = bitcast i8* %inner to i16*
89  store i16 0, i16* %wider2
90; CHECK: Undefined behavior: Buffer overflow
91  %before = getelementptr i8* %buf, i32 -1
92  %wider3 = bitcast i8* %before to i16*
93  store i16 0, i16* %wider3
94
95  br label %next
96
97next:
98; CHECK: Static alloca outside of entry block
99  %a = alloca i32
100; CHECK: Return statement in function with noreturn attribute
101  ret i32 0
102
103foo:
104; CHECK-NOT: Undefined behavior: Buffer overflow
105; CHECK-NOT: Memory reference address is misaligned
106  %e = bitcast i8* @E to i64*
107  store i64 0, i64* %e
108  %z = add i32 0, 0
109; CHECK: unreachable immediately preceded by instruction without side effects
110  unreachable
111}
112
113; CHECK: Unnamed function with non-local linkage
114define void @0() nounwind {
115  ret void
116}
117
118; CHECK: va_start called in a non-varargs function
119declare void @llvm.va_start(i8*)
120define void @not_vararg(i8* %p) nounwind {
121  call void @llvm.va_start(i8* %p)
122  ret void
123}
124
125; CHECK: Undefined behavior: Branch to non-blockaddress
126define void @use_indbr() {
127  indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
128block:
129  unreachable
130}
131
132; CHECK: Undefined behavior: Call with "tail" keyword references alloca
133declare void @tailcallee(i8*)
134define void @use_tail(i8* %valist) {
135  %t = alloca i8
136  tail call void @tailcallee(i8* %t)
137  ret void
138}
139
140; CHECK: Unusual: Returning alloca value
141define i8* @return_local(i32 %n, i32 %m) {
142  %t = alloca i8, i32 %n
143  %s = getelementptr i8* %t, i32 %m
144  ret i8* %s
145}
146
147; CHECK: Unusual: Returning alloca value
148define i32* @return_obscured_local() {
149entry:
150  %retval = alloca i32*
151  %x = alloca i32
152  store i32* %x, i32** %retval
153  br label %next
154next:
155  %t0 = load i32** %retval
156  %t1 = insertvalue { i32, i32, i32* } zeroinitializer, i32* %t0, 2
157  %t2 = extractvalue { i32, i32, i32* } %t1, 2
158  br label %exit
159exit:
160  %t3 = phi i32* [ %t2, %next ]
161  %t4 = bitcast i32* %t3 to i32*
162  %t5 = ptrtoint i32* %t4 to i64
163  %t6 = add i64 %t5, 0
164  %t7 = inttoptr i64 %t6 to i32*
165  ret i32* %t7
166}
167
168; CHECK: Undefined behavior: Undef pointer dereference
169define i32* @self_reference() {
170entry:
171  unreachable
172exit:
173  %t3 = phi i32* [ %t4, %exit ]
174  %t4 = bitcast i32* %t3 to i32*
175  %x = load volatile i32* %t3
176  br label %exit
177}
178
179; CHECK: Call return type mismatches callee return type
180%struct = type { double, double }
181declare i32 @nonstruct_callee() nounwind
182define void @struct_caller() nounwind {
183entry:
184  call %struct bitcast (i32 ()* @foo to %struct ()*)()
185
186  ; CHECK: Undefined behavior: indirectbr with no destinations
187  indirectbr i8* null, []
188}
189