1 // RUN: LSAN_BASE="use_registers=0:use_stacks=0"
2 // RUN: %clangxx_lsan %s -o %t
3 
4 // RUN: rm -f %t.supp
5 // RUN: touch %t.supp
6 // RUN: %push_to_device %t.supp %device_rundir/%t.supp
7 // RUN: %env_lsan_opts="$LSAN_BASE:suppressions='%device_rundir/%t.supp'" not %run %t 2>&1 | FileCheck %s --check-prefix=NOSUPP
8 
9 // RUN: echo "leak:*LSanTestLeakingFunc*" > %t.supp
10 // RUN: %push_to_device  %t.supp %device_rundir/%t.supp
11 // RUN: %env_lsan_opts="$LSAN_BASE:suppressions='%device_rundir/%t.supp'" not %run %t 2>&1 | FileCheck %s
12 //
13 // RUN: echo "leak:%t" > %t.supp
14 // RUN: %push_to_device  %t.supp %device_rundir/%t.supp
15 // RUN: %env_lsan_opts="$LSAN_BASE:suppressions='%device_rundir/%t.supp':symbolize=false" %run %t
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 
20 void *LSanTestLeakingFunc() {
21   void *p = malloc(666);
22   fprintf(stderr, "Test alloc: %p.\n", p);
23   return p;
24 }
25 
26 void LSanTestUnsuppressedLeakingFunc() {
27   void **p = (void **)LSanTestLeakingFunc();
28   *p = malloc(777);
29   fprintf(stderr, "Test alloc: %p.\n", *p);
30 }
31 
32 int main() {
33   LSanTestUnsuppressedLeakingFunc();
34   void *q = malloc(1337);
35   fprintf(stderr, "Test alloc: %p.\n", q);
36   return 0;
37 }
38 // CHECK: Suppressions used:
39 // CHECK: 1 666 *LSanTestLeakingFunc*
40 // CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 1337 byte(s) leaked in 1 allocation(s)
41 
42 // NOSUPP: SUMMARY: {{(Leak|Address)}}Sanitizer: 2780 byte(s) leaked in 3 allocation(s).
43