[llvm] r317762 - [llvm-cov] Don't render empty region marker lines

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 18:33:44 PST 2017


Author: vedantk
Date: Wed Nov  8 18:33:44 2017
New Revision: 317762

URL: http://llvm.org/viewvc/llvm-project?rev=317762&view=rev
Log:
[llvm-cov] Don't render empty region marker lines

This fixes an issue where llvm-cov prints an empty line, thinking it
needs to display region markers, when it actually doesn't.

Modified:
    llvm/trunk/test/tools/llvm-cov/deferred-region.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageView.h
    llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp

Modified: llvm/trunk/test/tools/llvm-cov/deferred-region.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/deferred-region.cpp?rev=317762&r1=317761&r2=317762&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/deferred-region.cpp (original)
+++ llvm/trunk/test/tools/llvm-cov/deferred-region.cpp Wed Nov  8 18:33:44 2017
@@ -2,7 +2,7 @@
 
 void foo(int x) {
   if (x == 0) { // CHECK: [[@LINE]]|{{ +}}2|
-    return; // CHECK: [[@LINE]]|{{ +}}1|
+    return; // CHECK-NEXT: [[@LINE]]|{{ +}}1|
   }
 
 } // CHECK: [[@LINE]]|{{ +}}1|

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp?rev=317762&r1=317761&r2=317762&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.cpp Wed Nov  8 18:33:44 2017
@@ -111,16 +111,19 @@ std::string SourceCoverageView::formatCo
 }
 
 bool SourceCoverageView::shouldRenderRegionMarkers(
-    CoverageSegmentArray Segments) const {
+    const LineCoverageStats &LCS) const {
   if (!getOptions().ShowRegionMarkers)
     return false;
 
-  // Render the region markers if there's more than one count to show.
-  unsigned RegionCount = 0;
-  for (const auto *S : Segments)
-    if (S->IsRegionEntry)
-      if (++RegionCount > 1)
-        return true;
+  CoverageSegmentArray Segments = LCS.getLineSegments();
+  if (Segments.empty())
+    return false;
+  for (unsigned I = 0, E = Segments.size() - 1; I < E; ++I) {
+    const auto *CurSeg = Segments[I];
+    if (!CurSeg->IsRegionEntry || CurSeg->Count == LCS.getExecutionCount())
+      continue;
+    return true;
+  }
   return false;
 }
 
@@ -220,7 +223,7 @@ void SourceCoverageView::print(raw_ostre
     renderLine(OS, {*LI, LI.line_number()}, *LCI, ExpansionColumn, ViewDepth);
 
     // Show the region markers.
-    if (shouldRenderRegionMarkers(LCI->getLineSegments()))
+    if (shouldRenderRegionMarkers(*LCI))
       renderRegionMarkers(OS, *LCI, ViewDepth);
 
     // Show the expansions and instantiations for this line.

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageView.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageView.h?rev=317762&r1=317761&r2=317762&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageView.h (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageView.h Wed Nov  8 18:33:44 2017
@@ -225,7 +225,7 @@ protected:
   static std::string formatCount(uint64_t N);
 
   /// \brief Check if region marker output is expected for a line.
-  bool shouldRenderRegionMarkers(CoverageSegmentArray Segments) const;
+  bool shouldRenderRegionMarkers(const LineCoverageStats &LCS) const;
 
   /// \brief Check if there are any sub-views attached to this view.
   bool hasSubViews() const;

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp?rev=317762&r1=317761&r2=317762&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp Wed Nov  8 18:33:44 2017
@@ -556,7 +556,7 @@ void SourceCoverageViewHTML::renderLine(
   // 4. Snippets[1:N+1] correspond to \p Segments[0:N]: use these to generate
   //    sub-line region count tooltips if needed.
 
-  if (shouldRenderRegionMarkers(Segments)) {
+  if (shouldRenderRegionMarkers(LCS)) {
     // Just consider the segments which start *and* end on this line.
     for (unsigned I = 0, E = Segments.size() - 1; I < E; ++I) {
       const auto *CurSeg = Segments[I];




More information about the llvm-commits mailing list