|
1 |
| -// RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK |
2 |
| -// RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK |
3 |
| -// RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK |
4 |
| -// RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK |
| 1 | +// RUN: %clangxx_hwasan -O0 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD |
| 2 | +// RUN: %clangxx_hwasan -O1 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD |
| 3 | +// RUN: %clangxx_hwasan -O2 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD |
| 4 | +// RUN: %clangxx_hwasan -O3 -DLOAD %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,LOAD |
| 5 | + |
| 6 | +// RUN: %clangxx_hwasan -O0 -DSTORE %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,STORE |
| 7 | + |
5 | 8 | // REQUIRES: stable-runtime
|
6 | 9 |
|
7 | 10 | #include <stdlib.h>
|
8 | 11 | #include <sanitizer/hwasan_interface.h>
|
9 | 12 |
|
10 | 13 | int main() {
|
11 | 14 | __hwasan_enable_allocator_tagging();
|
12 |
| - char *x = (char*)malloc(10); |
| 15 | + char * volatile x = (char*)malloc(10); |
13 | 16 | free(x);
|
14 | 17 | __hwasan_disable_allocator_tagging();
|
| 18 | +#ifdef STORE |
| 19 | + x[5] = 42; |
| 20 | +#endif |
| 21 | +#ifdef LOAD |
15 | 22 | return x[5];
|
16 |
| - // CHECK: READ of size 1 at |
17 |
| - // CHECK: #0 {{.*}} in main {{.*}}use-after-free.cc:15 |
| 23 | +#endif |
| 24 | + // LOAD: READ of size 1 at |
| 25 | + // LOAD: #0 {{.*}} in main {{.*}}use-after-free.cc:22 |
| 26 | + |
| 27 | + // STORE: WRITE of size 1 at |
| 28 | + // STORE: #0 {{.*}} in main {{.*}}use-after-free.cc:19 |
18 | 29 |
|
19 | 30 | // CHECK: freed here:
|
20 | 31 | // CHECK: #0 {{.*}} in free {{.*}}hwasan_interceptors.cc
|
21 |
| - // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:13 |
| 32 | + // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:16 |
22 | 33 |
|
23 | 34 | // CHECK: previously allocated here:
|
24 | 35 | // CHECK: #0 {{.*}} in __interceptor_malloc {{.*}}hwasan_interceptors.cc
|
25 |
| - // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:12 |
| 36 | + // CHECK: #1 {{.*}} in main {{.*}}use-after-free.cc:15 |
26 | 37 |
|
27 | 38 | // CHECK: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
|
28 | 39 | }
|
0 commit comments