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)
12 @E = external global i8
14 define i32 @foo() noreturn {
16 %buf2 = alloca {i8, i8}, align 2
17 ; CHECK: Caller and callee calling convention differ
19 ; CHECK: Null pointer dereference
20 store i32 0, i32* null
21 ; CHECK: Null pointer dereference
22 %t = load i32, i32* null
23 ; CHECK: Undef pointer dereference
24 store i32 0, i32* undef
25 ; CHECK: Undef pointer dereference
26 %u = load i32, 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}, {i8, i8}* %buf2, i32 0, i32 1
35 store i8 0, i8* %gep, align 2
36 ; CHECK: Division by zero
38 ; CHECK: Division by zero
40 ; CHECK: Division by zero
42 ; CHECK: Division by zero
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
50 ; CHECK: Shift count out of range
52 ; CHECK: Shift count out of range
54 ; CHECK: xor(undef, undef)
55 %xx = xor i32 undef, undef
56 ; CHECK: sub(undef, undef)
57 %xs = sub i32 undef, undef
59 ; CHECK: Write to read-only memory
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, 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)
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, i1 0)
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}, {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, i8* %buf, i32 -1
92 %wider3 = bitcast i8* %before to i16*
93 store i16 0, i16* %wider3
98 ; CHECK: Static alloca outside of entry block
100 ; CHECK: Return statement in function with noreturn attribute
104 ; CHECK-NOT: Undefined behavior: Buffer overflow
105 ; CHECK-NOT: Memory reference address is misaligned
106 %e = bitcast i8* @E to i64*
109 ; CHECK: unreachable immediately preceded by instruction without side effects
113 ; CHECK: Unnamed function with non-local linkage
114 define void @0() nounwind {
118 ; CHECK: va_start called in a non-varargs function
119 declare void @llvm.va_start(i8*)
120 define void @not_vararg(i8* %p) nounwind {
121 call void @llvm.va_start(i8* %p)
125 ; CHECK: Undefined behavior: Branch to non-blockaddress
126 define void @use_indbr() {
127 indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
132 ; CHECK: Undefined behavior: Call with "tail" keyword references alloca
133 declare void @tailcallee(i8*)
134 define void @use_tail(i8* %valist) {
136 tail call void @tailcallee(i8* %t)
140 ; CHECK: Unusual: Returning alloca value
141 define i8* @return_local(i32 %n, i32 %m) {
142 %t = alloca i8, i32 %n
143 %s = getelementptr i8, i8* %t, i32 %m
147 ; CHECK: Unusual: Returning alloca value
148 define i32* @return_obscured_local() {
150 %retval = alloca i32*
152 store i32* %x, i32** %retval
155 %t0 = load i32*, i32** %retval
156 %t1 = insertvalue { i32, i32, i32* } zeroinitializer, i32* %t0, 2
157 %t2 = extractvalue { i32, i32, i32* } %t1, 2
160 %t3 = phi i32* [ %t2, %next ]
161 %t4 = bitcast i32* %t3 to i32*
162 %t5 = ptrtoint i32* %t4 to i64
164 %t7 = inttoptr i64 %t6 to i32*
168 ; CHECK: Undefined behavior: Undef pointer dereference
169 define i32* @self_reference() {
173 %t3 = phi i32* [ %t4, %exit ]
174 %t4 = bitcast i32* %t3 to i32*
175 %x = load volatile i32, i32* %t3
179 ; CHECK: Call return type mismatches callee return type
180 %struct = type { double, double }
181 declare i32 @nonstruct_callee() nounwind
182 define void @struct_caller() nounwind {
184 call %struct bitcast (i32 ()* @foo to %struct ()*)()
186 ; CHECK: Undefined behavior: indirectbr with no destinations
187 indirectbr i8* null, []