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: stable-runtime
7
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11
12 #include "utils.h"
13
main()14 int main() {
15 char Q[16] __attribute__((aligned(256)));
16 char P[16] __attribute__((aligned(256)));
17 #if TEST_NO == 1
18 memset(Q, 0, 32);
19 #elif TEST_NO == 2
20 memmove(Q, Q + 16, 16);
21 #elif TEST_NO == 3
22 memcpy(Q, P, 32);
23 #endif
24 write(STDOUT_FILENO, UNTAG("recovered\n"), 10);
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, 32)
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