1 | // RUN: %clang_hwasan %s -DTEST_NO=1 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=WRITE |
2 | // RUN: %clang_hwasan %s -DTEST_NO=2 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=READ |
3 | // RUN: %clang_hwasan %s -DTEST_NO=3 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=WRITE |
4 | // RUN: %clang_hwasan %s -DTEST_NO=2 -mllvm -hwasan-instrument-mem-intrinsics -o %t && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefix=RECOVER |
5 | |
6 | // REQUIRES: pointer-tagging |
7 | |
8 | #include <stdio.h> |
9 | #include <stdlib.h> |
10 | #include <string.h> |
11 | #include <unistd.h> |
12 | |
13 | int main() { |
14 | char Q[16] __attribute__((aligned(256))); |
15 | char P[16] __attribute__((aligned(256))); |
16 | #if TEST_NO == 1 |
17 | memset(Q, 0, 32); |
18 | #elif TEST_NO == 2 |
19 | memmove(Q, Q + 16, 16); |
20 | #elif TEST_NO == 3 |
21 | memcpy(Q, P, 32); |
22 | #endif |
23 | write(STDOUT_FILENO, buf: "recovered\n" , n: 10); |
24 | // WRITE: ERROR: HWAddressSanitizer: tag-mismatch on address |
25 | // WRITE: WRITE of size 32 at {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) |
26 | // WRITE: Invalid access starting at offset 16 |
27 | // WRITE: Memory tags around the buggy address (one tag corresponds to 16 bytes): |
28 | // WRITE: =>{{.*}}[[PTR_TAG]]{{[[:space:]]\[}}[[MEM_TAG]] |
29 | // WRITE-NOT: recovered |
30 | |
31 | // READ: ERROR: HWAddressSanitizer: tag-mismatch on address |
32 | // READ-NOT: Invalid access starting at offset |
33 | // READ: READ {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) |
34 | // READ: Memory tags around the buggy address (one tag corresponds to 16 bytes): |
35 | // READ: =>{{.*}}[[PTR_TAG]]{{[[:space:]]\[}}[[MEM_TAG]] |
36 | // READ-NOT: recovered |
37 | |
38 | // RECOVER: recovered |
39 | return 0; |
40 | } |
41 | |