[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / lsan / TestCases / do_leak_check_override.cpp
blob840842a2c2a275684d9ff347c4b397d524883a9a
1 // Test for __lsan_do_leak_check(). We test it by making the leak check run
2 // before global destructors, which also tests compatibility with HeapChecker's
3 // "normal" mode (LSan runs in "strict" mode by default).
4 // RUN: %clangxx_lsan %s -o %t
5 // RUN: %env_lsan_opts=use_stacks=0:use_registers=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-strict %s
6 // RUN: %env_lsan_opts=use_stacks=0:use_registers=0 not %run %t foo 2>&1 | FileCheck --check-prefix=CHECK-normal %s
8 // Investigate why LeakyGlobal leak does show
9 // UNSUPPORTED: arm-linux || armhf-linux
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <sanitizer/lsan_interface.h>
15 struct LeakyGlobal {
16 LeakyGlobal() {
17 p = malloc(1337);
19 ~LeakyGlobal() {
20 p = 0;
22 void *p;
25 LeakyGlobal leaky_global;
27 int main(int argc, char *argv[]) {
28 // Register leak check to run before global destructors.
29 if (argc > 1)
30 atexit(&__lsan_do_leak_check);
31 void *p = malloc(666);
32 printf("Test alloc: %p\n", p);
33 printf("Test alloc in leaky global: %p\n", leaky_global.p);
34 return 0;
37 // CHECK-strict: SUMMARY: {{(Leak|Address)}}Sanitizer: 2003 byte(s) leaked in 2 allocation(s)
38 // CHECK-normal: SUMMARY: {{(Leak|Address)}}Sanitizer: 666 byte(s) leaked in 1 allocation(s)