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=1" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak 6 // RUN: %env_lsan_opts="" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak 7 8 // FIXME: This check is not very important and fails on arm7. 9 // %env_lsan_opts=$LSAN_BASE:"use_globals=0" not %run %t 2>&1 | FileCheck %s --check-prefixes=LEAK 10 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include <string.h> 14 15 #ifdef TEST_LIB 16 17 void set(char *a) { 18 strcpy(a, "hello"); // NOLINT 19 } 20 21 #else 22 23 static void *g; 24 25 void set(char *a); 26 void foo(void *a) { 27 // Store from a different function to suppress global localization. 28 g = a; 29 } 30 31 int main() { 32 char a[10]; 33 set(a); 34 char *b = strdup(a); 35 printf("%p %s\n", b, b); 36 g = b; 37 } 38 39 #endif 40 41 // LEAK: LeakSanitizer: detected memory leaks 42