Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / debug_double_free.cpp
blobde5ac7b0c8d5cda5155a62207710e1404740e27e
1 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 #include <sanitizer/asan_interface.h>
4 #include <stdio.h>
5 #include <stdlib.h>
7 // FIXME: Doesn't work with DLLs
8 // XFAIL: win32-dynamic-asan
10 // If we use %p with MSVC, it comes out all upper case. Use %08x to get
11 // lowercase hex.
12 #ifdef _MSC_VER
13 # ifdef _WIN64
14 # define PTR_FMT "0x%08llx"
15 # else
16 # define PTR_FMT "0x%08x"
17 # endif
18 // Solaris libc omits the leading 0x.
19 #elif defined(__sun__) && defined(__svr4__)
20 # define PTR_FMT "0x%p"
21 #else
22 # define PTR_FMT "%p"
23 #endif
25 char *heap_ptr;
27 int main() {
28 // Disable stderr buffering. Needed on Windows.
29 setvbuf(stderr, NULL, _IONBF, 0);
31 heap_ptr = (char *)malloc(10);
32 fprintf(stderr, "heap_ptr: " PTR_FMT "\n", heap_ptr);
33 // CHECK: heap_ptr: 0x[[ADDR:[0-9a-f]+]]
35 free(heap_ptr);
36 free(heap_ptr); // BOOM
37 return 0;
40 // Required for dyld macOS 12.0+
41 #if (__APPLE__)
42 __attribute__((weak))
43 #endif
44 extern "C" void
45 __asan_on_error() {
46 int present = __asan_report_present();
47 void *addr = __asan_get_report_address();
48 const char *description = __asan_get_report_description();
50 fprintf(stderr, "%s\n", (present == 1) ? "report present" : "");
51 // CHECK: report present
52 fprintf(stderr, "addr: " PTR_FMT "\n", addr);
53 // CHECK: addr: {{0x0*}}[[ADDR]]
54 fprintf(stderr, "description: %s\n", description);
55 // CHECK: description: double-free
58 // CHECK: AddressSanitizer: attempting double-free on {{0x0*}}[[ADDR]] in thread T0