blob: 4cf9fd7fce63eee9c4824c9e98c78d9238bf0a58 [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 Gohman113902e2010-04-08 18:47:09 +00006
Dan Gohman5b61b382010-04-30 19:05:00 +00007@CG = constant i32 7
8
Dan Gohman113902e2010-04-08 18:47:09 +00009define i32 @foo() noreturn {
10; CHECK: Caller and callee calling convention differ
11 call void @bar()
12; CHECK: Null pointer dereference
13 store i32 0, i32* null
14; CHECK: Null pointer dereference
15 %t = load i32* null
Dan Gohmandd98c4d2010-04-08 23:05:57 +000016; CHECK: Undef pointer dereference
17 store i32 0, i32* undef
18; CHECK: Undef pointer dereference
19 %u = load i32* undef
Dan Gohman113902e2010-04-08 18:47:09 +000020; CHECK: Memory reference address is misaligned
21 %x = inttoptr i32 1 to i32*
22 load i32* %x, align 4
23; CHECK: Division by zero
24 %sd = sdiv i32 2, 0
25; CHECK: Division by zero
26 %ud = udiv i32 2, 0
27; CHECK: Division by zero
28 %sr = srem i32 2, 0
29; CHECK: Division by zero
30 %ur = urem i32 2, 0
Dan Gohmandd98c4d2010-04-08 23:05:57 +000031; CHECK: extractelement index out of range
32 %ee = extractelement <4 x i32> zeroinitializer, i32 4
33; CHECK: insertelement index out of range
34 %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
35; CHECK: Shift count out of range
36 %r = lshr i32 0, 32
37; CHECK: Shift count out of range
38 %q = ashr i32 0, 32
39; CHECK: Shift count out of range
40 %l = shl i32 0, 32
Dan Gohmanbe02b202010-04-09 01:39:53 +000041; CHECK: xor(undef, undef)
42 %xx = xor i32 undef, undef
43; CHECK: sub(undef, undef)
44 %xs = sub i32 undef, undef
Dan Gohman5b61b382010-04-30 19:05:00 +000045
46; CHECK: Write to read-only memory
47 store i32 8, i32* @CG
48; CHECK: Write to text section
49 store i32 8, i32* bitcast (i32()* @foo to i32*)
50; CHECK: Load from block address
51 %lb = load i32* bitcast (i8* blockaddress(@foo, %next) to i32*)
52; CHECK: Call to block address
53 call void()* bitcast (i8* blockaddress(@foo, %next) to void()*)()
Dan Gohman882ddb42010-05-26 22:21:25 +000054; CHECK: Undefined behavior: Null pointer dereference
55 call void @llvm.stackrestore(i8* null)
Dan Gohman5b61b382010-04-30 19:05:00 +000056
Dan Gohman113902e2010-04-08 18:47:09 +000057 br label %next
58
59next:
60; CHECK: Static alloca outside of entry block
61 %a = alloca i32
62; CHECK: Return statement in function with noreturn attribute
63 ret i32 0
Dan Gohmanbe02b202010-04-09 01:39:53 +000064
65foo:
66 %z = add i32 0, 0
67; CHECK: unreachable immediately preceded by instruction without side effects
68 unreachable
69}
70
71; CHECK: Unnamed function with non-local linkage
72define void @0() nounwind {
73 ret void
74}
75
76; CHECK: va_start called in a non-varargs function
77declare void @llvm.va_start(i8*)
78define void @not_vararg(i8* %p) nounwind {
79 call void @llvm.va_start(i8* %p)
80 ret void
Dan Gohman113902e2010-04-08 18:47:09 +000081}
Dan Gohman5b61b382010-04-30 19:05:00 +000082
Dan Gohman113b3e22010-05-26 21:46:36 +000083; CHECK: Undefined behavior: Branch to non-blockaddress
Dan Gohman5b61b382010-04-30 19:05:00 +000084define void @use_indbr() {
85 indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
86block:
87 unreachable
88}
Dan Gohman113b3e22010-05-26 21:46:36 +000089
Dan Gohman078f8592010-05-28 16:34:49 +000090; CHECK: Undefined behavior: Call with "tail" keyword references alloca
Dan Gohman113b3e22010-05-26 21:46:36 +000091declare void @tailcallee(i8*)
92define void @use_tail(i8* %valist) {
93 %t = alloca i8
94 tail call void @tailcallee(i8* %t)
Dan Gohman113b3e22010-05-26 21:46:36 +000095 ret void
96}
Dan Gohman292fc872010-05-28 04:33:42 +000097
Dan Gohman078f8592010-05-28 16:34:49 +000098; CHECK: Unusual: Returning alloca value
Dan Gohman292fc872010-05-28 04:33:42 +000099define i8* @return_local(i32 %n, i32 %m) {
100 %t = alloca i8, i32 %n
101 %s = getelementptr i8* %t, i32 %m
102 ret i8* %s
103}
Dan Gohmanff26d4e2010-05-28 16:21:24 +0000104
Dan Gohman078f8592010-05-28 16:34:49 +0000105; CHECK: Unusual: Returning alloca value
Dan Gohmanff26d4e2010-05-28 16:21:24 +0000106define i32* @return_obscured_local() {
107entry:
108 %retval = alloca i32*
109 %x = alloca i32
110 store i32* %x, i32** %retval
111 br label %next
112next:
113 %t0 = load i32** %retval
114 %t1 = insertvalue { i32, i32, i32* } zeroinitializer, i32* %t0, 2
115 %t2 = extractvalue { i32, i32, i32* } %t1, 2
116 br label %exit
117exit:
118 %t3 = phi i32* [ %t2, %next ]
119 %t4 = bitcast i32* %t3 to i32*
120 %t5 = ptrtoint i32* %t4 to i64
121 %t6 = add i64 %t5, 0
122 %t7 = inttoptr i64 %t6 to i32*
123 ret i32* %t7
124}