brintos

brintos / llvm-project-archived public Read only

0
0
Text · 952 B · 3d6d140 Raw
41 lines · cpp
1// Test that unused globals are included in the root set.2// RUN: %clangxx_lsan -O2 %s -DTEST_LIB -c -o %t.o3// RUN: %clangxx_lsan -O2 %s %t.o -o %t4// RUN: %env_lsan_opts="use_stacks=0:use_registers=0:use_globals=1" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak5// RUN: %env_lsan_opts="" %run %t 2>&1 | FileCheck %s --implicit-check-not=leak6 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=LEAK9 10#include <stdio.h>11#include <stdlib.h>12#include <string.h>13 14#ifdef TEST_LIB15 16void set(char *a) {17  strcpy(a, "hello");18}19 20#else21 22static void *g;23 24void set(char *a);25void foo(void *a) {26  // Store from a different function to suppress global localization.27  g = a;28}29 30int 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#endif39 40// LEAK: LeakSanitizer: detected memory leaks41