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
3 target datalayout = "e-p:64:64:64"
5 declare fastcc void @bar()
6 declare void @llvm.stackrestore(i8*)
7 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
8 declare void @llvm.memcpy.inline.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
9 declare void @has_sret(i8* sret(i8) %p)
10 declare void @has_noaliases(i32* noalias %p, i32* %q)
11 declare void @one_arg(i32)
15 @E = external global i8
17 define i32 @foo() noreturn {
19 %buf2 = alloca {i8, i8}, align 2
20 ; CHECK: Caller and callee calling convention differ
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
41 ; CHECK: Division by zero
43 ; CHECK: Division by zero
45 ; CHECK: Division by zero
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
53 ; CHECK: Shift count out of range
55 ; CHECK: Shift count out of range
57 ; CHECK: xor(undef, undef)
58 %xx = xor i32 undef, undef
59 ; CHECK: sub(undef, undef)
60 %xs = sub i32 undef, undef
62 ; CHECK: Write to read-only memory
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* 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)
83 ; CHECK: Write to read-only memory
84 call 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
86 call 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
88 call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (i32* @CG to i8*), i8* bitcast (i32* @CG to i8*), i64 1, i1 0)
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
105 ; CHECK: Static alloca outside of entry block
107 ; CHECK: Return statement in function with noreturn attribute
111 ; CHECK-NOT: Undefined behavior: Buffer overflow
112 ; CHECK-NOT: Memory reference address is misaligned
113 %e = bitcast i8* @E to i64*
116 ; CHECK: unreachable immediately preceded by instruction without side effects
120 ; CHECK: Unnamed function with non-local linkage
121 define void @0() nounwind {
125 ; CHECK: va_start called in a non-varargs function
126 declare void @llvm.va_start(i8*)
127 define void @not_vararg(i8* %p) nounwind {
128 call void @llvm.va_start(i8* %p)
132 ; CHECK: Undefined behavior: Branch to non-blockaddress
133 define void @use_indbr() {
134 indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
139 ; CHECK: Undefined behavior: Call with "tail" keyword references alloca
140 declare void @tailcallee(i8*)
141 define void @use_tail(i8* %valist) {
143 tail call void @tailcallee(i8* %t)
147 ; CHECK: Unusual: Returning alloca value
148 define i8* @return_local(i32 %n, i32 %m) {
149 %t = alloca i8, i32 %n
150 %s = getelementptr i8, i8* %t, i32 %m
154 ; CHECK: Unusual: Returning alloca value
155 define i32* @return_obscured_local() {
157 %retval = alloca i32*
159 store i32* %x, i32** %retval
162 %t0 = load i32*, i32** %retval
163 %t1 = insertvalue { i32, i32, i32* } zeroinitializer, i32* %t0, 2
164 %t2 = extractvalue { i32, i32, i32* } %t1, 2
167 %t3 = phi i32* [ %t2, %next ]
168 %t4 = bitcast i32* %t3 to i32*
169 %t5 = ptrtoint i32* %t4 to i64
171 %t7 = inttoptr i64 %t6 to i32*
175 ; CHECK: Undefined behavior: Undef pointer dereference
176 define i32* @self_reference() {
180 %t3 = phi i32* [ %t4, %exit ]
181 %t4 = bitcast i32* %t3 to i32*
182 %x = load volatile i32, i32* %t3
186 ; CHECK: Call return type mismatches callee return type
187 %struct = type { double, double }
188 declare i32 @nonstruct_callee() nounwind
189 define void @struct_caller() nounwind {
191 call %struct bitcast (i32 ()* @foo to %struct ()*)()
193 ; CHECK: Undefined behavior: indirectbr with no destinations
194 indirectbr i8* null, []
197 define 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)