1 // RUN: %clangxx_asan -xc++ -shared -fPIC -o %t.so - < %s
2 // RUN: %clang_asan %s -o %t.out -ldl
3 //
4 // RUN: { env ASAN_OPTIONS=verbosity=1 %t.out %t.so || : ; } 2>&1 | FileCheck %s
5 //
6 // CHECK: AddressSanitizer: failed to intercept '__cxa_throw'
7 //
8 // This tests assumes static linking of the asan runtime.
9 // UNSUPPORTED: asan-dynamic-runtime
10 
11 #ifdef __cplusplus
12 
foo(void)13 static void foo(void) {
14   int i = 0;
15   throw(i);
16 }
17 
18 extern "C" {
19 int bar(void);
20 };
bar(void)21 int bar(void) {
22   try {
23     foo();
24   } catch (int i) {
25     return i;
26   }
27   return -1;
28 }
29 
30 #else
31 
32 #include <assert.h>
33 #include <dlfcn.h>
34 
main(int argc,char ** argv)35 int main(int argc, char **argv) {
36   int (*bar)(void);
37   void *handle = dlopen(argv[1], RTLD_LAZY);
38   assert(handle);
39   bar = dlsym(handle, "bar");
40   assert(bar);
41   return bar();
42 }
43 
44 #endif
45