[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / lsan / TestCases / use_globals_unused.cpp
blob3d6d140d609115dad88530bcac02278673cb8c82
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: %env_lsan_opts="use_stacks=0:use_registers=0:use_globals=1" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak
5 // RUN: %env_lsan_opts="" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak
7 // FIXME: This check is not very important and fails on arm7.
8 // %env_lsan_opts="use_stacks=0:use_registers=0:use_globals=0" not %run %t 2>&1 | FileCheck %s --check-prefixes=LEAK
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
14 #ifdef TEST_LIB
16 void set(char *a) {
17 strcpy(a, "hello");
20 #else
22 static void *g;
24 void set(char *a);
25 void foo(void *a) {
26 // Store from a different function to suppress global localization.
27 g = a;
30 int main() {
31 char a[10];
32 set(a);
33 char *b = strdup(a);
34 printf("%p %s\n", b, b);
35 g = b;
38 #endif
40 // LEAK: LeakSanitizer: detected memory leaks