1 // Test that ASan doesn't hang on stack overflow in recovery mode.
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
9 #include <sys/resource.h>
11 static volatile int *recurse(volatile int n
, volatile int *p
) {
12 // CHECK: {{stack-overflow on address 0x.* \(pc 0x.* bp 0x.* sp 0x.* T.*\)}}
13 if (n
>= 0) *recurse(n
+ 1, p
) += n
;
18 void LimitStackAndReexec(int argc
, char **argv
) {
20 int res
= getrlimit(RLIMIT_STACK
, &rlim
);
22 if (rlim
.rlim_cur
== RLIM_INFINITY
) {
23 rlim
.rlim_cur
= 256 * 1024;
24 res
= setrlimit(RLIMIT_STACK
, &rlim
);
28 assert(0 && "unreachable");
32 int main(int argc
, char **argv
) {
33 LimitStackAndReexec(argc
, argv
);
35 return *recurse(argc
+ 1, &res
);