Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // Test that use-after-return works with exceptions. |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 2 | // export ASAN_OPTIONS=$ASAN_OPTIONS:detect_stack_use_after_return=1 |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 3 | // RUN: %clangxx_asan -O0 %s -o %t && %run %t |
| 4 | |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 5 | // Clang doesn't support exceptions on Windows yet. |
| 6 | // XFAIL: win32 |
| 7 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 8 | #include <stdio.h> |
| 9 | |
| 10 | volatile 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 | |
| 24 | void 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 | |
| 33 | int 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 | } |