diff --git a/llvm/tools/llvm-dwarfdump/Statistics.cpp b/llvm/tools/llvm-dwarfdump/Statistics.cpp --- a/llvm/tools/llvm-dwarfdump/Statistics.cpp +++ b/llvm/tools/llvm-dwarfdump/Statistics.cpp @@ -206,7 +206,7 @@ uint64_t BytesEntryValuesCovered = 0; auto &FnStats = FnStatMap[FnPrefix]; bool IsParam = Die.getTag() == dwarf::DW_TAG_formal_parameter; - bool IsLocalVar = Die.getTag() == dwarf::DW_TAG_variable; + bool IsVariable = Die.getTag() == dwarf::DW_TAG_variable; if (Die.getTag() == dwarf::DW_TAG_call_site || Die.getTag() == dwarf::DW_TAG_GNU_call_site) { @@ -220,11 +220,15 @@ return; } - if (!IsParam && !IsLocalVar && Die.getTag() != dwarf::DW_TAG_member) { + if (!IsParam && !IsVariable && Die.getTag() != dwarf::DW_TAG_member) { // Not a variable or constant member. return; } + // Ignore declarations of global variables. + if (IsVariable && Die.find(dwarf::DW_AT_declaration)) + return; + if (Die.findRecursively(dwarf::DW_AT_decl_file) && Die.findRecursively(dwarf::DW_AT_decl_line)) HasSrcLoc = true; @@ -286,17 +290,17 @@ LocStats.NumVarParam++; if (IsParam) LocStats.NumParam++; - else if (IsLocalVar) + else if (IsVariable) LocStats.NumVar++; collectLocStats(BytesCovered, BytesInScope, LocStats.VarParamLocStats, LocStats.ParamLocStats, LocStats.VarLocStats, IsParam, - IsLocalVar); + IsVariable); // Non debug entry values coverage statistics. collectLocStats(BytesCovered - BytesEntryValuesCovered, BytesInScope, LocStats.VarParamNonEntryValLocStats, LocStats.ParamNonEntryValLocStats, - LocStats.VarNonEntryValLocStats, IsParam, IsLocalVar); + LocStats.VarNonEntryValLocStats, IsParam, IsVariable); } // Collect PC range coverage data. @@ -318,7 +322,7 @@ std::min(BytesInScope, BytesCovered); GlobalStats.ParamScopeBytes += BytesInScope; GlobalStats.ParamScopeEntryValueBytesCovered += BytesEntryValuesCovered; - } else if (IsLocalVar) { + } else if (IsVariable) { GlobalStats.VarScopeBytesCovered += std::min(BytesInScope, BytesCovered); GlobalStats.VarScopeBytes += BytesInScope; GlobalStats.VarScopeEntryValueBytesCovered += BytesEntryValuesCovered; @@ -338,7 +342,7 @@ FnStats.NumParamSourceLocations++; if (HasLoc) FnStats.NumParamLocations++; - } else if (IsLocalVar) { + } else if (IsVariable) { FnStats.NumVars++; if (HasType) FnStats.NumVarTypes++;