llvm-project
196 строк · 6.0 Кб
1; RUN: opt -aa-pipeline=basic-aa -passes=lint -disable-output < %s 2>&1 | FileCheck %s
2target datalayout = "e-p:64:64:64"
3
4declare fastcc void @bar()
5declare void @llvm.stackrestore(ptr)
6declare void @llvm.memcpy.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
7declare void @llvm.memcpy.inline.p0.p0.i64(ptr nocapture, ptr nocapture, i64, i1) nounwind
8declare void @llvm.memset.p0.i8.i64(ptr nocapture, i8, i64, i1) nounwind
9declare void @llvm.memset.inline.p0.i8.i64(ptr nocapture, i8, i64, i1) nounwind
10declare void @has_sret(ptr sret(i8) %p)
11declare void @has_noaliases(ptr noalias %p, ptr %q)
12declare void @one_arg(i32)
13
14@CG = constant i32 7
15@CG2 = constant i32 7
16@E = external global i8
17
18define i32 @foo() noreturn {
19%buf = alloca i8
20%buf2 = alloca {i8, i8}, align 2
21; CHECK: Caller and callee calling convention differ
22call void @bar()
23; CHECK: Null pointer dereference
24store i32 0, ptr null
25; CHECK: Null pointer dereference
26%t = load i32, ptr null
27; CHECK: Undef pointer dereference
28store i32 0, ptr undef
29; CHECK: Undef pointer dereference
30%u = load i32, ptr undef
31; CHECK: All-ones pointer dereference
32store i32 0, ptr inttoptr (i64 -1 to ptr)
33; CHECK: Address one pointer dereference
34store i32 0, ptr inttoptr (i64 1 to ptr)
35; CHECK: Memory reference address is misaligned
36store i8 0, ptr %buf, align 2
37; CHECK: Memory reference address is misaligned
38%gep = getelementptr {i8, i8}, ptr %buf2, i32 0, i32 1
39store i8 0, ptr %gep, align 2
40; CHECK: Division by zero
41%sd = sdiv i32 2, 0
42; CHECK: Division by zero
43%ud = udiv i32 2, 0
44; CHECK: Division by zero
45%sr = srem i32 2, 0
46; CHECK: Division by zero
47%ur = urem i32 2, 0
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
53%r = lshr i32 0, 32
54; CHECK: Shift count out of range
55%q = ashr i32 0, 32
56; CHECK: Shift count out of range
57%l = shl i32 0, 32
58; CHECK: xor(undef, undef)
59%xx = xor i32 undef, undef
60; CHECK: sub(undef, undef)
61%xs = sub i32 undef, undef
62
63; CHECK: Write to read-only memory
64store i32 8, ptr @CG
65; CHECK: Write to text section
66store i32 8, ptr @foo
67; CHECK: Load from block address
68%lb = load i32, ptr blockaddress(@foo, %next)
69; CHECK: Call to block address
70call void() blockaddress(@foo, %next)()
71; CHECK: Undefined behavior: Null pointer dereference
72call void @llvm.stackrestore(ptr null)
73; CHECK: Undefined behavior: Null pointer dereference
74call void @has_sret(ptr sret(i8) null)
75; CHECK: Unusual: noalias argument aliases another argument
76call void @has_noaliases(ptr @CG, ptr @CG)
77; CHECK: Call argument count mismatches callee argument count
78call void (i32, i32) @one_arg(i32 0, i32 0)
79; CHECK: Call argument count mismatches callee argument count
80call void () @one_arg()
81; CHECK: Call argument type mismatches callee parameter type
82call void (float) @one_arg(float 0.0)
83
84; CHECK: Write to read-only memory
85call void @llvm.memcpy.p0.p0.i64(ptr @CG, ptr @CG2, i64 1, i1 0)
86; CHECK: Write to read-only memory
87call void @llvm.memcpy.inline.p0.p0.i64(ptr @CG, ptr @CG2, i64 1, i1 0)
88; CHECK: Unusual: noalias argument aliases another argument
89call void @llvm.memcpy.p0.p0.i64(ptr @CG, ptr @CG, i64 1, i1 0)
90
91; CHECK: Write to read-only memory
92call void @llvm.memset.p0.i8.i64(ptr @CG, i8 1, i64 1, i1 0)
93; CHECK: Write to read-only memory
94call void @llvm.memset.inline.p0.i8.i64(ptr @CG, i8 1, i64 1, i1 0)
95
96; CHECK: Undefined behavior: Buffer overflow
97store i16 0, ptr %buf
98; CHECK: Undefined behavior: Buffer overflow
99%inner = getelementptr {i8, i8}, ptr %buf2, i32 0, i32 1
100store i16 0, ptr %inner
101; CHECK: Undefined behavior: Buffer overflow
102%before = getelementptr i8, ptr %buf, i32 -1
103store i16 0, ptr %before
104
105br label %next
106
107next:
108; CHECK: Static alloca outside of entry block
109%a = alloca i32
110; CHECK: Return statement in function with noreturn attribute
111ret i32 0
112
113foo:
114; CHECK-NOT: Undefined behavior: Buffer overflow
115; CHECK-NOT: Memory reference address is misaligned
116store i64 0, ptr @E
117%z = add i32 0, 0
118; CHECK: unreachable immediately preceded by instruction without side effects
119unreachable
120}
121
122; CHECK: Unnamed function with non-local linkage
123define void @0() nounwind {
124ret void
125}
126
127; CHECK: Undefined behavior: Branch to non-blockaddress
128define void @use_indbr() {
129indirectbr ptr @foo, [label %block]
130block:
131unreachable
132}
133
134; CHECK: Undefined behavior: Call with "tail" keyword references alloca
135declare void @tailcallee(ptr)
136define void @use_tail(ptr %valist) {
137%t = alloca i8
138tail call void @tailcallee(ptr %t)
139ret void
140}
141
142; CHECK: Unusual: Returning alloca value
143define ptr @return_local(i32 %n, i32 %m) {
144%t = alloca i8, i32 %n
145%s = getelementptr i8, ptr %t, i32 %m
146ret ptr %s
147}
148
149; CHECK: Unusual: Returning alloca value
150define ptr @return_obscured_local() {
151entry:
152%retval = alloca ptr
153%x = alloca i32
154store ptr %x, ptr %retval
155br label %next
156next:
157%t0 = load ptr, ptr %retval
158%t1 = insertvalue { i32, i32, ptr } zeroinitializer, ptr %t0, 2
159%t2 = extractvalue { i32, i32, ptr } %t1, 2
160br label %exit
161exit:
162%t3 = phi ptr [ %t2, %next ]
163%t5 = ptrtoint ptr %t3 to i64
164%t6 = add i64 %t5, 0
165%t7 = inttoptr i64 %t6 to ptr
166ret ptr %t7
167}
168
169; CHECK: Undefined behavior: Undef pointer dereference
170define ptr @self_reference() {
171entry:
172unreachable
173exit:
174%t3 = phi ptr [ %t4, %exit ]
175%t4 = bitcast ptr %t3 to ptr
176%x = load volatile i32, ptr %t3
177br label %exit
178}
179
180; CHECK: Call return type mismatches callee return type
181%struct = type { double, double }
182declare i32 @nonstruct_callee() nounwind
183define void @struct_caller() nounwind {
184entry:
185call %struct @foo()
186
187; CHECK: Undefined behavior: indirectbr with no destinations
188indirectbr ptr null, []
189}
190
191define i32 @memcpy_inline_same_address() noreturn {
192%buf = alloca i64, align 1
193; CHECK: Unusual: noalias argument aliases another argument
194call void @llvm.memcpy.inline.p0.p0.i64(ptr %buf, ptr %buf, i64 1, i1 false)
195unreachable
196}
197