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 6 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 9 10 #include <stdio.h> 11 #include <stdlib.h> 12 #include <string.h> 13 14 #ifdef TEST_LIB 15 16 void set(char *a) { 17 strcpy(a, "hello"); 18 } 19 20 #else 21 22 static void *g; 23 24 void set(char *a); 25 void foo(void *a) { 26 // Store from a different function to suppress global localization. 27 g = a; 28 } 29 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; 36 } 37 38 #endif 39 40 // LEAK: LeakSanitizer: detected memory leaks 41