1 ; RUN: opt -basicaa -lint -disable-output < %s 2>&1 | FileCheck %s
2 target datalayout = "e-p:64:64:64"
4 declare fastcc void @bar()
5 declare void @llvm.stackrestore(i8*)
6 declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i1) nounwind
7 declare void @has_sret(i8* sret %p)
8 declare void @has_noaliases(i32* noalias %p, i32* %q)
9 declare void @one_arg(i32)
13 @E = external global i8
15 define i32 @foo() noreturn {
17 %buf2 = alloca {i8, i8}, align 2
18 ; CHECK: Caller and callee calling convention differ
20 ; CHECK: Null pointer dereference
21 store i32 0, i32* null
22 ; CHECK: Null pointer dereference
23 %t = load i32, i32* null
24 ; CHECK: Undef pointer dereference
25 store i32 0, i32* undef
26 ; CHECK: Undef pointer dereference
27 %u = load i32, i32* undef
28 ; CHECK: All-ones pointer dereference
29 store i32 0, i32* inttoptr (i64 -1 to i32*)
30 ; CHECK: Address one pointer dereference
31 store i32 0, i32* inttoptr (i64 1 to i32*)
32 ; CHECK: Memory reference address is misaligned
33 store i8 0, i8* %buf, align 2
34 ; CHECK: Memory reference address is misaligned
35 %gep = getelementptr {i8, i8}, {i8, i8}* %buf2, i32 0, i32 1
36 store i8 0, i8* %gep, align 2
37 ; CHECK: Division by zero
39 ; CHECK: Division by zero
41 ; CHECK: Division by zero
43 ; CHECK: Division by zero
45 ; CHECK: extractelement index out of range
46 %ee = extractelement <4 x i32> zeroinitializer, i32 4
47 ; CHECK: insertelement index out of range
48 %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
49 ; CHECK: Shift count out of range
51 ; CHECK: Shift count out of range
53 ; CHECK: Shift count out of range
55 ; CHECK: xor(undef, undef)
56 %xx = xor i32 undef, undef
57 ; CHECK: sub(undef, undef)
58 %xs = sub i32 undef, undef
60 ; CHECK: Write to read-only memory
62 ; CHECK: Write to text section
63 store i32 8, i32* bitcast (i32()* @foo to i32*)
64 ; CHECK: Load from block address
65 %lb = load i32, i32* bitcast (i8* blockaddress(@foo, %next) to i32*)
66 ; CHECK: Call to block address
67 call void() bitcast (i8* blockaddress(@foo, %next) to void()*)()
68 ; CHECK: Undefined behavior: Null pointer dereference
69 call void @llvm.stackrestore(i8* null)
70 ; CHECK: Undefined behavior: Null pointer dereference
71 call void @has_sret(i8* null)
72 ; CHECK: Unusual: noalias argument aliases another argument
73 call void @has_noaliases(i32* @CG, i32* @CG)
74 ; CHECK: Call argument count mismatches callee argument count
75 call void (i32, i32) bitcast (void (i32)* @one_arg to void (i32, i32)*)(i32 0, i32 0)
76 ; CHECK: Call argument count mismatches callee argument count
77 call void () bitcast (void (i32)* @one_arg to void ()*)()
78 ; CHECK: Call argument type mismatches callee parameter type
79 call void (float) bitcast (void (i32)* @one_arg to void (float)*)(float 0.0)
81 ; CHECK: Write to read-only memory
82 call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (i32* @CG to i8*), i8* bitcast (i32* @CG2 to i8*), i64 1, i1 0)
83 ; CHECK: Unusual: noalias argument aliases another argument
84 call void @llvm.memcpy.p0i8.p0i8.i64(i8* bitcast (i32* @CG to i8*), i8* bitcast (i32* @CG to i8*), i64 1, i1 0)
86 ; CHECK: Undefined behavior: Buffer overflow
87 %wider = bitcast i8* %buf to i16*
88 store i16 0, i16* %wider
89 ; CHECK: Undefined behavior: Buffer overflow
90 %inner = getelementptr {i8, i8}, {i8, i8}* %buf2, i32 0, i32 1
91 %wider2 = bitcast i8* %inner to i16*
92 store i16 0, i16* %wider2
93 ; CHECK: Undefined behavior: Buffer overflow
94 %before = getelementptr i8, i8* %buf, i32 -1
95 %wider3 = bitcast i8* %before to i16*
96 store i16 0, i16* %wider3
101 ; CHECK: Static alloca outside of entry block
103 ; CHECK: Return statement in function with noreturn attribute
107 ; CHECK-NOT: Undefined behavior: Buffer overflow
108 ; CHECK-NOT: Memory reference address is misaligned
109 %e = bitcast i8* @E to i64*
112 ; CHECK: unreachable immediately preceded by instruction without side effects
116 ; CHECK: Unnamed function with non-local linkage
117 define void @0() nounwind {
121 ; CHECK: va_start called in a non-varargs function
122 declare void @llvm.va_start(i8*)
123 define void @not_vararg(i8* %p) nounwind {
124 call void @llvm.va_start(i8* %p)
128 ; CHECK: Undefined behavior: Branch to non-blockaddress
129 define void @use_indbr() {
130 indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
135 ; CHECK: Undefined behavior: Call with "tail" keyword references alloca
136 declare void @tailcallee(i8*)
137 define void @use_tail(i8* %valist) {
139 tail call void @tailcallee(i8* %t)
143 ; CHECK: Unusual: Returning alloca value
144 define i8* @return_local(i32 %n, i32 %m) {
145 %t = alloca i8, i32 %n
146 %s = getelementptr i8, i8* %t, i32 %m
150 ; CHECK: Unusual: Returning alloca value
151 define i32* @return_obscured_local() {
153 %retval = alloca i32*
155 store i32* %x, i32** %retval
158 %t0 = load i32*, i32** %retval
159 %t1 = insertvalue { i32, i32, i32* } zeroinitializer, i32* %t0, 2
160 %t2 = extractvalue { i32, i32, i32* } %t1, 2
163 %t3 = phi i32* [ %t2, %next ]
164 %t4 = bitcast i32* %t3 to i32*
165 %t5 = ptrtoint i32* %t4 to i64
167 %t7 = inttoptr i64 %t6 to i32*
171 ; CHECK: Undefined behavior: Undef pointer dereference
172 define i32* @self_reference() {
176 %t3 = phi i32* [ %t4, %exit ]
177 %t4 = bitcast i32* %t3 to i32*
178 %x = load volatile i32, i32* %t3
182 ; CHECK: Call return type mismatches callee return type
183 %struct = type { double, double }
184 declare i32 @nonstruct_callee() nounwind
185 define void @struct_caller() nounwind {
187 call %struct bitcast (i32 ()* @foo to %struct ()*)()
189 ; CHECK: Undefined behavior: indirectbr with no destinations
190 indirectbr i8* null, []