1 // Check that ASan dumps the CPU registers on a SIGSEGV.
2 
3 // RUN: %clangxx_asan %s -o %t
4 // RUN: not %run %t 2>&1 | FileCheck %s
5 
6 #include <assert.h>
7 #include <stdio.h>
8 #include <sys/mman.h>
9 
main()10 int main() {
11   fprintf(stderr, "Hello\n");
12   char *ptr;
13 
14   ptr = (char *)mmap(NULL, 0x10000, PROT_NONE, MAP_ANON | MAP_PRIVATE, -1, 0);
15   assert(ptr && "failed to mmap");
16 
17   fprintf(stderr, sizeof(uintptr_t) == 8 ? "p = 0x%016lx\n" : "p = 0x%08lx\n", (uintptr_t)ptr);
18   // CHECK: p = [[ADDR:0x[0-9]+]]
19 
20   char c = *ptr;  // BOOM
21   // CHECK: ERROR: AddressSanitizer: {{SEGV|BUS}}
22   // CHECK: Register values:
23   // CHECK: [[ADDR]]
24   fprintf(stderr, "World\n");
25   return c;
26 }
27