xref: /llvm-project/compiler-rt/test/lsan/TestCases/use_globals_initialized.cpp (revision eb3be66028eac88098e0186cff80e0421949dd69)
197ccf6b8SFangrui Song // Test that initialized globals are included in the root set.
297ccf6b8SFangrui Song // RUN: %clangxx_lsan %s -o %t
3d08e5d4cSClemens Wasser // RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_globals=0" not %run %t 2>&1 | FileCheck %s
4d08e5d4cSClemens Wasser // RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0:use_globals=1" %run %t 2>&1
597ccf6b8SFangrui Song // RUN: %env_lsan_opts="" %run %t 2>&1
697ccf6b8SFangrui Song 
797ccf6b8SFangrui Song #include <stdio.h>
897ccf6b8SFangrui Song #include <stdlib.h>
997ccf6b8SFangrui Song #include "sanitizer_common/print_address.h"
1097ccf6b8SFangrui Song 
1197ccf6b8SFangrui Song void *data_var = (void *)1;
1297ccf6b8SFangrui Song 
main()1397ccf6b8SFangrui Song int main() {
1497ccf6b8SFangrui Song   data_var = malloc(1337);
1597ccf6b8SFangrui Song   print_address("Test alloc: ", 1, data_var);
1697ccf6b8SFangrui Song   return 0;
1797ccf6b8SFangrui Song }
1897ccf6b8SFangrui Song // CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
1997ccf6b8SFangrui Song // CHECK: LeakSanitizer: detected memory leaks
2097ccf6b8SFangrui Song // CHECK: [[ADDR]] (1337 bytes)
21*eb3be660SKirill Stoimenov // CHECK: SUMMARY: {{.*}}Sanitizer:
22