| Chandler Carruth | 5da5343 | 2012-07-02 18:37:59 +0000 | [diff] [blame] | 1 | ; RUN: opt -basicaa -lint -disable-output < %s 2>&1 | FileCheck %s |
| Dan Gohman | 98bc437 | 2010-04-08 18:47:09 +0000 | [diff] [blame] | 2 | target datalayout = "e-p:64:64:64" |
| 3 | |
| 4 | declare fastcc void @bar() |
| Dan Gohman | a20a5cd | 2010-05-26 22:21:25 +0000 | [diff] [blame] | 5 | declare void @llvm.stackrestore(i8*) |
| Dan Gohman | c575ec6 | 2010-05-28 17:44:00 +0000 | [diff] [blame] | 6 | declare void @llvm.memcpy.p0i8.p0i8.i64(i8* nocapture, i8* nocapture, i64, i32, i1) nounwind |
| Dan Gohman | 0fa67e4 | 2010-05-28 21:43:57 +0000 | [diff] [blame] | 7 | declare void @has_sret(i8* sret %p) |
| 8 | declare void @has_noaliases(i32* noalias %p, i32* %q) |
| 9 | declare void @one_arg(i32) |
| Dan Gohman | 98bc437 | 2010-04-08 18:47:09 +0000 | [diff] [blame] | 10 | |
| Dan Gohman | 299e7b9 | 2010-04-30 19:05:00 +0000 | [diff] [blame] | 11 | @CG = constant i32 7 |
| 12 | |
| Dan Gohman | 98bc437 | 2010-04-08 18:47:09 +0000 | [diff] [blame] | 13 | define i32 @foo() noreturn { |
| Duncan Sands | 3f4d0b1 | 2012-09-25 10:00:49 +0000 | [diff] [blame] | 14 | %buf = alloca i8 |
| 15 | %buf2 = alloca {i8, i8}, align 2 |
| Dan Gohman | 98bc437 | 2010-04-08 18:47:09 +0000 | [diff] [blame] | 16 | ; CHECK: Caller and callee calling convention differ |
| 17 | call void @bar() |
| 18 | ; CHECK: Null pointer dereference |
| 19 | store i32 0, i32* null |
| 20 | ; CHECK: Null pointer dereference |
| 21 | %t = load i32* null |
| Dan Gohman | 7808d49 | 2010-04-08 23:05:57 +0000 | [diff] [blame] | 22 | ; CHECK: Undef pointer dereference |
| 23 | store i32 0, i32* undef |
| 24 | ; CHECK: Undef pointer dereference |
| 25 | %u = load i32* undef |
| Dan Gohman | 0fa67e4 | 2010-05-28 21:43:57 +0000 | [diff] [blame] | 26 | ; CHECK: All-ones pointer dereference |
| 27 | store i32 0, i32* inttoptr (i64 -1 to i32*) |
| 28 | ; CHECK: Address one pointer dereference |
| 29 | store i32 0, i32* inttoptr (i64 1 to i32*) |
| Dan Gohman | 98bc437 | 2010-04-08 18:47:09 +0000 | [diff] [blame] | 30 | ; CHECK: Memory reference address is misaligned |
| Duncan Sands | 3f4d0b1 | 2012-09-25 10:00:49 +0000 | [diff] [blame] | 31 | store i8 0, i8* %buf, align 2 |
| 32 | ; CHECK: Memory reference address is misaligned |
| 33 | %gep = getelementptr {i8, i8}* %buf2, i32 0, i32 1 |
| 34 | store i8 0, i8* %gep, align 2 |
| Dan Gohman | 98bc437 | 2010-04-08 18:47:09 +0000 | [diff] [blame] | 35 | ; CHECK: Division by zero |
| 36 | %sd = sdiv i32 2, 0 |
| 37 | ; CHECK: Division by zero |
| 38 | %ud = udiv i32 2, 0 |
| 39 | ; CHECK: Division by zero |
| 40 | %sr = srem i32 2, 0 |
| 41 | ; CHECK: Division by zero |
| 42 | %ur = urem i32 2, 0 |
| Dan Gohman | 7808d49 | 2010-04-08 23:05:57 +0000 | [diff] [blame] | 43 | ; CHECK: extractelement index out of range |
| 44 | %ee = extractelement <4 x i32> zeroinitializer, i32 4 |
| 45 | ; CHECK: insertelement index out of range |
| 46 | %ie = insertelement <4 x i32> zeroinitializer, i32 0, i32 4 |
| 47 | ; CHECK: Shift count out of range |
| 48 | %r = lshr i32 0, 32 |
| 49 | ; CHECK: Shift count out of range |
| 50 | %q = ashr i32 0, 32 |
| 51 | ; CHECK: Shift count out of range |
| 52 | %l = shl i32 0, 32 |
| Dan Gohman | 9ba08a4 | 2010-04-09 01:39:53 +0000 | [diff] [blame] | 53 | ; CHECK: xor(undef, undef) |
| 54 | %xx = xor i32 undef, undef |
| 55 | ; CHECK: sub(undef, undef) |
| 56 | %xs = sub i32 undef, undef |
| Dan Gohman | 299e7b9 | 2010-04-30 19:05:00 +0000 | [diff] [blame] | 57 | |
| 58 | ; CHECK: Write to read-only memory |
| 59 | store i32 8, i32* @CG |
| 60 | ; CHECK: Write to text section |
| 61 | store i32 8, i32* bitcast (i32()* @foo to i32*) |
| 62 | ; CHECK: Load from block address |
| 63 | %lb = load i32* bitcast (i8* blockaddress(@foo, %next) to i32*) |
| 64 | ; CHECK: Call to block address |
| 65 | call void()* bitcast (i8* blockaddress(@foo, %next) to void()*)() |
| Dan Gohman | a20a5cd | 2010-05-26 22:21:25 +0000 | [diff] [blame] | 66 | ; CHECK: Undefined behavior: Null pointer dereference |
| 67 | call void @llvm.stackrestore(i8* null) |
| Dan Gohman | 0fa67e4 | 2010-05-28 21:43:57 +0000 | [diff] [blame] | 68 | ; CHECK: Undefined behavior: Null pointer dereference |
| 69 | call void @has_sret(i8* null) |
| 70 | ; CHECK: Unusual: noalias argument aliases another argument |
| 71 | call void @has_noaliases(i32* @CG, i32* @CG) |
| 72 | ; CHECK: Call argument count mismatches callee argument count |
| 73 | call void (i32, i32)* bitcast (void (i32)* @one_arg to void (i32, i32)*)(i32 0, i32 0) |
| 74 | ; CHECK: Call argument count mismatches callee argument count |
| 75 | call void ()* bitcast (void (i32)* @one_arg to void ()*)() |
| 76 | ; CHECK: Call argument type mismatches callee parameter type |
| 77 | call void (float)* bitcast (void (i32)* @one_arg to void (float)*)(float 0.0) |
| Dan Gohman | 299e7b9 | 2010-04-30 19:05:00 +0000 | [diff] [blame] | 78 | |
| Dan Gohman | c575ec6 | 2010-05-28 17:44:00 +0000 | [diff] [blame] | 79 | ; CHECK: Write to read-only memory |
| 80 | 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) |
| 81 | |
| Duncan Sands | a221eea | 2012-09-26 07:45:36 +0000 | [diff] [blame^] | 82 | ; CHECK: Undefined behavior: Buffer overflow |
| 83 | %wider = bitcast i8* %buf to i16* |
| 84 | store i16 0, i16* %wider |
| 85 | ; CHECK: Undefined behavior: Buffer overflow |
| 86 | %inner = getelementptr {i8, i8}* %buf2, i32 0, i32 1 |
| 87 | %wider2 = bitcast i8* %inner to i16* |
| 88 | store i16 0, i16* %wider2 |
| 89 | ; CHECK: Undefined behavior: Buffer overflow |
| 90 | %before = getelementptr i8* %buf, i32 -1 |
| 91 | %wider3 = bitcast i8* %before to i16* |
| 92 | store i16 0, i16* %wider3 |
| 93 | |
| Dan Gohman | 98bc437 | 2010-04-08 18:47:09 +0000 | [diff] [blame] | 94 | br label %next |
| 95 | |
| 96 | next: |
| 97 | ; CHECK: Static alloca outside of entry block |
| 98 | %a = alloca i32 |
| 99 | ; CHECK: Return statement in function with noreturn attribute |
| 100 | ret i32 0 |
| Dan Gohman | 9ba08a4 | 2010-04-09 01:39:53 +0000 | [diff] [blame] | 101 | |
| 102 | foo: |
| 103 | %z = add i32 0, 0 |
| 104 | ; CHECK: unreachable immediately preceded by instruction without side effects |
| 105 | unreachable |
| 106 | } |
| 107 | |
| 108 | ; CHECK: Unnamed function with non-local linkage |
| 109 | define void @0() nounwind { |
| 110 | ret void |
| 111 | } |
| 112 | |
| 113 | ; CHECK: va_start called in a non-varargs function |
| 114 | declare void @llvm.va_start(i8*) |
| 115 | define void @not_vararg(i8* %p) nounwind { |
| 116 | call void @llvm.va_start(i8* %p) |
| 117 | ret void |
| Dan Gohman | 98bc437 | 2010-04-08 18:47:09 +0000 | [diff] [blame] | 118 | } |
| Dan Gohman | 299e7b9 | 2010-04-30 19:05:00 +0000 | [diff] [blame] | 119 | |
| Dan Gohman | 1249adf | 2010-05-26 21:46:36 +0000 | [diff] [blame] | 120 | ; CHECK: Undefined behavior: Branch to non-blockaddress |
| Dan Gohman | 299e7b9 | 2010-04-30 19:05:00 +0000 | [diff] [blame] | 121 | define void @use_indbr() { |
| 122 | indirectbr i8* bitcast (i32()* @foo to i8*), [label %block] |
| 123 | block: |
| 124 | unreachable |
| 125 | } |
| Dan Gohman | 1249adf | 2010-05-26 21:46:36 +0000 | [diff] [blame] | 126 | |
| Dan Gohman | cef9fc3 | 2010-05-28 16:34:49 +0000 | [diff] [blame] | 127 | ; CHECK: Undefined behavior: Call with "tail" keyword references alloca |
| Dan Gohman | 1249adf | 2010-05-26 21:46:36 +0000 | [diff] [blame] | 128 | declare void @tailcallee(i8*) |
| 129 | define void @use_tail(i8* %valist) { |
| 130 | %t = alloca i8 |
| 131 | tail call void @tailcallee(i8* %t) |
| Dan Gohman | 1249adf | 2010-05-26 21:46:36 +0000 | [diff] [blame] | 132 | ret void |
| 133 | } |
| Dan Gohman | ddba4b7 | 2010-05-28 04:33:42 +0000 | [diff] [blame] | 134 | |
| Dan Gohman | cef9fc3 | 2010-05-28 16:34:49 +0000 | [diff] [blame] | 135 | ; CHECK: Unusual: Returning alloca value |
| Dan Gohman | ddba4b7 | 2010-05-28 04:33:42 +0000 | [diff] [blame] | 136 | define i8* @return_local(i32 %n, i32 %m) { |
| 137 | %t = alloca i8, i32 %n |
| 138 | %s = getelementptr i8* %t, i32 %m |
| 139 | ret i8* %s |
| 140 | } |
| Dan Gohman | 54d7aaa | 2010-05-28 16:21:24 +0000 | [diff] [blame] | 141 | |
| Dan Gohman | cef9fc3 | 2010-05-28 16:34:49 +0000 | [diff] [blame] | 142 | ; CHECK: Unusual: Returning alloca value |
| Dan Gohman | 54d7aaa | 2010-05-28 16:21:24 +0000 | [diff] [blame] | 143 | define i32* @return_obscured_local() { |
| 144 | entry: |
| 145 | %retval = alloca i32* |
| 146 | %x = alloca i32 |
| 147 | store i32* %x, i32** %retval |
| 148 | br label %next |
| 149 | next: |
| 150 | %t0 = load i32** %retval |
| 151 | %t1 = insertvalue { i32, i32, i32* } zeroinitializer, i32* %t0, 2 |
| 152 | %t2 = extractvalue { i32, i32, i32* } %t1, 2 |
| 153 | br label %exit |
| 154 | exit: |
| 155 | %t3 = phi i32* [ %t2, %next ] |
| 156 | %t4 = bitcast i32* %t3 to i32* |
| 157 | %t5 = ptrtoint i32* %t4 to i64 |
| 158 | %t6 = add i64 %t5, 0 |
| 159 | %t7 = inttoptr i64 %t6 to i32* |
| 160 | ret i32* %t7 |
| 161 | } |
| Dan Gohman | 862f034 | 2010-05-28 16:45:33 +0000 | [diff] [blame] | 162 | |
| 163 | ; CHECK: Undefined behavior: Undef pointer dereference |
| 164 | define i32* @self_reference() { |
| 165 | entry: |
| 166 | unreachable |
| 167 | exit: |
| 168 | %t3 = phi i32* [ %t4, %exit ] |
| 169 | %t4 = bitcast i32* %t3 to i32* |
| Chris Lattner | 6a144a2 | 2011-11-27 06:54:59 +0000 | [diff] [blame] | 170 | %x = load volatile i32* %t3 |
| Dan Gohman | 862f034 | 2010-05-28 16:45:33 +0000 | [diff] [blame] | 171 | br label %exit |
| 172 | } |
| Dan Gohman | c128e70 | 2010-07-12 18:02:04 +0000 | [diff] [blame] | 173 | |
| 174 | ; CHECK: Call return type mismatches callee return type |
| 175 | %struct = type { double, double } |
| 176 | declare i32 @nonstruct_callee() nounwind |
| 177 | define void @struct_caller() nounwind { |
| 178 | entry: |
| 179 | call %struct bitcast (i32 ()* @foo to %struct ()*)() |
| Dan Gohman | d8968da | 2010-08-02 23:06:43 +0000 | [diff] [blame] | 180 | |
| 181 | ; CHECK: Undefined behavior: indirectbr with no destinations |
| 182 | indirectbr i8* null, [] |
| Dan Gohman | c128e70 | 2010-07-12 18:02:04 +0000 | [diff] [blame] | 183 | } |