Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / backtrace_interceptor.cpp
blobf1ce7d18c0b8a2eacb0142119fc5efc9ad227fda
1 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
3 // Windows does not have execinfo.h. For now, be conservative and
4 // restrict the test to glibc.
5 // REQUIRES: glibc-2.27
7 // Test the backtrace() interceptor.
9 #include <assert.h>
10 #include <execinfo.h>
11 #include <math.h>
12 #include <stdio.h>
13 #include <stdlib.h>
15 #define MAX_BT 100
17 int main() {
18 void **buffer = (void **)malloc(sizeof(void *) * MAX_BT);
19 assert(buffer != NULL);
20 free(buffer);
22 // Deliberate use-after-free of 'buffer'. We expect ASan to
23 // catch this, without triggering internal sanitizer errors.
24 int numEntries = backtrace(buffer, MAX_BT);
25 printf("backtrace returned %d entries\n", numEntries);
27 // CHECK: use-after-free
28 // CHECK: SUMMARY
29 return 0;