43 lines · cpp
1// Test that use-after-return works with exceptions.2// RUN: %clangxx_asan -O0 %s -o %t3// RUN: %env_asan_opts=detect_stack_use_after_return=1 %run %t4// RUN: %clangxx_asan -O0 %s -o %t -fsanitize-address-use-after-return=always5// RUN: %run %t6 7#include <stdio.h>8 9volatile char *g;10 11#ifndef FRAME_SIZE12# define FRAME_SIZE 10013#endif14 15#ifndef NUM_ITER16# define NUM_ITER 400017#endif18 19#ifndef DO_THROW20# define DO_THROW 121#endif22 23void Func(int depth) {24 char frame[FRAME_SIZE];25 g = &frame[0];26 if (depth)27 Func(depth - 1);28 else if (DO_THROW)29 throw 1;30}31 32int main(int argc, char **argv) {33 for (int i = 0; i < NUM_ITER; i++) {34 try {35 Func(argc * 100);36 } catch(...) {37 }38 if ((i % (NUM_ITER / 10)) == 0)39 fprintf(stderr, "done [%d]\n", i);40 }41 return 0;42}43