blob: bed3dba3a59edd8a9fbd130e4e8e81a13bcf641c [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 Gohman113902e2010-04-08 18:47:09 +00007
Dan Gohman5b61b382010-04-30 19:05:00 +00008@CG = constant i32 7
9
Dan Gohman113902e2010-04-08 18:47:09 +000010define i32 @foo() noreturn {
11; CHECK: Caller and callee calling convention differ
12 call void @bar()
13; CHECK: Null pointer dereference
14 store i32 0, i32* null
15; CHECK: Null pointer dereference
16 %t = load i32* null
Dan Gohmandd98c4d2010-04-08 23:05:57 +000017; CHECK: Undef pointer dereference
18 store i32 0, i32* undef
19; CHECK: Undef pointer dereference
20 %u = load i32* undef
Dan Gohman113902e2010-04-08 18:47:09 +000021; CHECK: Memory reference address is misaligned
22 %x = inttoptr i32 1 to i32*
23 load i32* %x, align 4
24; CHECK: Division by zero
25 %sd = sdiv i32 2, 0
26; CHECK: Division by zero
27 %ud = udiv i32 2, 0
28; CHECK: Division by zero
29 %sr = srem i32 2, 0
30; CHECK: Division by zero
31 %ur = urem i32 2, 0
Dan Gohmandd98c4d2010-04-08 23:05:57 +000032; CHECK: extractelement index out of range
33 %ee = extractelement <4 x i32> zeroinitializer, i32 4
34; CHECK: insertelement index out of range
35 %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
36; CHECK: Shift count out of range
37 %r = lshr i32 0, 32
38; CHECK: Shift count out of range
39 %q = ashr i32 0, 32
40; CHECK: Shift count out of range
41 %l = shl i32 0, 32
Dan Gohmanbe02b202010-04-09 01:39:53 +000042; CHECK: xor(undef, undef)
43 %xx = xor i32 undef, undef
44; CHECK: sub(undef, undef)
45 %xs = sub i32 undef, undef
Dan Gohman5b61b382010-04-30 19:05:00 +000046
47; CHECK: Write to read-only memory
48 store i32 8, i32* @CG
49; CHECK: Write to text section
50 store i32 8, i32* bitcast (i32()* @foo to i32*)
51; CHECK: Load from block address
52 %lb = load i32* bitcast (i8* blockaddress(@foo, %next) to i32*)
53; CHECK: Call to block address
54 call void()* bitcast (i8* blockaddress(@foo, %next) to void()*)()
Dan Gohman882ddb42010-05-26 22:21:25 +000055; CHECK: Undefined behavior: Null pointer dereference
56 call void @llvm.stackrestore(i8* null)
Dan Gohman5b61b382010-04-30 19:05:00 +000057
Dan Gohman13ec30b2010-05-28 17:44:00 +000058; CHECK: Write to read-only memory
59 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)
60
Dan Gohman113902e2010-04-08 18:47:09 +000061 br label %next
62
63next:
64; CHECK: Static alloca outside of entry block
65 %a = alloca i32
66; CHECK: Return statement in function with noreturn attribute
67 ret i32 0
Dan Gohmanbe02b202010-04-09 01:39:53 +000068
69foo:
70 %z = add i32 0, 0
71; CHECK: unreachable immediately preceded by instruction without side effects
72 unreachable
73}
74
75; CHECK: Unnamed function with non-local linkage
76define void @0() nounwind {
77 ret void
78}
79
80; CHECK: va_start called in a non-varargs function
81declare void @llvm.va_start(i8*)
82define void @not_vararg(i8* %p) nounwind {
83 call void @llvm.va_start(i8* %p)
84 ret void
Dan Gohman113902e2010-04-08 18:47:09 +000085}
Dan Gohman5b61b382010-04-30 19:05:00 +000086
Dan Gohman113b3e22010-05-26 21:46:36 +000087; CHECK: Undefined behavior: Branch to non-blockaddress
Dan Gohman5b61b382010-04-30 19:05:00 +000088define void @use_indbr() {
89 indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
90block:
91 unreachable
92}
Dan Gohman113b3e22010-05-26 21:46:36 +000093
Dan Gohman078f8592010-05-28 16:34:49 +000094; CHECK: Undefined behavior: Call with "tail" keyword references alloca
Dan Gohman113b3e22010-05-26 21:46:36 +000095declare void @tailcallee(i8*)
96define void @use_tail(i8* %valist) {
97 %t = alloca i8
98 tail call void @tailcallee(i8* %t)
Dan Gohman113b3e22010-05-26 21:46:36 +000099 ret void
100}
Dan Gohman292fc872010-05-28 04:33:42 +0000101
Dan Gohman078f8592010-05-28 16:34:49 +0000102; CHECK: Unusual: Returning alloca value
Dan Gohman292fc872010-05-28 04:33:42 +0000103define i8* @return_local(i32 %n, i32 %m) {
104 %t = alloca i8, i32 %n
105 %s = getelementptr i8* %t, i32 %m
106 ret i8* %s
107}
Dan Gohmanff26d4e2010-05-28 16:21:24 +0000108
Dan Gohman078f8592010-05-28 16:34:49 +0000109; CHECK: Unusual: Returning alloca value
Dan Gohmanff26d4e2010-05-28 16:21:24 +0000110define i32* @return_obscured_local() {
111entry:
112 %retval = alloca i32*
113 %x = alloca i32
114 store i32* %x, i32** %retval
115 br label %next
116next:
117 %t0 = load i32** %retval
118 %t1 = insertvalue { i32, i32, i32* } zeroinitializer, i32* %t0, 2
119 %t2 = extractvalue { i32, i32, i32* } %t1, 2
120 br label %exit
121exit:
122 %t3 = phi i32* [ %t2, %next ]
123 %t4 = bitcast i32* %t3 to i32*
124 %t5 = ptrtoint i32* %t4 to i64
125 %t6 = add i64 %t5, 0
126 %t7 = inttoptr i64 %t6 to i32*
127 ret i32* %t7
128}
Dan Gohman17d95962010-05-28 16:45:33 +0000129
130; CHECK: Undefined behavior: Undef pointer dereference
131define i32* @self_reference() {
132entry:
133 unreachable
134exit:
135 %t3 = phi i32* [ %t4, %exit ]
136 %t4 = bitcast i32* %t3 to i32*
137 %x = volatile load i32* %t3
138 br label %exit
139}