1 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 #include <sanitizer/asan_interface.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
14 # define PTR_FMT "0x%08llx"
16 # define PTR_FMT "0x%08x"
18 // Solaris libc omits the leading 0x.
19 #elif defined(__sun__) && defined(__svr4__)
20 # define PTR_FMT "0x%p"
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]+]]
36 free(heap_ptr
); // BOOM
40 // Required for dyld macOS 12.0+
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