| 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 | fflush(stdout); |
| 25 | // WRITE: ERROR: HWAddressSanitizer: tag-mismatch on address |
| 26 | // WRITE: WRITE of size 32 at {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) |
| 27 | // WRITE: Invalid access starting at offset 16 |
| 28 | // WRITE: Memory tags around the buggy address (one tag corresponds to 16 bytes): |
| 29 | // WRITE: =>{{.*}}[[PTR_TAG]]{{[[:space:]]\[}}[[MEM_TAG]] |
| 30 | // WRITE-NOT: recovered |
| 31 | |
| 32 | // READ: ERROR: HWAddressSanitizer: tag-mismatch on address |
| 33 | // READ-NOT: Invalid access starting at offset |
| 34 | // READ: READ {{.*}} tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) |
| 35 | // READ: Memory tags around the buggy address (one tag corresponds to 16 bytes): |
| 36 | // READ: =>{{.*}}[[PTR_TAG]]{{[[:space:]]\[}}[[MEM_TAG]] |
| 37 | // READ-NOT: recovered |
| 38 | |
| 39 | // RECOVER: recovered |
| 40 | return 0; |
| 41 | } |
| 42 | |