1 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 #include <sanitizer/asan_interface.h>
7 // If we use %p with MS CRTs, it comes out all upper case. Use %08x to get
11 # define PTR_FMT "0x%08llx"
13 # define PTR_FMT "0x%08x"
15 // Solaris libc omits the leading 0x.
16 #elif defined(__sun__) && defined(__svr4__)
17 # define PTR_FMT "0x%p"
25 // Disable stderr buffering. Needed on Windows.
26 setvbuf(stderr
, NULL
, _IONBF
, 0);
28 heap_ptr
= (char *)malloc(10);
29 fprintf(stderr
, "heap_ptr: " PTR_FMT
"\n", heap_ptr
);
30 // CHECK: heap_ptr: 0x[[ADDR:[0-9a-f]+]]
33 free(heap_ptr
); // BOOM
37 // Required for dyld macOS 12.0+
43 int present
= __asan_report_present();
44 void *addr
= __asan_get_report_address();
45 const char *description
= __asan_get_report_description();
47 fprintf(stderr
, "%s\n", (present
== 1) ? "report present" : "");
48 // CHECK: report present
49 fprintf(stderr
, "addr: " PTR_FMT
"\n", addr
);
50 // CHECK: addr: {{0x0*}}[[ADDR]]
51 fprintf(stderr
, "description: %s\n", description
);
52 // CHECK: description: double-free
55 // CHECK: AddressSanitizer: attempting double-free on {{0x0*}}[[ADDR]] in thread T0