1 // RUN: %clang_hwasan -O0 %s -o %t
2 // RUN: %env_hwasan_opts=malloc_bisect_left=0,malloc_bisect_right=0          not %run %t 2>&1 | \
3 // RUN:     FileCheck %s --check-prefix=CRASH
4 // RUN: %env_hwasan_opts=malloc_bisect_left=1000,malloc_bisect_right=999         %run %t 2>&1
5 // RUN: %env_hwasan_opts=malloc_bisect_left=0,malloc_bisect_right=4294967295 not %run %t 2>&1 | \
6 // RUN:     FileCheck %s --check-prefix=CRASH
7 // RUN: %env_hwasan_opts=malloc_bisect_left=0,malloc_bisect_right=4294967295,malloc_bisect_dump=1 not %run %t 2>&1 | \
8 // RUN:     FileCheck %s --check-prefixes=CRASH,DUMP
9 
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <sanitizer/hwasan_interface.h>
13 
main()14 int main() {
15   __hwasan_enable_allocator_tagging();
16   // DUMP: [alloc] {{.*}} 10{{$}}
17   // DUMP: in main{{.*}}malloc_bisect.c
18   char * volatile p = (char*)malloc(10);
19   // CRASH: HWAddressSanitizer: tag-mismatch on address
20   // CRASH: in main{{.*}}malloc_bisect.c
21   char volatile x = p[16];
22   free(p);
23   __hwasan_disable_allocator_tagging();
24 
25   return 0;
26 }
27