Reinstate checking of stackrestore, with checking for both Read
[oota-llvm.git] / test / Other / lint.ll
1 ; RUN: opt -lint -disable-output < %s |& FileCheck %s
2 target datalayout = "e-p:64:64:64"
3
4 declare fastcc void @bar()
5 declare void @llvm.stackrestore(i8*)
6
7 @CG = constant i32 7
8
9 define 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
16 ; CHECK: Undef pointer dereference
17   store i32 0, i32* undef
18 ; CHECK: Undef pointer dereference
19   %u = load i32* undef
20 ; 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
31 ; 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
41 ; CHECK: xor(undef, undef)
42   %xx = xor i32 undef, undef
43 ; CHECK: sub(undef, undef)
44   %xs = sub i32 undef, undef
45
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()*)()
54 ; CHECK: Undefined behavior: Null pointer dereference
55   call void @llvm.stackrestore(i8* null)
56
57   br label %next
58
59 next:
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
64
65 foo:
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
72 define void @0() nounwind {
73   ret void
74 }
75
76 ; CHECK: va_start called in a non-varargs function
77 declare void @llvm.va_start(i8*)
78 define void @not_vararg(i8* %p) nounwind {
79   call void @llvm.va_start(i8* %p)
80   ret void
81 }
82
83 ; CHECK: Undefined behavior: Branch to non-blockaddress
84 define void @use_indbr() {
85   indirectbr i8* bitcast (i32()* @foo to i8*), [label %block]
86 block:
87   unreachable
88 }
89
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
92 declare void @tailcallee(i8*)
93 define 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 }