]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/lsan/TestCases/recoverable_leak_check.cc
Vendor import of compiler-rt trunk r351319 (just before the release_80
[FreeBSD/FreeBSD.git] / test / lsan / TestCases / recoverable_leak_check.cc
1 // Test for on-demand leak checking.
2 // RUN: LSAN_BASE="use_stacks=0:use_registers=0"
3 // RUN: %clangxx_lsan %s -o %t
4 // RUN: %env_lsan_opts=$LSAN_BASE %run %t foo 2>&1 | FileCheck %s
5 // RUN: %env_lsan_opts=$LSAN_BASE %run %t 2>&1 | FileCheck %s
6 //
7 // UNSUPPORTED: darwin
8
9 #include <assert.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <unistd.h>
13 #include <sanitizer/lsan_interface.h>
14
15 void *p;
16
17 int main(int argc, char *argv[]) {
18   p = malloc(23);
19
20   assert(__lsan_do_recoverable_leak_check() == 0);
21
22   fprintf(stderr, "Test alloc: %p.\n", malloc(1337));
23 // CHECK: Test alloc:
24
25   assert(__lsan_do_recoverable_leak_check() == 1);
26 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte
27
28   // Test that we correctly reset chunk tags.
29   p = 0;
30   assert(__lsan_do_recoverable_leak_check() == 1);
31 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1360 byte
32
33   _exit(0);
34 }