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#include <stdlib.h>
18#include <sanitizer/hwasan_interface.h>
19
20int main() {
21 __hwasan_enable_allocator_tagging();
22 int* volatile x = (int*)malloc(size: 16);
23 free(ptr: x);
24 __hwasan_disable_allocator_tagging();
25 return x[2] + ((char *)x)[6] + ((char *)x)[9];
26 // COMMON: READ of size 4 at
27 // When instrumenting with callbacks, main is actually #1, and #0 is __hwasan_load4.
28 // COMMON: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-3]]
29 // COMMON: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
30
31 // RECOVER: READ of size 1 at
32 // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-7]]
33 // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
34
35 // RECOVER: READ of size 1 at
36 // RECOVER: #{{.*}} in main {{.*}}halt-on-error.cpp:[[@LINE-11]]
37 // RECOVER: SUMMARY: HWAddressSanitizer: tag-mismatch {{.*}} in main
38
39 // COMMON-NOT: tag-mismatch
40}
41

source code of compiler-rt/test/hwasan/TestCases/halt-on-error.cpp