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