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// FIXME: Recursive call into malloc from stack->Print(). Or maybe this feature
11// needs to be removed. We don't use it, but it's in the hot code.
12// UNSUPPORTED: internal_symbolizer
13
14#include <stdlib.h>
15#include <stdio.h>
16#include <sanitizer/hwasan_interface.h>
17
18int main() {
19 __hwasan_enable_allocator_tagging();
20 // DUMP: [alloc] {{.*}} 10{{$}}
21 // DUMP: in main{{.*}}malloc_bisect.c
22 char * volatile p = (char*)malloc(size: 10);
23 // CRASH: HWAddressSanitizer: tag-mismatch on address
24 // CRASH: in main{{.*}}malloc_bisect.c
25 char volatile x = p[16];
26 free(ptr: p);
27 __hwasan_disable_allocator_tagging();
28
29 return 0;
30}
31

source code of compiler-rt/test/hwasan/TestCases/malloc_bisect.c