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, i32, 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 define i32 @foo() noreturn {
15 %buf2 = alloca {i8, i8}, align 2
16 ; CHECK: Caller and callee calling convention differ
18 ; CHECK: Null pointer dereference
19 store i32 0, i32* null
20 ; CHECK: Null pointer dereference
22 ; CHECK: Undef pointer dereference
23 store i32 0, i32* undef
24 ; CHECK: Undef pointer dereference
26 ; CHECK: All-ones pointer dereference
27 store i32 0, i32* inttoptr (i64 -1 to i32*)
28 ; CHECK: Address one pointer dereference
29 store i32 0, i32* inttoptr (i64 1 to i32*)
30 ; CHECK: Memory reference address is misaligned
31 store i8 0, i8* %buf, align 2
32 ; CHECK: Memory reference address is misaligned
33 %gep = getelementptr {i8, i8}* %buf2, i32 0, i32 1
34 store i8 0, i8* %gep, align 2
35 ; CHECK: Division by zero
37 ; CHECK: Division by zero
39 ; CHECK: Division by zero
41 ; CHECK: Division by zero
43 ; CHECK: extractelement index out of range
44 %ee = extractelement <4 x i32> zeroinitializer, i32 4
45 ; CHECK: insertelement index out of range
46 %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
47 ; CHECK: Shift count out of range
49 ; CHECK: Shift count out of range
51 ; CHECK: Shift count out of range
53 ; CHECK: xor(undef, undef)
54 %xx = xor i32 undef, undef
55 ; CHECK: sub(undef, undef)
56 %xs = sub i32 undef, undef
58 ; CHECK: Write to read-only memory
60 ; CHECK: Write to text section
61 store i32 8, i32* bitcast (i32()* @foo to i32*)
62 ; CHECK: Load from block address
63 %lb = load i32* bitcast (i8* blockaddress(@foo, %next) to i32*)
64 ; CHECK: Call to block address
65 call void()* bitcast (i8* blockaddress(@foo, %next) to void()*)()
66 ; CHECK: Undefined behavior: Null pointer dereference
67 call void @llvm.stackrestore(i8* null)
68 ; CHECK: Undefined behavior: Null pointer dereference
69 call void @has_sret(i8* null)
70 ; CHECK: Unusual: noalias argument aliases another argument
71 call void @has_noaliases(i32* @CG, i32* @CG)
72 ; CHECK: Call argument count mismatches callee argument count
73 call void (i32, i32)* bitcast (void (i32)* @one_arg to void (i32, i32)*)(i32 0, i32 0)
74 ; CHECK: Call argument count mismatches callee argument count
75 call void ()* bitcast (void (i32)* @one_arg to void ()*)()
76 ; CHECK: Call argument type mismatches callee parameter type
77 call void (float)* bitcast (void (i32)* @one_arg to void (float)*)(float 0.0)
79 ; CHECK: Write to read-only memory
80 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)
85 ; CHECK: Static alloca outside of entry block
87 ; CHECK: Return statement in function with noreturn attribute
92 ; CHECK: unreachable immediately preceded by instruction without side effects
96 ; CHECK: Unnamed function with non-local linkage
97 define void @0() nounwind {
101 ; CHECK: va_start called in a non-varargs function
102 declare void @llvm.va_start(i8*)
103 define void @not_vararg(i8* %p) nounwind {
104 call void @llvm.va_start(i8* %p)
108 ; CHECK: Undefined behavior: Branch to non-blockaddress
109 define void @use_indbr() {
110 indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
115 ; CHECK: Undefined behavior: Call with "tail" keyword references alloca
116 declare void @tailcallee(i8*)
117 define void @use_tail(i8* %valist) {
119 tail call void @tailcallee(i8* %t)
123 ; CHECK: Unusual: Returning alloca value
124 define i8* @return_local(i32 %n, i32 %m) {
125 %t = alloca i8, i32 %n
126 %s = getelementptr i8* %t, i32 %m
130 ; CHECK: Unusual: Returning alloca value
131 define i32* @return_obscured_local() {
133 %retval = alloca i32*
135 store i32* %x, i32** %retval
138 %t0 = load i32** %retval
139 %t1 = insertvalue { i32, i32, i32* } zeroinitializer, i32* %t0, 2
140 %t2 = extractvalue { i32, i32, i32* } %t1, 2
143 %t3 = phi i32* [ %t2, %next ]
144 %t4 = bitcast i32* %t3 to i32*
145 %t5 = ptrtoint i32* %t4 to i64
147 %t7 = inttoptr i64 %t6 to i32*
151 ; CHECK: Undefined behavior: Undef pointer dereference
152 define i32* @self_reference() {
156 %t3 = phi i32* [ %t4, %exit ]
157 %t4 = bitcast i32* %t3 to i32*
158 %x = load volatile i32* %t3
162 ; CHECK: Call return type mismatches callee return type
163 %struct = type { double, double }
164 declare i32 @nonstruct_callee() nounwind
165 define void @struct_caller() nounwind {
167 call %struct bitcast (i32 ()* @foo to %struct ()*)()
169 ; CHECK: Undefined behavior: indirectbr with no destinations
170 indirectbr i8* null, []