1 ; RUN: opt -aa-pipeline=basic-aa -passes=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(ptr)
6 declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
7 declare void @llvm.memcpy.inline.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
8 declare void @llvm.memset.p0.i8.i64(ptr nocapture, i8, i64, i1) nounwind
9 declare void @llvm.memset.inline.p0.i8.i64(ptr nocapture, i8, i64, i1) nounwind
10 declare void @has_sret(ptr sret(i8) %p)
11 declare void @has_noaliases(ptr noalias %p, ptr %q)
12 declare void @one_arg(i32)
16 @E = external global i8
18 define i32 @foo() noreturn {
20 %buf2 = alloca {i8, i8}, align 2
21 ; CHECK: Caller and callee calling convention differ
23 ; CHECK: Null pointer dereference
25 ; CHECK: Null pointer dereference
26 %t = load i32, ptr null
27 ; CHECK: Undef pointer dereference
28 store i32 0, ptr undef
29 ; CHECK: Undef pointer dereference
30 %u = load i32, ptr undef
31 ; CHECK: All-ones pointer dereference
32 store i32 0, ptr inttoptr (i64 -1 to ptr)
33 ; CHECK: Address one pointer dereference
34 store i32 0, ptr inttoptr (i64 1 to ptr)
35 ; CHECK: Memory reference address is misaligned
36 store i8 0, ptr %buf, align 2
37 ; CHECK: Memory reference address is misaligned
38 %gep = getelementptr {i8, i8}, ptr %buf2, i32 0, i32 1
39 store i8 0, ptr %gep, align 2
40 ; CHECK: Division by zero
42 ; CHECK: Division by zero
44 ; CHECK: Division by zero
46 ; CHECK: Division by zero
48 ; CHECK: extractelement index out of range
49 %ee = extractelement <4 x i32> zeroinitializer, i32 4
50 ; CHECK: insertelement index out of range
51 %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
52 ; CHECK: Shift count out of range
54 ; CHECK: Shift count out of range
56 ; CHECK: Shift count out of range
58 ; CHECK: xor(undef, undef)
59 %xx = xor i32 undef, undef
60 ; CHECK: sub(undef, undef)
61 %xs = sub i32 undef, undef
63 ; CHECK: Write to read-only memory
65 ; CHECK: Write to text section
67 ; CHECK: Load from block address
68 %lb = load i32, ptr blockaddress(@foo, %next)
69 ; CHECK: Call to block address
70 call void() blockaddress(@foo, %next)()
71 ; CHECK: Undefined behavior: Null pointer dereference
72 call void @llvm.stackrestore(ptr null)
73 ; CHECK: Undefined behavior: Null pointer dereference
74 call void @has_sret(ptr sret(i8) null)
75 ; CHECK: Unusual: noalias argument aliases another argument
76 call void @has_noaliases(ptr @CG, ptr @CG)
77 ; CHECK: Call argument count mismatches callee argument count
78 call void (i32, i32) @one_arg(i32 0, i32 0)
79 ; CHECK: Call argument count mismatches callee argument count
80 call void () @one_arg()
81 ; CHECK: Call argument type mismatches callee parameter type
82 call void (float) @one_arg(float 0.0)
84 ; CHECK: Write to read-only memory
85 call void @llvm.memcpy.p0.p0.i64(ptr @CG, ptr @CG2, i64 1, i1 0)
86 ; CHECK: Write to read-only memory
87 call void @llvm.memcpy.inline.p0.p0.i64(ptr @CG, ptr @CG2, i64 1, i1 0)
88 ; CHECK: Unusual: noalias argument aliases another argument
89 call void @llvm.memcpy.p0.p0.i64(ptr @CG, ptr @CG, i64 1, i1 0)
91 ; CHECK: Write to read-only memory
92 call void @llvm.memset.p0.i8.i64(ptr @CG, i8 1, i64 1, i1 0)
93 ; CHECK: Write to read-only memory
94 call void @llvm.memset.inline.p0.i8.i64(ptr @CG, i8 1, i64 1, i1 0)
96 ; CHECK: Undefined behavior: Buffer overflow
98 ; CHECK: Undefined behavior: Buffer overflow
99 %inner = getelementptr {i8, i8}, ptr %buf2, i32 0, i32 1
100 store i16 0, ptr %inner
101 ; CHECK: Undefined behavior: Buffer overflow
102 %before = getelementptr i8, ptr %buf, i32 -1
103 store i16 0, ptr %before
108 ; CHECK: Static alloca outside of entry block
110 ; CHECK: Return statement in function with noreturn attribute
114 ; CHECK-NOT: Undefined behavior: Buffer overflow
115 ; CHECK-NOT: Memory reference address is misaligned
118 ; CHECK: unreachable immediately preceded by instruction without side effects
122 ; CHECK: Unnamed function with non-local linkage
123 define void @0() nounwind {
127 ; CHECK: va_start called in a non-varargs function
128 declare void @llvm.va_start(ptr)
129 define void @not_vararg(ptr %p) nounwind {
130 call void @llvm.va_start(ptr %p)
134 ; CHECK: Undefined behavior: Branch to non-blockaddress
135 define void @use_indbr() {
136 indirectbr ptr @foo, [label %block]
141 ; CHECK: Undefined behavior: Call with "tail" keyword references alloca
142 declare void @tailcallee(ptr)
143 define void @use_tail(ptr %valist) {
145 tail call void @tailcallee(ptr %t)
149 ; CHECK: Unusual: Returning alloca value
150 define ptr @return_local(i32 %n, i32 %m) {
151 %t = alloca i8, i32 %n
152 %s = getelementptr i8, ptr %t, i32 %m
156 ; CHECK: Unusual: Returning alloca value
157 define ptr @return_obscured_local() {
161 store ptr %x, ptr %retval
164 %t0 = load ptr, ptr %retval
165 %t1 = insertvalue { i32, i32, ptr } zeroinitializer, ptr %t0, 2
166 %t2 = extractvalue { i32, i32, ptr } %t1, 2
169 %t3 = phi ptr [ %t2, %next ]
170 %t5 = ptrtoint ptr %t3 to i64
172 %t7 = inttoptr i64 %t6 to ptr
176 ; CHECK: Undefined behavior: Undef pointer dereference
177 define ptr @self_reference() {
181 %t3 = phi ptr [ %t4, %exit ]
182 %t4 = bitcast ptr %t3 to ptr
183 %x = load volatile i32, ptr %t3
187 ; CHECK: Call return type mismatches callee return type
188 %struct = type { double, double }
189 declare i32 @nonstruct_callee() nounwind
190 define void @struct_caller() nounwind {
194 ; CHECK: Undefined behavior: indirectbr with no destinations
195 indirectbr ptr null, []
198 define i32 @memcpy_inline_same_address() noreturn {
199 %buf = alloca i64, align 1
200 ; CHECK: Unusual: noalias argument aliases another argument
201 call void @llvm.memcpy.inline.p0.p0.i64(ptr %buf, ptr %buf, i64 1, i1 false)