aboutsummaryrefslogtreecommitdiff
path: root/test/asan/TestCases/throw_call_test.cc
blob: 20a7c0b7660155102bb8fac142b6b9ce7cc58306 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// RUN: %clangxx_asan %s -o %t && %run %t
// http://code.google.com/p/address-sanitizer/issues/detail?id=147 (not fixed).
// BROKEN: %clangxx_asan %s -o %t -static-libstdc++ && %run %t

#include <stdio.h>
static volatile int zero = 0;
inline void pretend_to_do_something(void *x) {
  __asm__ __volatile__("" : : "r" (x) : "memory");
}

__attribute__((noinline, no_sanitize_address))
void ReallyThrow() {
  fprintf(stderr, "ReallyThrow\n");
  if (zero == 0)
    throw 42;
}

__attribute__((noinline))
void Throw() {
  int a, b, c, d, e, f, g, h;
  pretend_to_do_something(&a);
  pretend_to_do_something(&b);
  pretend_to_do_something(&c);
  pretend_to_do_something(&d);
  pretend_to_do_something(&e);
  pretend_to_do_something(&f);
  pretend_to_do_something(&g);
  pretend_to_do_something(&h);
  fprintf(stderr, "Throw stack = %p\n", &a);
  ReallyThrow();
}

__attribute__((noinline))
void CheckStack() {
  int ar[100];
  pretend_to_do_something(ar);
  fprintf(stderr, "CheckStack stack = %p, %p\n", ar, ar + 100);
  for (int i = 0; i < 100; i++)
    ar[i] = i;
}

int main(int argc, char** argv) {
  try {
    Throw();
  } catch(int a) {
    fprintf(stderr, "a = %d\n", a);
  }
  CheckStack();
}