[llvm] r280981 - [llvm-cov] Fix issues with segment highlighting in the html view

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 8 12:18:23 PDT 2016


Author: vedantk
Date: Thu Sep  8 14:18:23 2016
New Revision: 280981

URL: http://llvm.org/viewvc/llvm-project?rev=280981&view=rev
Log:
[llvm-cov] Fix issues with segment highlighting in the html view

The text and html coverage views take different approaches to emitting
highlighted regions. That's because this problem is easier in the text
view: there's no need to worry about escaping text or adding tooltip
content to a highlighted snippet.

Unfortunately, the html view didn't get region highlighting quite right.

This patch fixes the situation, bringing parity between the two views.

Modified:
    llvm/trunk/test/tools/llvm-cov/showHighlightedRanges.cpp
    llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp
    llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp

Modified: llvm/trunk/test/tools/llvm-cov/showHighlightedRanges.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/showHighlightedRanges.cpp?rev=280981&r1=280980&r2=280981&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/showHighlightedRanges.cpp (original)
+++ llvm/trunk/test/tools/llvm-cov/showHighlightedRanges.cpp Thu Sep  8 14:18:23 2016
@@ -1,38 +1,38 @@
 // RUN: llvm-cov show %S/Inputs/highlightedRanges.covmapping -instr-profile %S/Inputs/highlightedRanges.profdata -dump -filename-equivalence %s 2>&1 | FileCheck %s -check-prefixes=TEXT,SHARED
 
 void func() {
-  return;                        // TEXT: Highlighted line [[@LINE+1]], 3 -> ?
-  int i = 0;                     // HTML: Highlighted line [[@LINE]], 1 ->
+  return;
+  int i = 0;                     // SHARED: Highlighted line [[@LINE]], 3 ->
 }                                // SHARED: Highlighted line [[@LINE]], 1 -> 2
 
 void func2(int x) {
   if(x > 5) {
     while(x >= 9) {
       return;
-      --x;                       // TEXT: Highlighted line [[@LINE]], 7 -> ?
+      --x;                       // SHARED: Highlighted line [[@LINE]], 7 ->
     }                            // SHARED: Highlighted line [[@LINE]], 1 -> 6
-    int i = 0;                   // TEXT: Highlighted line [[@LINE]], 5 -> ?
+    int i = 0;                   // SHARED: Highlighted line [[@LINE]], 5 ->
   }                              // SHARED: Highlighted line [[@LINE]], 1 -> 4
 }
 
 void test() {
   int x = 0;
 
-  if (x) {                       // TEXT: Highlighted line [[@LINE]], 10 -> ?
-    x = 0;                       // SHARED: Highlighted line [[@LINE]], 1 -> ?
-  } else {                       // TEXT: Highlighted line [[@LINE]], 1 -> 4
+  if (x) {                       // SHARED: Highlighted line [[@LINE]], 10 ->
+    x = 0;                       // SHARED: Highlighted line [[@LINE]], 1 ->
+  } else {                       // SHARED: Highlighted line [[@LINE]], 1 -> 4
     x = 1;
   }
 
-                                  // TEXT: Highlighted line [[@LINE+1]], 26 -> 29
-  for (int i = 0; i < 0; ++i) {   // TEXT: Highlighted line [[@LINE]], 31 -> ?
-    x = 1;                        // TEXT: Highlighted line [[@LINE]], 1 -> ?
+                                  // SHARED: Highlighted line [[@LINE+1]], 26 ->
+  for (int i = 0; i < 0; ++i) {   // SHARED: Highlighted line [[@LINE]], 31 ->
+    x = 1;                        // SHARED: Highlighted line [[@LINE]], 1 ->
   }                               // SHARED: Highlighted line [[@LINE]], 1 -> 4
 
   x = x < 10 ? x +
                1
-             : x - 1;             // TEXT: Highlighted line [[@LINE]], 16 -> 21
-  x = x > 10 ? x +                // TEXT: Highlighted line [[@LINE]], 16 -> ?
+             : x - 1;             // SHARED: Highlighted line [[@LINE]], 16 -> 21
+  x = x > 10 ? x +                // SHARED: Highlighted line [[@LINE]], 16 ->
                1                  // SHARED: Highlighted line [[@LINE]], 1 -> 17
              : x - 1;
 }

Modified: llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp?rev=280981&r1=280980&r2=280981&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp (original)
+++ llvm/trunk/test/tools/llvm-cov/showLineExecutionCounts.cpp Thu Sep  8 14:18:23 2016
@@ -50,7 +50,7 @@ int main() {
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>int main() {
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>  int x = 0
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
-// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre><span class='red'>  if (x) {
+// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre>  if (x) {
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre>
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre><span class='red'>  }</span>
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>    x = 1;
@@ -62,7 +62,7 @@ int main() {
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>  x = x < 10
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>  x = x > 10
-// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre><span class='red'>        x - 1:
+// HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='uncovered-line'><pre>0</pre></td><td class='code'><pre>        x - 1:
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>        x + 1;
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>
 // HTML: <td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='covered-line'><pre>161</pre></td><td class='code'><pre>  return 0;

Modified: llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp?rev=280981&r1=280980&r2=280981&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp (original)
+++ llvm/trunk/tools/llvm-cov/SourceCoverageViewHTML.cpp Thu Sep  8 14:18:23 2016
@@ -415,26 +415,21 @@ void SourceCoverageViewHTML::renderLine(
   //    snippet 3, and so on.
 
   Optional<std::string> Color;
-  SmallVector<std::pair<unsigned, unsigned>, 4> HighlightedRanges;
+  SmallVector<std::pair<unsigned, unsigned>, 2> HighlightedRanges;
   auto Highlight = [&](const std::string &Snippet, unsigned LC, unsigned RC) {
-    if (getOptions().Debug) {
-      if (!HighlightedRanges.empty() &&
-          HighlightedRanges.back().second == LC - 1) {
-        HighlightedRanges.back().second = RC;
-      } else
-        HighlightedRanges.emplace_back(LC, RC);
-    }
+    if (getOptions().Debug)
+      HighlightedRanges.emplace_back(LC, RC);
     return tag("span", Snippet, Color.getValue());
   };
 
   auto CheckIfUncovered = [](const coverage::CoverageSegment *S) {
-    return S && (S->HasCount && S->Count == 0);
+    return S && S->HasCount && S->Count == 0;
   };
 
-  if (CheckIfUncovered(WrappedSegment) ||
-      CheckIfUncovered(Segments.empty() ? nullptr : Segments.front())) {
+  if (CheckIfUncovered(WrappedSegment)) {
     Color = "red";
-    Snippets[0] = Highlight(Snippets[0], 0, Snippets[0].size());
+    if (!Snippets[0].empty())
+      Snippets[0] = Highlight(Snippets[0], 1, 1 + Snippets[0].size());
   }
 
   for (unsigned I = 0, E = Segments.size(); I < E; ++I) {
@@ -452,16 +447,15 @@ void SourceCoverageViewHTML::renderLine(
   }
 
   if (Color.hasValue() && Segments.empty())
-    Snippets.back() = Highlight(Snippets.back(), Snippets[0].size(), 0);
+    Snippets.back() = Highlight(Snippets.back(), 1, 1 + Snippets.back().size());
 
   if (getOptions().Debug) {
     for (const auto &Range : HighlightedRanges) {
-      errs() << "Highlighted line " << LineNo << ", " << Range.first + 1
-             << " -> ";
+      errs() << "Highlighted line " << LineNo << ", " << Range.first << " -> ";
       if (Range.second == 0)
         errs() << "?";
       else
-        errs() << Range.second + 1;
+        errs() << Range.second;
       errs() << "\n";
     }
   }




More information about the llvm-commits mailing list