blob: eb0b7629e432ff69000f2b22d0e5bced841d7e7b [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()
5
Dan Gohman5b61b382010-04-30 19:05:00 +00006@CG = constant i32 7
7
Dan Gohman113902e2010-04-08 18:47:09 +00008define i32 @foo() noreturn {
9; CHECK: Caller and callee calling convention differ
10 call void @bar()
11; CHECK: Null pointer dereference
12 store i32 0, i32* null
13; CHECK: Null pointer dereference
14 %t = load i32* null
Dan Gohmandd98c4d2010-04-08 23:05:57 +000015; CHECK: Undef pointer dereference
16 store i32 0, i32* undef
17; CHECK: Undef pointer dereference
18 %u = load i32* undef
Dan Gohman113902e2010-04-08 18:47:09 +000019; CHECK: Memory reference address is misaligned
20 %x = inttoptr i32 1 to i32*
21 load i32* %x, align 4
22; CHECK: Division by zero
23 %sd = sdiv i32 2, 0
24; CHECK: Division by zero
25 %ud = udiv i32 2, 0
26; CHECK: Division by zero
27 %sr = srem i32 2, 0
28; CHECK: Division by zero
29 %ur = urem i32 2, 0
Dan Gohmandd98c4d2010-04-08 23:05:57 +000030; CHECK: extractelement index out of range
31 %ee = extractelement <4 x i32> zeroinitializer, i32 4
32; CHECK: insertelement index out of range
33 %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4
34; CHECK: Shift count out of range
35 %r = lshr i32 0, 32
36; CHECK: Shift count out of range
37 %q = ashr i32 0, 32
38; CHECK: Shift count out of range
39 %l = shl i32 0, 32
Dan Gohmanbe02b202010-04-09 01:39:53 +000040; CHECK: xor(undef, undef)
41 %xx = xor i32 undef, undef
42; CHECK: sub(undef, undef)
43 %xs = sub i32 undef, undef
Dan Gohman5b61b382010-04-30 19:05:00 +000044
45; CHECK: Write to read-only memory
46 store i32 8, i32* @CG
47; CHECK: Write to text section
48 store i32 8, i32* bitcast (i32()* @foo to i32*)
49; CHECK: Load from block address
50 %lb = load i32* bitcast (i8* blockaddress(@foo, %next) to i32*)
51; CHECK: Call to block address
52 call void()* bitcast (i8* blockaddress(@foo, %next) to void()*)()
53
Dan Gohman113902e2010-04-08 18:47:09 +000054 br label %next
55
56next:
57; CHECK: Static alloca outside of entry block
58 %a = alloca i32
59; CHECK: Return statement in function with noreturn attribute
60 ret i32 0
Dan Gohmanbe02b202010-04-09 01:39:53 +000061
62foo:
63 %z = add i32 0, 0
64; CHECK: unreachable immediately preceded by instruction without side effects
65 unreachable
66}
67
68; CHECK: Unnamed function with non-local linkage
69define void @0() nounwind {
70 ret void
71}
72
73; CHECK: va_start called in a non-varargs function
74declare void @llvm.va_start(i8*)
75define void @not_vararg(i8* %p) nounwind {
76 call void @llvm.va_start(i8* %p)
77 ret void
Dan Gohman113902e2010-04-08 18:47:09 +000078}
Dan Gohman5b61b382010-04-30 19:05:00 +000079
Dan Gohman113b3e22010-05-26 21:46:36 +000080; CHECK: Undefined behavior: Branch to non-blockaddress
Dan Gohman5b61b382010-04-30 19:05:00 +000081define void @use_indbr() {
82 indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
83block:
84 unreachable
85}
Dan Gohman113b3e22010-05-26 21:46:36 +000086
87; CHECK: Undefined behavior: Call with "tail" keyword references alloca or va_arg
88; CHECK: Undefined behavior: Call with "tail" keyword references alloca or va_arg
89declare void @tailcallee(i8*)
90define void @use_tail(i8* %valist) {
91 %t = alloca i8
92 tail call void @tailcallee(i8* %t)
93 %s = va_arg i8* %valist, i8*
94 tail call void @tailcallee(i8* %s)
95 ret void
96}