Index: llvm/test/tools/llvm-dwarfdump/X86/inlined_variables_with_zero_cov.test =================================================================== --- /dev/null +++ llvm/test/tools/llvm-dwarfdump/X86/inlined_variables_with_zero_cov.test @@ -0,0 +1,32 @@ +## This checks the number of inlined variables with 0% location +## coverage in split dwarf cases. +## $ cat test1.cpp +## __attribute__((optnone)) static void x() { +## } +## __attribute__((always_inline)) static void y() { +## int var; +## x(); +## } +## void f1() { +## y(); +## } +## +## $ cat test2.cpp +## __attribute__((optnone)) static void x() { +## } +## __attribute__((always_inline)) static void y() { +## int var; +## x(); +## } +## void f1(); +## int main() { +## f1(); +## y(); +## } +## $ clang++ -O1 -g -gsplit-dwarf test2.cpp test1.cpp -o split-dwarf-test +## +RUN: llvm-dwarfdump --statistics %S/Inputs/split-dwarf-test | FileCheck %s +CHECK: "#variables processed by location statistics": 2 +CHECK: "#variables with 0% of parent scope covered by DW_AT_location": 2 +CHECK: "#local vars processed by location statistics": 2 +CHECK: "#local vars with 0% of parent scope covered by DW_AT_location": 2 Index: llvm/tools/llvm-dwarfdump/Statistics.cpp =================================================================== --- llvm/tools/llvm-dwarfdump/Statistics.cpp +++ llvm/tools/llvm-dwarfdump/Statistics.cpp @@ -720,11 +720,19 @@ StringRef FormatName = Obj.getFileFormatName(); GlobalStats GlobalStats; LocationStats LocStats; - InlinedVarsTyMap GlobalInlinedFnInfo; - InlinedFnInstacesTy InlinedFnsToBeProcessed; StringMap Statistics; for (const auto &CU : static_cast(&DICtx)->compile_units()) { if (DWARFDie CUDie = CU->getNonSkeletonUnitDIE(false)) { + // These variables are being reset for each CU, since there could be + // a situation where we have two subprogram DIEs with the same offsets + // in two diferent CUs, and we can end up using wrong variables info + // when trying to resolve abstract_orign attribute. + // TODO: Handle LTO cases where the abstract origin of + // the function is in a different CU than the one it's + // referenced from or inlined into. + InlinedVarsTyMap GlobalInlinedFnInfo; + InlinedFnInstacesTy InlinedFnsToBeProcessed; + collectStatsRecursive(CUDie, "/", "g", 0, 0, Statistics, GlobalStats, LocStats, GlobalInlinedFnInfo, InlinedFnsToBeProcessed);