OLD | NEW |
(Empty) | |
| 1 ; RUN: not pnacl-abicheck < %s | FileCheck %s |
| 2 |
| 3 ; This test checks that the PNaCl ABI verifier enforces the normal |
| 4 ; form introduced by the ReplacePtrsWithInts pass. |
| 5 |
| 6 |
| 7 @var = global [4 x i8] c"xxxx" |
| 8 @ptr = global i32 ptrtoint ([4 x i8]* @var to i32) |
| 9 |
| 10 declare i8* @llvm.nacl.read.tp() |
| 11 |
| 12 |
| 13 define internal void @pointer_arg(i8* %arg) { |
| 14 ret void |
| 15 } |
| 16 ; CHECK: Function pointer_arg has disallowed type |
| 17 |
| 18 define internal i8* @pointer_return() { |
| 19 unreachable |
| 20 } |
| 21 ; CHECK-NEXT: Function pointer_return has disallowed type |
| 22 |
| 23 define internal void @func() { |
| 24 ret void |
| 25 } |
| 26 |
| 27 define internal void @func_with_arg(i32 %arg) { |
| 28 ret void |
| 29 } |
| 30 |
| 31 |
| 32 define internal void @allowed_cases(i32 %arg) { |
| 33 inttoptr i32 123 to i8* |
| 34 |
| 35 ptrtoint [4 x i8]* @var to i32 |
| 36 |
| 37 %alloc = alloca i8 |
| 38 ptrtoint i8* %alloc to i32 |
| 39 load i8* %alloc, align 1 |
| 40 |
| 41 ; These instructions may use a NormalizedPtr, which may be a global. |
| 42 load i32* @ptr, align 1 |
| 43 store i32 123, i32* @ptr, align 1 |
| 44 |
| 45 ; A NormalizedPtr may be a bitcast. |
| 46 %ptr_bitcast = bitcast [4 x i8]* @var to i32* |
| 47 load i32* %ptr_bitcast, align 1 |
| 48 |
| 49 ; A NormalizedPtr may be an inttoptr. |
| 50 %ptr_from_int = inttoptr i32 123 to i32* |
| 51 load i32* %ptr_from_int, align 1 |
| 52 |
| 53 ; Check direct and indirect function calls. |
| 54 %func_as_int = ptrtoint void ()* @func to i32 |
| 55 %func_ptr = inttoptr i32 %func_as_int to void ()* |
| 56 call void %func_ptr() |
| 57 call void @func() |
| 58 call void @func_with_arg(i32 123) |
| 59 |
| 60 ; Intrinsic calls may return pointers. |
| 61 %thread_ptr = call i8* @llvm.nacl.read.tp() |
| 62 ptrtoint i8* %thread_ptr to i32 |
| 63 |
| 64 ; Bitcasts between non-pointers are not restricted |
| 65 bitcast i64 0 to double |
| 66 bitcast i32 0 to float |
| 67 |
| 68 ; ConstantInts and Arguments are allowed as operands. |
| 69 add i32 %arg, 123 |
| 70 |
| 71 ret void |
| 72 } |
| 73 ; CHECK-NOT: disallowed |
| 74 |
| 75 |
| 76 define internal void @bad_cases() { |
| 77 entry: |
| 78 ptrtoint [4 x i8]* @var to i16 |
| 79 ; CHECK: Function bad_cases disallowed: non-i32 ptrtoint |
| 80 |
| 81 inttoptr i16 123 to i8* |
| 82 ; CHECK-NEXT: non-i32 inttoptr |
| 83 |
| 84 %a = alloca i32 |
| 85 ; CHECK-NEXT: non-i8 alloca: %a |
| 86 %a2 = alloca [4 x i8] |
| 87 ; CHECK-NEXT: non-i8 alloca: %a2 |
| 88 |
| 89 store i32 0, i32* null, align 1 |
| 90 ; CHECK-NEXT: bad pointer |
| 91 |
| 92 store i32 0, i32* undef, align 1 |
| 93 ; CHECK-NEXT: bad pointer |
| 94 |
| 95 %bc = bitcast i32* @ptr to i31* |
| 96 ; CHECK-NEXT: bad result type |
| 97 store i31 0, i31* %bc, align 1 |
| 98 ; CHECK-NEXT: bad pointer |
| 99 |
| 100 ; Only one level of bitcasts is allowed. |
| 101 %b = bitcast i32* %a to i8* |
| 102 %c = bitcast i8* %b to i16* |
| 103 ; CHECK-NEXT: operand not InherentPtr |
| 104 |
| 105 br label %block |
| 106 block: |
| 107 %phi1 = phi i8* [ undef, %entry ] |
| 108 ; CHECK-NEXT: bad operand: %phi1 |
| 109 %phi2 = phi i32* [ undef, %entry ] |
| 110 ; CHECK-NEXT: bad operand: %phi2 |
| 111 |
| 112 icmp eq i32* @ptr, @ptr |
| 113 ; CHECK-NEXT: Expects integer arithmetic type: {{.*}} icmp eq i32* |
| 114 icmp eq void ()* @func, @func |
| 115 ; CHECK-NEXT: Expects integer arithmetic type: {{.*}} icmp eq void ()* |
| 116 icmp eq i31 0, 0 |
| 117 ; CHECK-NEXT: Invalid integer arithmetic type: {{.*}} icmp eq i31 |
| 118 |
| 119 call void null() |
| 120 ; CHECK-NEXT: bad function callee operand |
| 121 |
| 122 call void @func_with_arg(i32 ptrtoint (i32* @ptr to i32)) |
| 123 ; CHECK-NEXT: bad operand |
| 124 |
| 125 ; Taking the address of an intrinsic is not allowed. |
| 126 ptrtoint i8* ()* @llvm.nacl.read.tp to i32 |
| 127 ; CHECK-NEXT: operand not InherentPtr |
| 128 |
| 129 ret void |
| 130 } |
| 131 |
| 132 ; CHECK-NOT: disallowed |
| 133 |
| 134 |
| 135 ; This stops the verifier from complaining about the lack of an entry point. |
| 136 define void @_start(i32 %arg) { |
| 137 ret void |
| 138 } |
OLD | NEW |