1// Test that SIGSEGV during leak checking does not crash the process.
2// RUN: %clangxx_lsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
3// UNSUPPORTED: ppc
4#include <sanitizer/lsan_interface.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <sys/mman.h>
8#include <unistd.h>
9
10char data[10 * 1024 * 1024];
11
12int main() {
13 long pagesize_mask = sysconf(_SC_PAGESIZE) - 1;
14 void *p = malloc(size: 10 * 1024 * 1024);
15 // surprise-surprise!
16 mprotect(addr: (void *)(((unsigned long)p + pagesize_mask) & ~pagesize_mask),
17 len: 16 * 1024, PROT_NONE);
18 mprotect(addr: (void *)(((unsigned long)data + pagesize_mask) & ~pagesize_mask),
19 len: 16 * 1024, PROT_NONE);
20 __lsan_do_leak_check();
21 fprintf(stderr, format: "DONE\n");
22}
23
24// CHECK: Tracer caught signal 11
25// CHECK: LeakSanitizer has encountered a fatal error
26// CHECK: HINT: For debugging, try setting {{.*}} LSAN_OPTIONS
27// CHECK-NOT: DONE
28

source code of compiler-rt/test/lsan/TestCases/Linux/leak_check_segv.cpp