Move MSan lit-tests under test/msan
[blocksruntime.git] / lib / asan / lit_tests / TestCases / double-free.cc
blob6bfd4fa2c7e542b70f1b01bdd4a96303510348e0
1 // RUN: %clangxx_asan -O0 %s -o %t 2>&1
2 // RUN: not %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=MALLOC-CTX
4 // Also works if no malloc context is available.
5 // RUN: ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=0 not %t 2>&1 | FileCheck %s
6 // RUN: ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=1 not %t 2>&1 | FileCheck %s
8 #include <stdlib.h>
9 #include <string.h>
10 int main(int argc, char **argv) {
11 char *x = (char*)malloc(10 * sizeof(char));
12 memset(x, 0, 10);
13 int res = x[argc];
14 free(x);
15 free(x + argc - 1); // BOOM
16 // CHECK: AddressSanitizer: attempting double-free{{.*}}in thread T0
17 // CHECK: #0 0x{{.*}} in {{.*}}free
18 // CHECK: #1 0x{{.*}} in main {{.*}}double-free.cc:[[@LINE-3]]
19 // CHECK: freed by thread T0 here:
20 // MALLOC-CTX: #0 0x{{.*}} in {{.*}}free
21 // MALLOC-CTX: #1 0x{{.*}} in main {{.*}}double-free.cc:[[@LINE-7]]
22 // CHECK: allocated by thread T0 here:
23 // MALLOC-CTX: double-free.cc:[[@LINE-12]]
24 return res;