| 1 | // RUN: %clangxx_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s |
| 2 | |
| 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | #include <sanitizer/hwasan_interface.h> |
| 7 | |
| 8 | __attribute__((no_sanitize("hwaddress" ))) extern "C" void callback(const char *msg) { |
| 9 | fprintf(stderr, format: "== error start\n%s\n== error end\n" , msg); |
| 10 | } |
| 11 | |
| 12 | int main() { |
| 13 | __hwasan_enable_allocator_tagging(); |
| 14 | __hwasan_set_error_report_callback(callback: &callback); |
| 15 | char *volatile p = (char *)malloc(size: 16); |
| 16 | p[16] = 1; |
| 17 | free(ptr: p); |
| 18 | // CHECK: ERROR: HWAddressSanitizer: |
| 19 | // CHECK: WRITE of size 1 at |
| 20 | // CHECK: allocated by thread {{.*}} here: |
| 21 | // CHECK: Memory tags around the buggy address |
| 22 | |
| 23 | // CHECK: == error start |
| 24 | // CHECK: ERROR: HWAddressSanitizer: |
| 25 | // CHECK: WRITE of size 1 at |
| 26 | // CHECK: allocated by thread {{.*}} here: |
| 27 | // CHECK: Memory tags around the buggy address |
| 28 | // CHECK: == error end |
| 29 | } |
| 30 | |