1 // RUN: %clangxx_hwasan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 // RUN: %clangxx_hwasan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 // RUN: %clangxx_hwasan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
4 // RUN: %clangxx_hwasan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
7 #include <sanitizer/hwasan_interface.h>
12 __attribute__((no_sanitize("hwaddress"))) void
13 ForceCallInterceptor(void *p
, const void *a
, size_t size
) {
14 assert(memcmp(p
, a
, size
) == 0);
17 int main(int argc
, char **argv
) {
18 __hwasan_enable_allocator_tagging();
19 char a
[] = {static_cast<char>(argc
), 2, 3, 4};
21 char *p
= (char *)malloc(size
);
24 ForceCallInterceptor(p
, a
, size
);
26 // CHECK: HWAddressSanitizer: tag-mismatch on address
27 // CHECK: READ of size 4
28 // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-4]]
29 // CHECK: Cause: use-after-free
30 // CHECK: freed by thread
31 // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-8]]
32 // CHECK: previously allocated by thread
33 // CHECK: #{{[[:digit:]]+}} 0x{{[[:xdigit:]]+}} in main {{.*}}memcmp.cpp:[[@LINE-12]]