1 // Checks that the ASan debugging API for getting report information
2 // returns correct values.
3 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
5 #include <sanitizer/asan_interface.h>
10 // Disable stderr buffering. Needed on Windows.
11 setvbuf(stderr
, NULL
, _IONBF
, 0);
13 char *heap_ptr
= (char *)malloc(10);
15 int present
= __asan_report_present();
16 fprintf(stderr
, "%s\n", (present
== 0) ? "no report" : "");
18 heap_ptr
[0] = 'A'; // BOOM
22 // If we use %p with MS CRTs, it comes out all upper case. Use %08x to get
26 # define PTR_FMT "0x%08llx"
28 # define PTR_FMT "0x%08x"
30 // Solaris libc omits the leading 0x.
31 #elif defined(__sun__) && defined(__svr4__)
32 # define PTR_FMT "0x%p"
37 // Required for dyld macOS 12.0+
43 int present
= __asan_report_present();
44 void *pc
= __asan_get_report_pc();
45 void *bp
= __asan_get_report_bp();
46 void *sp
= __asan_get_report_sp();
47 void *addr
= __asan_get_report_address();
48 int is_write
= __asan_get_report_access_type();
49 size_t access_size
= __asan_get_report_access_size();
50 const char *description
= __asan_get_report_description();
52 fprintf(stderr
, "%s\n", (present
== 1) ? "report" : "");
54 fprintf(stderr
, "pc: " PTR_FMT
"\n", pc
);
55 // CHECK: pc: 0x[[PC:[0-9a-f]+]]
56 fprintf(stderr
, "bp: " PTR_FMT
"\n", bp
);
57 // CHECK: bp: 0x[[BP:[0-9a-f]+]]
58 fprintf(stderr
, "sp: " PTR_FMT
"\n", sp
);
59 // CHECK: sp: 0x[[SP:[0-9a-f]+]]
60 fprintf(stderr
, "addr: " PTR_FMT
"\n", addr
);
61 // CHECK: addr: 0x[[ADDR:[0-9a-f]+]]
62 fprintf(stderr
, "type: %s\n", (is_write
? "write" : "read"));
64 fprintf(stderr
, "access_size: %ld\n", access_size
);
65 // CHECK: access_size: 1
66 fprintf(stderr
, "description: %s\n", description
);
67 // CHECK: description: heap-use-after-free
70 // CHECK: AddressSanitizer: heap-use-after-free on address {{0x0*}}[[ADDR]] at pc {{0x0*}}[[PC]] bp {{0x0*}}[[BP]] sp {{0x0*}}[[SP]]
71 // CHECK: WRITE of size 1 at {{0x0*}}[[ADDR]] thread T0