llvm-cov: Fix an issue with showing regions but not counts

In r217746, though it was supposed to be NFC, I broke llvm-cov's
handling of showing regions without showing counts. This should've
shown up in the existing tests, except they were checking debug output
that was displayed regardless of what was actually output. I've moved
the relevant debug output to a more appropriate place so that the
tests catch this kind of thing.

llvm-svn: 217835
diff --git a/llvm/tools/llvm-cov/SourceCoverageView.cpp b/llvm/tools/llvm-cov/SourceCoverageView.cpp
index 87a68e0..7c6d9a5 100644
--- a/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/llvm/tools/llvm-cov/SourceCoverageView.cpp
@@ -118,6 +118,13 @@
     Buffer.clear();
   }
   OS << "\n";
+
+  if (Options.Debug) {
+    for (const auto &Region : Regions) {
+      errs() << "Marker at " << Region.Line << ":" << Region.Column << " = "
+             << Region.ExecutionCount << "\n";
+    }
+  }
 }
 
 /// \brief Insert a new highlighting range into the line's highlighting ranges
@@ -316,17 +323,24 @@
   }
 }
 
-void
-SourceCoverageView::createLineCoverageInfo(SourceCoverageDataManager &Data) {
+void SourceCoverageView::setUpVisibleRange(SourceCoverageDataManager &Data) {
   auto CountedRegions = Data.getSourceRegions();
   if (!CountedRegions.size())
     return;
 
-  LineOffset = CountedRegions.front().LineStart;
-  LineStats.resize(CountedRegions.front().LineEnd - LineOffset + 1);
+  unsigned Start = CountedRegions.front().LineStart, End = 0;
   for (const auto &CR : CountedRegions) {
-    if (CR.LineEnd > LineStats.size())
-      LineStats.resize(CR.LineEnd - LineOffset + 1);
+    Start = std::min(Start, CR.LineStart);
+    End = std::max(End, CR.LineEnd);
+  }
+  LineOffset = Start;
+  LineStats.resize(End - Start + 1);
+}
+
+void
+SourceCoverageView::createLineCoverageInfo(SourceCoverageDataManager &Data) {
+  auto CountedRegions = Data.getSourceRegions();
+  for (const auto &CR : CountedRegions) {
     if (CR.Kind == coverage::CounterMappingRegion::SkippedRegion) {
       // Reset the line stats for skipped regions.
       for (unsigned Line = CR.LineStart; Line <= CR.LineEnd;
@@ -395,16 +409,10 @@
     if (CR.Kind != coverage::CounterMappingRegion::SkippedRegion)
       Markers.push_back(
           RegionMarker(CR.LineStart, CR.ColumnStart, CR.ExecutionCount));
-
-  if (Options.Debug) {
-    for (const auto &Marker : Markers) {
-      outs() << "Marker at " << Marker.Line << ":" << Marker.Column << " = "
-             << Marker.ExecutionCount << "\n";
-    }
-  }
 }
 
 void SourceCoverageView::load(SourceCoverageDataManager &Data) {
+  setUpVisibleRange(Data);
   if (Options.ShowLineStats)
     createLineCoverageInfo(Data);
   if (Options.Colors)