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