blob: acf52f918dd8dd5efeaa0201def721584b925c42 [file] [log] [blame]
Stephen Hines6d186232014-11-26 17:56:19 -08001// 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
4
5#include <sanitizer/asan_interface.h>
6#include <stdio.h>
7#include <stdlib.h>
8
9int main() {
10 char *heap_ptr = (char *)malloc(10);
11 free(heap_ptr);
12 int present = __asan_report_present();
13 fprintf(stderr, "%s\n", (present == 0) ? "no report" : "");
14 // CHECK: no report
15 heap_ptr[0] = 'A'; // BOOM
16 return 0;
17}
18
19void __asan_on_error() {
20 int present = __asan_report_present();
21 void *pc = __asan_get_report_pc();
22 void *bp = __asan_get_report_bp();
23 void *sp = __asan_get_report_sp();
24 void *addr = __asan_get_report_address();
25 int is_write = __asan_get_report_access_type();
26 size_t access_size = __asan_get_report_access_size();
27 const char *description = __asan_get_report_description();
28
29 fprintf(stderr, "%s\n", (present == 1) ? "report" : "");
30 // CHECK: report
31 fprintf(stderr, "pc: %p\n", pc);
32 // CHECK: pc: 0x[[PC:[0-9a-f]+]]
33 fprintf(stderr, "bp: %p\n", bp);
34 // CHECK: bp: 0x[[BP:[0-9a-f]+]]
35 fprintf(stderr, "sp: %p\n", sp);
36 // CHECK: sp: 0x[[SP:[0-9a-f]+]]
37 fprintf(stderr, "addr: %p\n", addr);
38 // CHECK: addr: 0x[[ADDR:[0-9a-f]+]]
39 fprintf(stderr, "type: %s\n", (is_write ? "write" : "read"));
40 // CHECK: type: write
41 fprintf(stderr, "access_size: %ld\n", access_size);
42 // CHECK: access_size: 1
43 fprintf(stderr, "description: %s\n", description);
44 // CHECK: description: heap-use-after-free
45}
46
47// CHECK: AddressSanitizer: heap-use-after-free on address {{0x0*}}[[ADDR]] at pc {{0x0*}}[[PC]] bp {{0x0*}}[[BP]] sp {{0x0*}}[[SP]]
48// CHECK: WRITE of size 1 at {{0x0*}}[[ADDR]] thread T0