[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / lsan / TestCases / recoverable_leak_check.cpp
blobb3750625d78ccfec6b74119ab9cece671d5e91be
1 // Test for on-demand leak checking.
2 // RUN: %clangxx_lsan %s -o %t
3 // RUN: %env_lsan_opts=use_stacks=0:use_registers=0 %run %t foo 2>&1 | FileCheck %s
4 // RUN: %env_lsan_opts=use_stacks=0:use_registers=0 %run %t 2>&1 | FileCheck %s
5 //
6 // UNSUPPORTED: darwin
8 #include <assert.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12 #include <sanitizer/lsan_interface.h>
14 void *p;
16 int main(int argc, char *argv[]) {
17 p = malloc(23);
19 assert(__lsan_do_recoverable_leak_check() == 0);
21 fprintf(stderr, "Test alloc: %p.\n", malloc(1337));
22 // CHECK: Test alloc:
24 assert(__lsan_do_recoverable_leak_check() == 1);
25 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte
27 // Test that we correctly reset chunk tags.
28 p = 0;
29 assert(__lsan_do_recoverable_leak_check() == 1);
30 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1360 byte
32 _exit(0);