]> git.proxmox.com Git - rustc.git/blob - src/compiler-rt/test/asan/TestCases/uar_and_exceptions.cc
New upstream version 1.12.0+dfsg1
[rustc.git] / src / compiler-rt / test / asan / TestCases / uar_and_exceptions.cc
1 // Test that use-after-return works with exceptions.
2 // RUN: %clangxx_asan -O0 %s -o %t
3 // RUN: %env_asan_opts=detect_stack_use_after_return=1 %run %t
4
5 #include <stdio.h>
6
7 volatile char *g;
8
9 #ifndef FRAME_SIZE
10 # define FRAME_SIZE 100
11 #endif
12
13 #ifndef NUM_ITER
14 # define NUM_ITER 4000
15 #endif
16
17 #ifndef DO_THROW
18 # define DO_THROW 1
19 #endif
20
21 void Func(int depth) {
22 char frame[FRAME_SIZE];
23 g = &frame[0];
24 if (depth)
25 Func(depth - 1);
26 else if (DO_THROW)
27 throw 1;
28 }
29
30 int main(int argc, char **argv) {
31 for (int i = 0; i < NUM_ITER; i++) {
32 try {
33 Func(argc * 100);
34 } catch(...) {
35 }
36 if ((i % (NUM_ITER / 10)) == 0)
37 fprintf(stderr, "done [%d]\n", i);
38 }
39 return 0;
40 }