1 // RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=COMMON
2 // RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=1 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON
3 // RUN: %clangxx_hwasan -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON
4 
5 // RUN: %clangxx_hwasan -O0 %s -o %t -fsanitize-recover=hwaddress && not %run %t 2>&1 | FileCheck %s --check-prefix=COMMON
6 // RUN: %clangxx_hwasan -O0 %s -o %t -fsanitize-recover=hwaddress && not %env_hwasan_opts=halt_on_error=1 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON
7 // RUN: %clangxx_hwasan -O0 %s -o %t -fsanitize-recover=hwaddress && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefixes=COMMON,RECOVER
8 
9 // RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=COMMON
10 // RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=1 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON
11 // RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON
12 
13 // RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t -fsanitize-recover=hwaddress && not %run %t 2>&1 | FileCheck %s --check-prefix=COMMON
14 // RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t -fsanitize-recover=hwaddress && not %env_hwasan_opts=halt_on_error=1 %run %t 2>&1 | FileCheck %s --check-prefix=COMMON
15 // RUN: %clangxx_hwasan -mllvm -hwasan-instrument-with-calls=1 -O0 %s -o %t -fsanitize-recover=hwaddress && not %env_hwasan_opts=halt_on_error=0 %run %t 2>&1 | FileCheck %s --check-prefixes=COMMON,RECOVER
16 
17 // REQUIRES: stable-runtime
18 
19 #include <stdlib.h>
20 #include <sanitizer/hwasan_interface.h>
21 
main()22 int main() {
23   __hwasan_enable_allocator_tagging();
24   int* volatile x = (int*)malloc(16);
25   free(x);
26   __hwasan_disable_allocator_tagging();
27   return x[2] + ((char *)x)[6] + ((char *)x)[9];
28   // COMMON: READ of size 4 at
29   // When instrumenting with callbacks, main is actually #1, and #0 is __hwasan_load4.
30   // COMMON: #{{.*}} in main {{.*}}halt-on-error.cpp:27
31   // COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in
32 
33   // RECOVER: READ of size 1 at
34   // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:27
35   // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in
36 
37   // RECOVER: READ of size 1 at
38   // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:27
39   // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in
40 
41   // COMMON-NOT: tag-mismatch
42 }
43