Home | History | Annotate | Download | only in lit_tests
      1 // RUN: %clangxx_asan %s -o %t && %t
      2 // http://code.google.com/p/address-sanitizer/issues/detail?id=147 (not fixed).
      3 // BROKEN: %clangxx_asan %s -o %t -static-libstdc++ && %t
      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, no_sanitize_address))
     11 void ReallyThrow() {
     12   fprintf(stderr, "ReallyThrow\n");
     13   if (zero == 0)
     14     throw 42;
     15 }
     16 
     17 __attribute__((noinline))
     18 void Throw() {
     19   int a, b, c, d, e;
     20   pretend_to_do_something(&a);
     21   pretend_to_do_something(&b);
     22   pretend_to_do_something(&c);
     23   pretend_to_do_something(&d);
     24   pretend_to_do_something(&e);
     25   fprintf(stderr, "Throw stack = %p\n", &a);
     26   ReallyThrow();
     27 }
     28 
     29 __attribute__((noinline))
     30 void CheckStack() {
     31   int ar[100];
     32   pretend_to_do_something(ar);
     33   for (int i = 0; i < 100; i++)
     34     ar[i] = i;
     35   fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100);
     36 }
     37 
     38 int main(int argc, char** argv) {
     39   try {
     40     Throw();
     41   } catch(int a) {
     42     fprintf(stderr, "a = %d\n", a);
     43   }
     44   CheckStack();
     45 }
     46