blob: bdeca434e6c2908762be3d4e08ca9b385374867a [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// Test that use-after-return works with exceptions.
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07002// export ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1
Stephen Hines2d1fdb22014-05-28 23:58:16 -07003// RUN: %clangxx_asan -O0 %s -o %t && %run %t
4
Stephen Hines6a211c52014-07-21 00:49:56 -07005// Clang doesn't support exceptions on Windows yet.
6// XFAIL: win32
7
Stephen Hines2d1fdb22014-05-28 23:58:16 -07008#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}