Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Darwin / crashlog-stacktraces.c
blob9151614819874f381eb8949979b20a6a760acb0a
1 // RUN: %clang_asan -O0 %s -o %t
2 // RUN: not %run %t 2>&1 | FileCheck %s
4 // Since ASan is built with -fomit-frame-pointer, backtrace is not able to
5 // symbolicate the trace past ASan runtime on i386. (This is fixed in
6 // latest OS X.)
7 // REQUIRES: asan-64-bits
9 #include <execinfo.h>
10 #include <sanitizer/common_interface_defs.h>
11 #include <stdio.h>
12 #include <stdlib.h>
14 void death_function() {
15 fprintf(stderr, "DEATH CALLBACK\n");
17 void* callstack[128];
18 int i, frames = backtrace(callstack, 128);
19 char** strs = backtrace_symbols(callstack, frames);
20 for (i = 0; i < frames; ++i) {
21 fprintf(stderr, "%s\n", strs[i]);
23 free(strs);
25 fprintf(stderr, "END OF BACKTRACE\n");
28 int fault_function() {
29 char *x = (char*)malloc(10 * sizeof(char));
30 free(x);
31 return x[5]; // BOOM
34 int main() {
35 __sanitizer_set_death_callback(death_function);
36 fault_function();
37 return 0;
40 // CHECK: {{.*ERROR: AddressSanitizer: heap-use-after-free on address}}
41 // CHECK: {{READ of size 1 at 0x.* thread T0}}
42 // CHECK: {{ #0 0x.* in fault_function}}
44 // CHECK: DEATH CALLBACK
45 // CHECK: death_function
46 // CHECK: fault_function
47 // CHECK: main
48 // CHECK: END OF BACKTRACE