[RISCV][NFC] Remove Redundant Inline Asm Logic (#124202)
[llvm-project.git] / compiler-rt / test / asan / TestCases / Linux / stack-overflow-recovery-mode.cpp
blob461702a0ea7a9653e5104dd6e1533521ca8ef56f
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
6 // Issue #109771
7 // XFAIL: target={{sparc.*-.*-linux.*}}
9 #include <assert.h>
10 #include <unistd.h>
11 #include <sys/mman.h>
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;
17 return p;
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);
30 execv(argv[0], argv);
31 assert(0 && "unreachable");
35 int main(int argc, char **argv) {
36 LimitStackAndReexec(argc, argv);
37 volatile int res;
38 return *recurse(argc + 1, &res);