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
7 // XFAIL: target={{sparc.*-.*-linux.*}}
12 #include <sys/resource.h>
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
;
21 void LimitStackAndReexec(int argc
, char **argv
) {
23 int res
= getrlimit(RLIMIT_STACK
, &rlim
);
25 if (rlim
.rlim_cur
== RLIM_INFINITY
) {
26 rlim
.rlim_cur
= 256 * 1024;
27 res
= setrlimit(RLIMIT_STACK
, &rlim
);
31 assert(0 && "unreachable");
35 int main(int argc
, char **argv
) {
36 LimitStackAndReexec(argc
, argv
);
38 return *recurse(argc
+ 1, &res
);