xref: /llvm-project/compiler-rt/test/lsan/TestCases/Linux/leak_check_segv.cpp (revision fd9f7b90109b3fb9a3ac8df5eb4dd966a359c2f4)
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 
10 char data[10 * 1024 * 1024];
11 
main()12 int main() {
13   long pagesize_mask = sysconf(_SC_PAGESIZE) - 1;
14   void *p = malloc(10 * 1024 * 1024);
15   // surprise-surprise!
16   mprotect((void *)(((unsigned long)p + pagesize_mask) & ~pagesize_mask),
17            16 * 1024, PROT_NONE);
18   mprotect((void *)(((unsigned long)data + pagesize_mask) & ~pagesize_mask),
19            16 * 1024, PROT_NONE);
20   __lsan_do_leak_check();
21   fprintf(stderr, "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