| 1 |
// RUN: %clang_hwasan %s -o %t && not %run %t 2>&1 | FileCheck %s |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
#include <stdio.h> |
| 5 |
#include <sanitizer/hwasan_interface.h> |
| 6 |
|
| 7 |
int main() { |
| 8 |
__hwasan_enable_allocator_tagging(); |
| 9 |
char * volatile x = (char*)malloc(40); |
| 10 |
free(x); |
| 11 |
free(x); |
| 12 |
// CHECK: ERROR: HWAddressSanitizer: invalid-free on address {{.*}} at pc {{[0x]+}}[[PC:.*]] on thread T{{[0-9]+}} |
| 13 |
// CHECK: tags: [[PTR_TAG:..]]/[[MEM_TAG:..]] (ptr/mem) |
| 14 |
// CHECK: #0 {{[0x]+}}{{.*}}[[PC]] |
| 15 |
// If we instrument using calls (default on x86), free is not the top frame |
| 16 |
// of the fault. With TCO the free frame can be replaced with the interceptor. |
| 17 |
// CHECK: in {{.*}}free |
| 18 |
// CHECK: freed by thread {{.*}} here: |
| 19 |
// CHECK: previously allocated by thread {{.*}} here: |
| 20 |
// CHECK: Memory tags around the buggy address (one tag corresponds to 16 bytes): |
| 21 |
// CHECK: =>{{.*}}[[MEM_TAG]] |
| 22 |
fprintf(stderr, "DONE\n"); |
| 23 |
__hwasan_disable_allocator_tagging(); |
| 24 |
// CHECK-NOT: DONE |
| 25 |
} |