Home | History | Annotate | Download | only in TestCases
      1 // RUN: %clangxx_asan %s -o %t && %run %t
      2 // RUN: %clangxx_asan %s -o %t -static-libstdc++ && %run %t
      3 
      4 // Clang doesn't support exceptions on Windows yet.
      5 // XFAIL: win32
      6 
      7 #include <stdio.h>
      8 static volatile int zero = 0;
      9 inline void pretend_to_do_something(void *x) {
     10   __asm__ __volatile__("" : : "r" (x) : "memory");
     11 }
     12 
     13 __attribute__((noinline))
     14 void ReallyThrow() {
     15   fprintf(stderr, "ReallyThrow\n");
     16   try {
     17     if (zero == 0)
     18       throw 42;
     19     else if (zero == 1)
     20       throw 1.;
     21   } catch(double x) {
     22   }
     23 }
     24 
     25 __attribute__((noinline))
     26 void Throw() {
     27   int a, b, c, d, e;
     28   pretend_to_do_something(&a);
     29   pretend_to_do_something(&b);
     30   pretend_to_do_something(&c);
     31   pretend_to_do_something(&d);
     32   pretend_to_do_something(&e);
     33   fprintf(stderr, "Throw stack = %p\n", &a);
     34   ReallyThrow();
     35 }
     36 
     37 __attribute__((noinline))
     38 void CheckStack() {
     39   int ar[100];
     40   pretend_to_do_something(ar);
     41   for (int i = 0; i < 100; i++)
     42     ar[i] = i;
     43   fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100);
     44 }
     45 
     46 int main(int argc, char** argv) {
     47   try {
     48     Throw();
     49   } catch(int a) {
     50     fprintf(stderr, "a = %d\n", a);
     51   }
     52   CheckStack();
     53 }
     54 
     55