OLD | NEW |
1 ; Verify that ASan properly catches and reports bugs | 1 ; Verify that ASan properly catches and reports bugs |
2 | 2 |
3 ; REQUIRES: no_minimal_build | 3 ; REQUIRES: no_minimal_build |
4 | 4 |
5 ; check with a one off the end local access | 5 ; check with a one off the end local load |
6 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ | 6 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
7 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ | 7 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
8 ; RUN: %t.pexe -o %t && %t 2>&1 | FileCheck %s | 8 ; RUN: %t.pexe -o %t && %t 2>&1 | FileCheck --check-prefix=LOCAL-LOAD %s |
9 | 9 |
10 ; check with a many off the end local access | 10 ; check with a many off the end local load |
11 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ | 11 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
12 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ | 12 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
13 ; RUN: %t.pexe -o %t && %t 1 2>&1 | FileCheck %s | 13 ; RUN: %t.pexe -o %t && %t 1 2>&1 | FileCheck --check-prefix=LOCAL-LOAD %s |
14 | 14 |
15 ; check with a one before the front local access | 15 ; check with a one before the front local load |
16 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ | 16 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
17 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ | 17 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
18 ; RUN: %t.pexe -o %t && %t 1 2 2>&1 | FileCheck %s | 18 ; RUN: %t.pexe -o %t && %t 1 2 2>&1 | FileCheck --check-prefix=LOCAL-LOAD %s |
19 | 19 |
20 ; check with a one off the end global access | 20 ; check with a one off the end global load |
21 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ | 21 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
22 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ | 22 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
23 ; RUN: %t.pexe -o %t && %t 1 2 3 2>&1 | FileCheck %s | 23 ; RUN: %t.pexe -o %t && %t 1 2 3 2>&1 | FileCheck \ |
| 24 ; RUN: --check-prefix=GLOBAL-LOAD %s |
24 | 25 |
25 ; check with a many off the end global access | 26 ; check with a many off the end global load |
26 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ | 27 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
27 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ | 28 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
28 ; RUN: %t.pexe -o %t && %t 1 2 3 4 2>&1 | FileCheck %s | 29 ; RUN: %t.pexe -o %t && %t 1 2 3 4 2>&1 | FileCheck \ |
| 30 ; RUN: --check-prefix=GLOBAL-LOAD %s |
29 | 31 |
30 ; check with a one before the front global access | 32 ; check with a one before the front global load |
31 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ | 33 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
32 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ | 34 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
33 ; RUN: %t.pexe -o %t && %t 1 2 3 4 5 2>&1 | FileCheck %s | 35 ; RUN: %t.pexe -o %t && %t 1 2 3 4 5 2>&1 | FileCheck \ |
| 36 ; RUN: --check-prefix=GLOBAL-LOAD %s |
34 | 37 |
| 38 ; check with a one off the end local store |
| 39 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
| 40 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
| 41 ; RUN: %t.pexe -o %t && %t 1 2 3 4 5 6 2>&1 | FileCheck \ |
| 42 ; RUN: --check-prefix=LOCAL-STORE %s |
| 43 |
| 44 ; check with a many off the end local store |
| 45 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
| 46 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
| 47 ; RUN: %t.pexe -o %t && %t 1 2 3 4 5 6 7 2>&1 | FileCheck \ |
| 48 ; RUN: --check-prefix=LOCAL-STORE %s |
| 49 |
| 50 ; check with a one before the front local store |
| 51 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
| 52 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
| 53 ; RUN: %t.pexe -o %t && %t 1 2 3 4 5 6 7 8 2>&1 | FileCheck \ |
| 54 ; RUN: --check-prefix=LOCAL-STORE %s |
| 55 |
| 56 ; check with a one off the end global store |
| 57 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
| 58 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
| 59 ; RUN: %t.pexe -o %t && %t 1 2 3 4 5 6 7 8 9 2>&1 | FileCheck \ |
| 60 ; RUN: --check-prefix=GLOBAL-STORE %s |
| 61 |
| 62 ; check with a many off the end global store |
| 63 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
| 64 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
| 65 ; RUN: %t.pexe -o %t && %t 1 2 3 4 5 6 7 8 9 10 2>&1 | FileCheck \ |
| 66 ; RUN: --check-prefix=GLOBAL-STORE %s |
| 67 |
| 68 ; check with a one before the front global store |
| 69 ; RUN: llvm-as %s -o - | pnacl-freeze > %t.pexe && %S/../../pydir/szbuild.py \ |
| 70 ; RUN: --fsanitize-address --sz=-allow-externally-defined-symbols \ |
| 71 ; RUN: %t.pexe -o %t && %t 1 2 3 4 5 6 7 8 9 10 11 2>&1 | FileCheck \ |
| 72 ; RUN: --check-prefix=GLOBAL-STORE %s |
35 | 73 |
36 declare external void @exit(i32) | 74 declare external void @exit(i32) |
37 | 75 |
38 ; A global array | 76 ; A global array |
39 @array = internal constant [12 x i8] zeroinitializer | 77 @array = internal constant [12 x i8] zeroinitializer |
40 | 78 |
41 define void @access(i32 %is_local_i, i32 %err) { | 79 define void @access(i32 %is_local_i, i32 %is_load_i, i32 %err) { |
42 ; get the base pointer to either the local or global array | 80 ; get the base pointer to either the local or global array |
43 %local = alloca i8, i32 12, align 1 | 81 %local = alloca i8, i32 12, align 1 |
44 %global = bitcast [12 x i8]* @array to i8* | 82 %global = bitcast [12 x i8]* @array to i8* |
45 %is_local = icmp ne i32 %is_local_i, 0 | 83 %is_local = icmp ne i32 %is_local_i, 0 |
46 %arr = select i1 %is_local, i8* %local, i8* %global | 84 %arr = select i1 %is_local, i8* %local, i8* %global |
47 | 85 |
48 ; determine the offset to access | 86 ; determine the offset to access |
49 %err_offset = mul i32 %err, 4 | 87 %err_offset = mul i32 %err, 4 |
50 %pos_offset = add i32 %err_offset, 12 | 88 %pos_offset = add i32 %err_offset, 12 |
51 %pos = icmp sge i32 %err_offset, 0 | 89 %pos = icmp sge i32 %err_offset, 0 |
52 %offset = select i1 %pos, i32 %pos_offset, i32 %err | 90 %offset = select i1 %pos, i32 %pos_offset, i32 %err |
53 | 91 |
54 ; calculate the address to access | 92 ; calculate the address to access |
55 %arraddr = ptrtoint i8* %arr to i32 | 93 %arraddr = ptrtoint i8* %arr to i32 |
56 %badaddr = add i32 %arraddr, %offset | 94 %badaddr = add i32 %arraddr, %offset |
57 %badptr = inttoptr i32 %badaddr to i8* | 95 %badptr = inttoptr i32 %badaddr to i8* |
58 | 96 |
59 ; perform the bad access | 97 ; determine load or store |
| 98 %is_load = icmp ne i32 %is_load_i, 0 |
| 99 br i1 %is_load, label %bad_load, label %bad_store |
| 100 |
| 101 bad_load: |
60 %result = load i8, i8* %badptr, align 1 | 102 %result = load i8, i8* %badptr, align 1 |
61 ret void | 103 ret void |
| 104 |
| 105 bad_store: |
| 106 store i8 42, i8* %badptr, align 1 |
| 107 ret void |
62 } | 108 } |
63 | 109 |
64 ; use argc to determine which test routine to run | 110 ; use argc to determine which test routine to run |
65 define void @_start(i32 %arg) { | 111 define void @_start(i32 %arg) { |
66 %argcaddr = add i32 %arg, 8 | 112 %argcaddr = add i32 %arg, 8 |
67 %argcptr = inttoptr i32 %argcaddr to i32* | 113 %argcptr = inttoptr i32 %argcaddr to i32* |
68 %argc = load i32, i32* %argcptr, align 1 | 114 %argc = load i32, i32* %argcptr, align 1 |
69 switch i32 %argc, label %error [i32 1, label %one_local | 115 switch i32 %argc, label %error [i32 1, label %one_local_load |
70 i32 2, label %many_local | 116 i32 2, label %many_local_load |
71 i32 3, label %neg_local | 117 i32 3, label %neg_local_load |
72 i32 4, label %one_global | 118 i32 4, label %one_global_load |
73 i32 5, label %many_global | 119 i32 5, label %many_global_load |
74 i32 6, label %neg_global] | 120 i32 6, label %neg_global_load |
75 one_local: | 121 i32 7, label %one_local_store |
| 122 i32 8, label %many_local_store |
| 123 i32 9, label %neg_local_store |
| 124 i32 10, label %one_global_store |
| 125 i32 11, label %many_global_store |
| 126 i32 12, label %neg_global_store] |
| 127 one_local_load: |
76 ; Access one past the end of a local | 128 ; Access one past the end of a local |
77 call void @access(i32 1, i32 0) | 129 call void @access(i32 1, i32 1, i32 0) |
78 br label %error | 130 br label %error |
79 many_local: | 131 many_local_load: |
80 ; Access five past the end of a local | 132 ; Access five past the end of a local |
81 call void @access(i32 1, i32 4) | 133 call void @access(i32 1, i32 1, i32 4) |
82 br label %error | 134 br label %error |
83 neg_local: | 135 neg_local_load: |
84 ; Access one before the beginning of a local | 136 ; Access one before the beginning of a local |
85 call void @access(i32 1, i32 -1) | 137 call void @access(i32 1, i32 1, i32 -1) |
86 br label %error | 138 br label %error |
87 one_global: | 139 one_global_load: |
88 ; Access one past the end of a global | 140 ; Access one past the end of a global |
89 call void @access(i32 0, i32 0) | 141 call void @access(i32 0, i32 1, i32 0) |
90 br label %error | 142 br label %error |
91 many_global: | 143 many_global_load: |
92 ; Access five past the end of a global | 144 ; Access five past the end of a global |
93 call void @access(i32 0, i32 4) | 145 call void @access(i32 0, i32 1, i32 4) |
94 br label %error | 146 br label %error |
95 neg_global: | 147 neg_global_load: |
96 ; Access one before the beginning of a global | 148 ; Access one before the beginning of a global |
97 call void @access(i32 0, i32 -1) | 149 call void @access(i32 0, i32 1, i32 -1) |
| 150 br label %error |
| 151 one_local_store: |
| 152 ; Access one past the end of a local |
| 153 call void @access(i32 1, i32 0, i32 0) |
| 154 br label %error |
| 155 many_local_store: |
| 156 ; Access five past the end of a local |
| 157 call void @access(i32 1, i32 0, i32 4) |
| 158 br label %error |
| 159 neg_local_store: |
| 160 ; Access one before the beginning of a local |
| 161 call void @access(i32 1, i32 0, i32 -1) |
| 162 br label %error |
| 163 one_global_store: |
| 164 ; Access one past the end of a global |
| 165 call void @access(i32 0, i32 0, i32 0) |
| 166 br label %error |
| 167 many_global_store: |
| 168 ; Access five past the end of a global |
| 169 call void @access(i32 0, i32 0, i32 4) |
| 170 br label %error |
| 171 neg_global_store: |
| 172 ; Access one before the beginning of a global |
| 173 call void @access(i32 0, i32 0, i32 -1) |
98 br label %error | 174 br label %error |
99 error: | 175 error: |
100 call void @exit(i32 1) | 176 call void @exit(i32 1) |
101 unreachable | 177 unreachable |
102 } | 178 } |
103 | 179 |
104 ; CHECK: Illegal access of 1 bytes at | 180 ; LOCAL-LOAD: Illegal 1 byte load from stack object at |
| 181 ; LOCAL-STORE: Illegal 1 byte store to stack object at |
| 182 ; GLOBAL-LOAD: Illegal 1 byte load from global object at |
| 183 ; GLOBAL-STORE: Illegal 1 byte store to global object at |
OLD | NEW |