blob: 1f9efe3ad9ad569784bf65dd62f3a31afa09fdef [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
90; CHECK: Undefined behavior: Call with "tail" keyword references alloca or va_arg
91; CHECK: Undefined behavior: Call with "tail" keyword references alloca or va_arg
92declare void @tailcallee(i8*)
93define void @use_tail(i8* %valist) {
94 %t = alloca i8
95 tail call void @tailcallee(i8* %t)
96 %s = va_arg i8* %valist, i8*
97 tail call void @tailcallee(i8* %s)
98 ret void
99}