Skip to content

Commit 5e9e463

Browse files
committed
[lsan] Test to show lsan dependency on globals
This test from @MaskRay comment on D69428. The patch is looking to break this behavior. If we go with D69428 I hope we will have some workaround for this test or include explicit test update into the patch. Reviewed By: MaskRay Differential Revision: https://reviews.llvm.org/D100906
1 parent eff4f65 commit 5e9e463

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Test that unused globals are included in the root set.
2+
// RUN: %clangxx_lsan -O2 %s -DTEST_LIB -c -o %t.o
3+
// RUN: %clangxx_lsan -O2 %s %t.o -o %t
4+
// RUN: LSAN_BASE="use_stacks=0:use_registers=0"
5+
// RUN: %env_lsan_opts=$LSAN_BASE:"use_globals=0" not %run %t 2>&1 | FileCheck %s --check-prefixes=LEAK
6+
// RUN: %env_lsan_opts=$LSAN_BASE:"use_globals=1" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak
7+
// RUN: %env_lsan_opts="" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak
8+
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <string.h>
12+
13+
#ifdef TEST_LIB
14+
15+
void set(char *a) {
16+
strcpy(a, "hello");
17+
}
18+
19+
#else
20+
21+
static void *g;
22+
23+
void set(char *a);
24+
void foo(void *a) {
25+
// Store from a different function to suppress global localization.
26+
g = a;
27+
}
28+
29+
int main() {
30+
char a[10];
31+
set(a);
32+
char *b = strdup(a);
33+
printf("%p %s\n", b, b);
34+
g = b;
35+
}
36+
37+
#endif
38+
39+
// LEAK: LeakSanitizer: detected memory leaks

0 commit comments

Comments
 (0)