1// RUN: %clangxx_asan -O0 %s -o %t
2// RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
3// RUN: %env_asan_opts=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
4// RUN: %env_asan_opts=malloc_context_size=1:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
5// RUN: %env_asan_opts=malloc_context_size=1:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
6// RUN: %env_asan_opts=malloc_context_size=2 not %run %t 2>&1 | FileCheck %s --check-prefix=TWO
7
8int main() {
9 char *x = new char[20];
10 delete[] x;
11 return x[0];
12
13 // CHECK: freed by thread T{{.*}} here:
14 // CHECK-NEXT: #0 0x{{.*}} in {{operator delete( )?\[\]|_ZdaPv}}
15 // CHECK-NOT: #1 0x{{.*}}
16
17 // CHECK: previously allocated by thread T{{.*}} here:
18 // CHECK-NEXT: #0 0x{{.*}} in {{operator new( )?\[\]|_Znam}}
19 // CHECK-NOT: #1 0x{{.*}}
20
21 // CHECK: SUMMARY: AddressSanitizer: heap-use-after-free
22
23 // TWO: previously allocated by thread T{{.*}} here:
24 // TWO-NEXT: #0 0x{{.*}}
25 // TWO-NEXT: #1 0x{{.*}} in main {{.*}}malloc_context_size.cpp
26 // TWO: SUMMARY: AddressSanitizer: heap-use-after-free
27}
28

source code of compiler-rt/test/asan/TestCases/malloc_context_size.cpp