1 // We can't unwind stack if we're running coroutines on heap-allocated
2 // memory. Make sure we don't report these leaks.
4 // RUN: %clangxx_lsan %s -o %t
5 // RUN: %env_lsan_opts= %run %t 2>&1
6 // RUN: %env_lsan_opts= not %run %t foo 2>&1 | FileCheck %s
7 // Missing 'getcontext' and 'makecontext' on Android.
8 // UNSUPPORTED: target={{(arm|aarch64|loongarch64|powerpc64).*}},android
10 #include "sanitizer_common/sanitizer_ucontext.h"
14 const int kStackSize
= 1 << 20;
18 printf("Child: %p\n", &child_stack
);
19 int *leaked
= new int[666];
22 int main(int argc
, char *argv
[]) {
23 char stack_memory
[kStackSize
+ 1] __attribute__((aligned(16)));
24 char *heap_memory
= new char[kStackSize
+ 1];
25 char *child_stack
= (argc
> 1) ? stack_memory
: heap_memory
;
27 printf("Child stack: %p\n", child_stack
);
28 ucontext_t orig_context
;
29 ucontext_t child_context
;
30 getcontext(&child_context
);
31 child_context
.uc_stack
.ss_sp
= child_stack
;
32 child_context
.uc_stack
.ss_size
= kStackSize
/ 2;
33 child_context
.uc_link
= &orig_context
;
34 makecontext(&child_context
, Child
, 0);
35 if (swapcontext(&orig_context
, &child_context
) < 0) {
36 perror("swapcontext");
44 // CHECK: SUMMARY: {{.*}}Sanitizer: 2664 byte(s) leaked in 1 allocation(s)