1 // Test that ASan doesn't hang on stack overflow in recovery mode. 2 // 3 // RUN: %clang_asan -O0 -fsanitize-recover=address %s -o %t 4 // RUN: %env_asan_opts=halt_on_error=false not %run %t 2>&1 | FileCheck %s 5 6 // Issue #109771 7 // XFAIL: target={{sparc.*-.*-linux.*}} 8 9 #include <assert.h> 10 #include <unistd.h> 11 #include <sys/mman.h> 12 #include <sys/resource.h> 13 14 static volatile int *recurse(volatile int n, volatile int *p) { 15 // CHECK: {{stack-overflow on address 0x.* \(pc 0x.* bp 0x.* sp 0x.* T.*\)}} 16 if (n >= 0) *recurse(n + 1, p) += n; 17 return p; 18 } 19 20 21 void LimitStackAndReexec(int argc, char **argv) { 22 struct rlimit rlim; 23 int res = getrlimit(RLIMIT_STACK, &rlim); 24 assert(res == 0); 25 if (rlim.rlim_cur == RLIM_INFINITY) { 26 rlim.rlim_cur = 256 * 1024; 27 res = setrlimit(RLIMIT_STACK, &rlim); 28 assert(res == 0); 29 30 execv(argv[0], argv); 31 assert(0 && "unreachable"); 32 } 33 } 34 35 int main(int argc, char **argv) { 36 LimitStackAndReexec(argc, argv); 37 volatile int res; 38 return *recurse(argc + 1, &res); 39 } 40