blob: dee3d11d2fb5e0543313d493af385d0cd3eb54ba [file] [log] [blame]
Dan Gohman113902e2010-04-08 18:47:09 +00001; RUN: opt -lint -disable-output < %s |& FileCheck %s
2target datalayout = "e-p:64:64:64"
3
4declare fastcc void @bar()
Dan Gohman882ddb42010-05-26 22:21:25 +00005declare void @llvm.stackrestore(i8*)
Dan Gohman13ec30b2010-05-28 17:44:00 +00006declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind
Dan Gohmanaec2a0d2010-05-28 21:43:57 +00007declare void @has_sret(i8* sret %p)
8declare void @has_noaliases(i32* noalias %p, i32* %q)
9declare void @one_arg(i32)
Dan Gohman113902e2010-04-08 18:47:09 +000010
Dan Gohman5b61b382010-04-30 19:05:00 +000011@CG = constant i32 7
12
Dan Gohman113902e2010-04-08 18:47:09 +000013define i32 @foo() noreturn {
14; CHECK: Caller and callee calling convention differ
15 call void @bar()
16; CHECK: Null pointer dereference
17 store i32 0, i32* null
18; CHECK: Null pointer dereference
19 %t = load i32* null
Dan Gohmandd98c4d2010-04-08 23:05:57 +000020; CHECK: Undef pointer dereference
21 store i32 0, i32* undef
22; CHECK: Undef pointer dereference
23 %u = load i32* undef
Dan Gohmanaec2a0d2010-05-28 21:43:57 +000024; CHECK: All-ones pointer dereference
25 store i32 0, i32* inttoptr (i64 -1 to i32*)
26; CHECK: Address one pointer dereference
27 store i32 0, i32* inttoptr (i64 1 to i32*)
Dan Gohman113902e2010-04-08 18:47:09 +000028; CHECK: Memory reference address is misaligned
29 %x = inttoptr i32 1 to i32*
30 load i32* %x, align 4
31; CHECK: Division by zero
32 %sd = sdiv i32 2, 0
33; CHECK: Division by zero
34 %ud = udiv i32 2, 0
35; CHECK: Division by zero
36 %sr = srem i32 2, 0
37; CHECK: Division by zero
38 %ur = urem i32 2, 0
Dan Gohmandd98c4d2010-04-08 23:05:57 +000039; CHECK: extractelement index out of range
40 %ee = extractelement <4 x i32> zeroinitializer, i32 4
41; CHECK: insertelement index out of range
42 %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
43; CHECK: Shift count out of range
44 %r = lshr i32 0, 32
45; CHECK: Shift count out of range
46 %q = ashr i32 0, 32
47; CHECK: Shift count out of range
48 %l = shl i32 0, 32
Dan Gohmanbe02b202010-04-09 01:39:53 +000049; CHECK: xor(undef, undef)
50 %xx = xor i32 undef, undef
51; CHECK: sub(undef, undef)
52 %xs = sub i32 undef, undef
Dan Gohman5b61b382010-04-30 19:05:00 +000053
54; CHECK: Write to read-only memory
55 store i32 8, i32* @CG
56; CHECK: Write to text section
57 store i32 8, i32* bitcast (i32()* @foo to i32*)
58; CHECK: Load from block address
59 %lb = load i32* bitcast (i8* blockaddress(@foo, %next) to i32*)
60; CHECK: Call to block address
61 call void()* bitcast (i8* blockaddress(@foo, %next) to void()*)()
Dan Gohman882ddb42010-05-26 22:21:25 +000062; CHECK: Undefined behavior: Null pointer dereference
63 call void @llvm.stackrestore(i8* null)
Dan Gohmanaec2a0d2010-05-28 21:43:57 +000064; CHECK: Undefined behavior: Null pointer dereference
65 call void @has_sret(i8* null)
66; CHECK: Unusual: noalias argument aliases another argument
67 call void @has_noaliases(i32* @CG, i32* @CG)
68; CHECK: Call argument count mismatches callee argument count
69 call void (i32, i32)* bitcast (void (i32)* @one_arg to void (i32, i32)*)(i32 0, i32 0)
70; CHECK: Call argument count mismatches callee argument count
71 call void ()* bitcast (void (i32)* @one_arg to void ()*)()
72; CHECK: Call argument type mismatches callee parameter type
73 call void (float)* bitcast (void (i32)* @one_arg to void (float)*)(float 0.0)
Dan Gohman5b61b382010-04-30 19:05:00 +000074
Dan Gohman13ec30b2010-05-28 17:44:00 +000075; CHECK: Write to read-only memory
76 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)
77
Dan Gohman113902e2010-04-08 18:47:09 +000078 br label %next
79
80next:
81; CHECK: Static alloca outside of entry block
82 %a = alloca i32
83; CHECK: Return statement in function with noreturn attribute
84 ret i32 0
Dan Gohmanbe02b202010-04-09 01:39:53 +000085
86foo:
87 %z = add i32 0, 0
88; CHECK: unreachable immediately preceded by instruction without side effects
89 unreachable
90}
91
92; CHECK: Unnamed function with non-local linkage
93define void @0() nounwind {
94 ret void
95}
96
97; CHECK: va_start called in a non-varargs function
98declare void @llvm.va_start(i8*)
99define void @not_vararg(i8* %p) nounwind {
100 call void @llvm.va_start(i8* %p)
101 ret void
Dan Gohman113902e2010-04-08 18:47:09 +0000102}
Dan Gohman5b61b382010-04-30 19:05:00 +0000103
Dan Gohman113b3e22010-05-26 21:46:36 +0000104; CHECK: Undefined behavior: Branch to non-blockaddress
Dan Gohman5b61b382010-04-30 19:05:00 +0000105define void @use_indbr() {
106 indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
107block:
108 unreachable
109}
Dan Gohman113b3e22010-05-26 21:46:36 +0000110
Dan Gohman078f8592010-05-28 16:34:49 +0000111; CHECK: Undefined behavior: Call with "tail" keyword references alloca
Dan Gohman113b3e22010-05-26 21:46:36 +0000112declare void @tailcallee(i8*)
113define void @use_tail(i8* %valist) {
114 %t = alloca i8
115 tail call void @tailcallee(i8* %t)
Dan Gohman113b3e22010-05-26 21:46:36 +0000116 ret void
117}
Dan Gohman292fc872010-05-28 04:33:42 +0000118
Dan Gohman078f8592010-05-28 16:34:49 +0000119; CHECK: Unusual: Returning alloca value
Dan Gohman292fc872010-05-28 04:33:42 +0000120define i8* @return_local(i32 %n, i32 %m) {
121 %t = alloca i8, i32 %n
122 %s = getelementptr i8* %t, i32 %m
123 ret i8* %s
124}
Dan Gohmanff26d4e2010-05-28 16:21:24 +0000125
Dan Gohman078f8592010-05-28 16:34:49 +0000126; CHECK: Unusual: Returning alloca value
Dan Gohmanff26d4e2010-05-28 16:21:24 +0000127define i32* @return_obscured_local() {
128entry:
129 %retval = alloca i32*
130 %x = alloca i32
131 store i32* %x, i32** %retval
132 br label %next
133next:
134 %t0 = load i32** %retval
135 %t1 = insertvalue { i32, i32, i32* } zeroinitializer, i32* %t0, 2
136 %t2 = extractvalue { i32, i32, i32* } %t1, 2
137 br label %exit
138exit:
139 %t3 = phi i32* [ %t2, %next ]
140 %t4 = bitcast i32* %t3 to i32*
141 %t5 = ptrtoint i32* %t4 to i64
142 %t6 = add i64 %t5, 0
143 %t7 = inttoptr i64 %t6 to i32*
144 ret i32* %t7
145}
Dan Gohman17d95962010-05-28 16:45:33 +0000146
147; CHECK: Undefined behavior: Undef pointer dereference
148define i32* @self_reference() {
149entry:
150 unreachable
151exit:
152 %t3 = phi i32* [ %t4, %exit ]
153 %t4 = bitcast i32* %t3 to i32*
154 %x = volatile load i32* %t3
155 br label %exit
156}
Dan Gohman545d0062010-07-12 18:02:04 +0000157
158; CHECK: Call return type mismatches callee return type
159%struct = type { double, double }
160declare i32 @nonstruct_callee() nounwind
161define void @struct_caller() nounwind {
162entry:
163 call %struct bitcast (i32 ()* @foo to %struct ()*)()
164 ret void
165}