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