1// Test that use-after-return works with exceptions.
2// export ASAN_OPTIONS=detect_stack_use_after_return=1
3// RUN: %clangxx_asan  -O0 %s -o %t && %run %t
4
5// Clang doesn't support exceptions on Windows yet.
6// XFAIL: win32
7
8#include <stdio.h>
9
10volatile char *g;
11
12#ifndef FRAME_SIZE
13# define FRAME_SIZE 100
14#endif
15
16#ifndef NUM_ITER
17# define NUM_ITER 4000
18#endif
19
20#ifndef DO_THROW
21# define DO_THROW 1
22#endif
23
24void Func(int depth) {
25  char frame[FRAME_SIZE];
26  g = &frame[0];
27  if (depth)
28    Func(depth - 1);
29  else if (DO_THROW)
30    throw 1;
31}
32
33int main(int argc, char **argv) {
34  for (int i = 0; i < NUM_ITER; i++) {
35    try {
36      Func(argc * 100);
37    } catch(...) {
38    }
39    if ((i % (NUM_ITER / 10)) == 0)
40      fprintf(stderr, "done [%d]\n", i);
41  }
42  return 0;
43}
44