[llvm-cov] Don't render empty region marker lines
authorVedant Kumar <vsk@apple.com>
Thu, 9 Nov 2017 02:33:44 +0000 (02:33 +0000)
committerVedant Kumar <vsk@apple.com>
Thu, 9 Nov 2017 02:33:44 +0000 (02:33 +0000)
This fixes an issue where llvm-cov prints an empty line, thinking it
needs to display region markers, when it actually doesn't.

llvm-svn: 317762

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

index a3f6b01..ae0b315 100644 (file)
@@ -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|
index 31ab132..8c39dab 100644 (file)
@@ -111,16 +111,19 @@ std::string SourceCoverageView::formatCount(uint64_t N) {
 }
 
 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_ostream &OS, bool WholeFile,
     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.
index 35dea59..7f58ea5 100644 (file)
@@ -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;
index 7e9fc23..3140651 100644 (file)
@@ -556,7 +556,7 @@ void SourceCoverageViewHTML::renderLine(raw_ostream &OS, LineRef L,
   // 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];