diff options
| author | Vedant Kumar <vsk@apple.com> | 2016-09-08 19:18:23 +0000 |
|---|---|---|
| committer | Vedant Kumar <vsk@apple.com> | 2016-09-08 19:18:23 +0000 |
| commit | 0b33f2c0032088e890f929f11ba559091182a8f9 (patch) | |
| tree | ceda599869596fa590e7e22faa4c65a58dd60216 | |
| parent | 55f9f18cb2ea5b843bdff373b97f265ce288f1ec (diff) | |
| download | bcm5719-llvm-0b33f2c0032088e890f929f11ba559091182a8f9.tar.gz bcm5719-llvm-0b33f2c0032088e890f929f11ba559091182a8f9.zip | |
[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.
llvm-svn: 280981
| -rw-r--r-- | llvm/test/tools/llvm-cov/showHighlightedRanges.cpp | 24 | ||||
| -rw-r--r-- | llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp | 4 | ||||
| -rw-r--r-- | llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp | 26 |
3 files changed, 24 insertions, 30 deletions
diff --git a/llvm/test/tools/llvm-cov/showHighlightedRanges.cpp b/llvm/test/tools/llvm-cov/showHighlightedRanges.cpp index c53a6c92fe2..4ed3f17e58f 100644 --- a/llvm/test/tools/llvm-cov/showHighlightedRanges.cpp +++ b/llvm/test/tools/llvm-cov/showHighlightedRanges.cpp @@ -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; } diff --git a/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp b/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp index 9637af4662a..f5448322cea 100644 --- a/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp +++ b/llvm/test/tools/llvm-cov/showLineExecutionCounts.cpp @@ -50,7 +50,7 @@ int main() { // TEXT: [[@LINE]]| 161|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() { // TEXT: [[@LINE]]| 161|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; diff --git a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp index ca3f350ff7a..17353b553f9 100644 --- a/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp +++ b/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -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"; } } |

