1 | // RUN: %clang_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 | int main() { |
9 | __hwasan_enable_allocator_tagging(); |
10 | char *p = (char *)malloc(size: 1); |
11 | fprintf(stderr, format: "ALLOC %p\n" , __hwasan_tag_pointer(p, tag: 0)); |
12 | // CHECK: ALLOC {{[0x]+}}[[ADDR:.*]] |
13 | free(ptr: p - 8); |
14 | // CHECK: ERROR: HWAddressSanitizer: invalid-free on address {{.*}} at pc {{[0x]+}}[[PC:.*]] on thread T{{[0-9]+}} |
15 | // CHECK: #0 {{[0x]+}}{{.*}}[[PC]] in {{.*}}free |
16 | // CHECK: #1 {{.*}} in main {{.*}}wild-free-close.c:[[@LINE-3]] |
17 | // CHECK: is located 8 bytes before a 1-byte region [{{[0x]+}}{{.*}}[[ADDR]] |
18 | // CHECK-NOT: Segmentation fault |
19 | // CHECK-NOT: SIGSEGV |
20 | return 0; |
21 | } |
22 | |