Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Linux / stack-trace-dlclose.cpp
blob899e0dfc6bda532876ee3a2078a35fd9eefc8fe9
1 // FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
2 // XFAIL: android
3 //
4 // RUN: rm -rf %t-dir
5 // RUN: mkdir -p %t-dir
6 // RUN: %clangxx_asan -DSHARED %s -shared -o %t-dir/stack_trace_dlclose.so -fPIC
7 // RUN: %clangxx_asan -DSO_DIR=\"%t-dir\" %s %libdl -o %t
8 // RUN: %env_asan_opts=exitcode=0 %run %t 2>&1 | FileCheck %s
9 // REQUIRES: stable-runtime
11 #include <assert.h>
12 #include <dlfcn.h>
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <unistd.h>
17 #include <sanitizer/common_interface_defs.h>
19 #ifdef SHARED
20 extern "C" {
21 void *foo() {
22 return malloc(1);
25 #else
26 void *handle;
28 int main(int argc, char **argv) {
29 void *handle = dlopen(SO_DIR "/stack_trace_dlclose.so", RTLD_LAZY);
30 assert(handle);
31 void *(*foo)() = (void *(*)())dlsym(handle, "foo");
32 assert(foo);
33 void *p = foo();
34 assert(p);
35 dlclose(handle);
37 free(p);
38 free(p); // double-free
40 return 0;
42 #endif
44 // CHECK: {{ #0 0x.* in (__interceptor_)?malloc}}
45 // CHECK: {{ #1 0x.* \(<unknown module>\)}}
46 // CHECK: {{ #2 0x.* in main}}