[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.

llvm-svn: 317762
This commit is contained in:
Vedant Kumar 2017-11-09 02:33:44 +00:00
parent 43247f0542
commit 69597042ff
4 changed files with 14 additions and 11 deletions

View 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|

View 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.

View 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;

View 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];