| 1 | // RUN: %clang_hwasan %s -o %t |
| 2 | // RUN: not %run %t 50 2>&1 | FileCheck %s |
| 3 | // RUN: not %run %t 40 2>&1 | FileCheck %s |
| 4 | // RUN: not %run %t 30 2>&1 | FileCheck %s |
| 5 | |
| 6 | #include <stdlib.h> |
| 7 | #include <stdio.h> |
| 8 | #include <sanitizer/hwasan_interface.h> |
| 9 | |
| 10 | int main(int argc, char **argv) { |
| 11 | __hwasan_enable_allocator_tagging(); |
| 12 | if (argc != 2) return 0; |
| 13 | int realloc_size = atoi(nptr: argv[1]); |
| 14 | char * volatile x = (char*)malloc(size: 40); |
| 15 | free(ptr: x); |
| 16 | x = realloc(ptr: x, size: realloc_size); |
| 17 | // CHECK: ERROR: HWAddressSanitizer: invalid-free on address |
| 18 | // CHECK: tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) |
| 19 | // CHECK: freed by thread {{.*}} here: |
| 20 | // CHECK: previously allocated by thread {{.*}} here: |
| 21 | // CHECK: Memory tags around the buggy address (one tag corresponds to 16 bytes): |
| 22 | // CHECK: =>{{.*}}[[MEM_TAG]] |
| 23 | fprintf(stderr, format: "DONE\n" ); |
| 24 | __hwasan_disable_allocator_tagging(); |
| 25 | // CHECK-NOT: DONE |
| 26 | } |
| 27 | |