Browse Source

[llvm-cov] Demangle symbols in function summaries (fixes PR31394)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294136 91177308-0d34-0410-b5e6-96231b3b80d8
Vedant Kumar 8 years ago
parent
commit
b766e93f51

+ 3 - 0
test/tools/llvm-cov/demangle.test

@@ -4,5 +4,8 @@ RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %S
 RUN: llvm-profdata merge %S/Inputs/hideUnexecutedSubviews.proftext -o %t.profdata
 RUN: llvm-profdata merge %S/Inputs/hideUnexecutedSubviews.proftext -o %t.profdata
 RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %t.profdata -Xdemangler sed -Xdemangler 's/_/X/g' -filename-equivalence %S/showTemplateInstantiations.cpp | FileCheck %s
 RUN: llvm-cov show %S/Inputs/templateInstantiations.covmapping -instr-profile %t.profdata -Xdemangler sed -Xdemangler 's/_/X/g' -filename-equivalence %S/showTemplateInstantiations.cpp | FileCheck %s
 
 
+// Check that we demangle names when printing out function summaries.
+RUN: llvm-cov report %S/Inputs/templateInstantiations.covmapping -instr-profile %S/Inputs/templateInstantiations.profdata -Xdemangler sed -Xdemangler 's/_/X/g' -filename-equivalence %S/showTemplateInstantiations.cpp | FileCheck %s
+
 CHECK-DAG: XZ4funcIbEiTX
 CHECK-DAG: XZ4funcIbEiTX
 CHECK-DAG: XZ4funcIiEiTX
 CHECK-DAG: XZ4funcIiEiTX

+ 1 - 1
tools/llvm-cov/CodeCoverage.cpp

@@ -823,7 +823,7 @@ int CodeCoverageTool::report(int argc, const char **argv,
   if (SourceFiles.empty())
   if (SourceFiles.empty())
     Report.renderFileReports(llvm::outs());
     Report.renderFileReports(llvm::outs());
   else
   else
-    Report.renderFunctionReports(SourceFiles, llvm::outs());
+    Report.renderFunctionReports(SourceFiles, DC, llvm::outs());
   return 0;
   return 0;
 }
 }
 
 

+ 7 - 4
tools/llvm-cov/CoverageReport.cpp

@@ -200,12 +200,14 @@ void CoverageReport::render(const FileCoverageSummary &File,
 }
 }
 
 
 void CoverageReport::render(const FunctionCoverageSummary &Function,
 void CoverageReport::render(const FunctionCoverageSummary &Function,
+                            const DemangleCache &DC,
                             raw_ostream &OS) const {
                             raw_ostream &OS) const {
   auto FuncCoverageColor =
   auto FuncCoverageColor =
       determineCoveragePercentageColor(Function.RegionCoverage);
       determineCoveragePercentageColor(Function.RegionCoverage);
   auto LineCoverageColor =
   auto LineCoverageColor =
       determineCoveragePercentageColor(Function.LineCoverage);
       determineCoveragePercentageColor(Function.LineCoverage);
-  OS << column(Function.Name, FunctionReportColumns[0], Column::RightTrim)
+  OS << column(DC.demangle(Function.Name), FunctionReportColumns[0],
+               Column::RightTrim)
      << format("%*u", FunctionReportColumns[1],
      << format("%*u", FunctionReportColumns[1],
                (unsigned)Function.RegionCoverage.NumRegions);
                (unsigned)Function.RegionCoverage.NumRegions);
   Options.colored_ostream(OS, FuncCoverageColor)
   Options.colored_ostream(OS, FuncCoverageColor)
@@ -230,6 +232,7 @@ void CoverageReport::render(const FunctionCoverageSummary &Function,
 }
 }
 
 
 void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
 void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
+                                           const DemangleCache &DC,
                                            raw_ostream &OS) {
                                            raw_ostream &OS) {
   bool isFirst = true;
   bool isFirst = true;
   for (StringRef Filename : Files) {
   for (StringRef Filename : Files) {
@@ -242,7 +245,7 @@ void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
 
 
     std::vector<StringRef> Funcnames;
     std::vector<StringRef> Funcnames;
     for (const auto &F : Functions)
     for (const auto &F : Functions)
-      Funcnames.emplace_back(F.Name);
+      Funcnames.emplace_back(DC.demangle(F.Name));
     adjustColumnWidths({}, Funcnames);
     adjustColumnWidths({}, Funcnames);
 
 
     OS << "File '" << Filename << "':\n";
     OS << "File '" << Filename << "':\n";
@@ -262,12 +265,12 @@ void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
       ++Totals.ExecutionCount;
       ++Totals.ExecutionCount;
       Totals.RegionCoverage += Function.RegionCoverage;
       Totals.RegionCoverage += Function.RegionCoverage;
       Totals.LineCoverage += Function.LineCoverage;
       Totals.LineCoverage += Function.LineCoverage;
-      render(Function, OS);
+      render(Function, DC, OS);
     }
     }
     if (Totals.ExecutionCount) {
     if (Totals.ExecutionCount) {
       renderDivider(FunctionReportColumns, OS);
       renderDivider(FunctionReportColumns, OS);
       OS << "\n";
       OS << "\n";
-      render(Totals, OS);
+      render(Totals, DC, OS);
     }
     }
   }
   }
 }
 }

+ 4 - 2
tools/llvm-cov/CoverageReport.h

@@ -25,14 +25,16 @@ class CoverageReport {
   const coverage::CoverageMapping &Coverage;
   const coverage::CoverageMapping &Coverage;
 
 
   void render(const FileCoverageSummary &File, raw_ostream &OS) const;
   void render(const FileCoverageSummary &File, raw_ostream &OS) const;
-  void render(const FunctionCoverageSummary &Function, raw_ostream &OS) const;
+  void render(const FunctionCoverageSummary &Function, const DemangleCache &DC,
+              raw_ostream &OS) const;
 
 
 public:
 public:
   CoverageReport(const CoverageViewOptions &Options,
   CoverageReport(const CoverageViewOptions &Options,
                  const coverage::CoverageMapping &Coverage)
                  const coverage::CoverageMapping &Coverage)
       : Options(Options), Coverage(Coverage) {}
       : Options(Options), Coverage(Coverage) {}
 
 
-  void renderFunctionReports(ArrayRef<std::string> Files, raw_ostream &OS);
+  void renderFunctionReports(ArrayRef<std::string> Files,
+                             const DemangleCache &DC, raw_ostream &OS);
 
 
   /// Prepare file reports for the files specified in \p Files.
   /// Prepare file reports for the files specified in \p Files.
   static std::vector<FileCoverageSummary>
   static std::vector<FileCoverageSummary>