Index: test/tools/llvm-cov/deferred-region.cpp =================================================================== --- test/tools/llvm-cov/deferred-region.cpp +++ test/tools/llvm-cov/deferred-region.cpp @@ -1,4 +1,4 @@ -// RUN: llvm-cov show %S/Inputs/deferred-regions.covmapping -instr-profile %S/Inputs/deferred-regions.profdata -show-line-counts-or-regions -dump -filename-equivalence %s 2>&1 | FileCheck %s +// RUN: llvm-cov show %S/Inputs/deferred-regions.covmapping -instr-profile %S/Inputs/deferred-regions.profdata -show-line-counts-or-regions -dump -filename-equivalence %s &> %t.out && FileCheck %s -input-file %t.out && FileCheck %s -input-file %t.out -check-prefix=MARKER void foo(int x) { if (x == 0) { @@ -77,3 +77,45 @@ gotos(); return 0; } + +// MARKER: Marker at 4:7 = 2 +// MARKER-NEXT: Highlighted line 17, 5 -> 11 +// MARKER-NEXT: Marker at 17:5 = 0 +// MARKER-NEXT: Marker at 19:3 = 1 +// MARKER-NEXT: Marker at 19:19 = 2 +// MARKER-NEXT: Marker at 19:27 = 1 +// MARKER-NEXT: Marker at 21:7 = 1 +// MARKER-NEXT: Marker at 23:5 = 1 +// MARKER-NEXT: Marker at 23:9 = 1 +// MARKER-NEXT: Highlighted line 24, 7 -> 12 +// MARKER-NEXT: Marker at 24:7 = 0 +// MARKER-NEXT: Highlighted line 36, 5 -> 11 +// MARKER-NEXT: Marker at 36:5 = 0 +// MARKER-NEXT: Marker at 39:10 = 3 +// MARKER-NEXT: Marker at 41:7 = 1 +// MARKER-NEXT: Marker at 43:5 = 1 +// MARKER-NEXT: Marker at 43:12 = 1 +// MARKER-NEXT: Highlighted line 45, 14 -> ? +// MARKER-NEXT: Marker at 45:9 = 1 +// MARKER-NEXT: Highlighted line 46, 1 -> ? +// MARKER-NEXT: Highlighted line 47, 1 -> 7 +// MARKER-NEXT: Highlighted line 47, 7 -> 14 +// MARKER-NEXT: Highlighted line 47, 14 -> 21 +// MARKER-NEXT: Highlighted line 47, 21 -> 23 +// MARKER-NEXT: Highlighted line 47, 23 -> 25 +// MARKER-NEXT: Highlighted line 47, 25 -> ? +// MARKER-NEXT: Marker at 47:7 = 0 +// MARKER-NEXT: Marker at 47:14 = 0 +// MARKER-NEXT: Marker at 47:23 = 0 +// MARKER-NEXT: Highlighted line 48, 1 -> 6 +// MARKER-NEXT: Highlighted line 51, 7 -> 20 +// MARKER-NEXT: Marker at 51:7 = 0 +// MARKER-NEXT: Marker at 53:5 = 1 +// MARKER-NEXT: Marker at 53:12 = 6 +// MARKER-NEXT: Highlighted line 55, 9 -> 14 +// MARKER-NEXT: Highlighted line 63, 5 -> 13 +// MARKER-NEXT: Marker at 63:5 = 0 +// MARKER-NEXT: Highlighted line 67, 1 -> ? +// MARKER-NEXT: Highlighted line 68, 1 -> 8 +// MARKER-NEXT: Highlighted line 68, 8 -> ? +// MARKER-NEXT: Highlighted line 69, 1 -> 2 Index: test/tools/llvm-cov/showRegionMarkers.cpp =================================================================== --- test/tools/llvm-cov/showRegionMarkers.cpp +++ test/tools/llvm-cov/showRegionMarkers.cpp @@ -1,27 +1,28 @@ // RUN: llvm-profdata merge %S/Inputs/regionMarkers.proftext -o %t.profdata -int main() { // CHECK: Marker at [[@LINE]]:12 = 1.11M +int main() { // CHECK-NOT: Marker at [[@LINE]]:12 int x = 0; - if (x) { // CHECK: Marker at [[@LINE]]:10 = 0 + if (x) { // CHECK-NOT: Marker at [[@LINE]]:10 x = 0; - } else { // CHECK: Marker at [[@LINE]]:10 = 1.11M + } else { // CHECK-NOT: Marker at [[@LINE]]:10 x = 1; } // CHECK: Marker at [[@LINE+2]]:19 = 112M // CHECK: Marker at [[@LINE+1]]:28 = 111M - for (int i = 0; i < 100; ++i) { // CHECK: Marker at [[@LINE]]:33 = 111M + for (int i = 0; i < 100; ++i) { // CHECK-NOT: Marker at [[@LINE]]:33 x = 1; } // CHECK: Marker at [[@LINE+1]]:16 = 1.11M x = x < 10 ? x + 1 : x - 1; // CHECK: Marker at [[@LINE]]:24 = 0 x = x > 10 ? - x - 1: // CHECK: Marker at [[@LINE]]:9 = 0 - x + 1; // CHECK: Marker at [[@LINE]]:9 = 1.11M + x - 1: // CHECK-NOT: Marker at [[@LINE]]:9 + x + 1; // CHECK-NOT: Marker at [[@LINE]]:9 return 0; } // RUN: llvm-cov show %S/Inputs/regionMarkers.covmapping -instr-profile %t.profdata -show-regions -dump -filename-equivalence %s 2>&1 | FileCheck %s +// RUN: llvm-cov show %S/Inputs/regionMarkers.covmapping -instr-profile %t.profdata -show-regions -format=html -dump -filename-equivalence %s 2>&1 | FileCheck %s // RUN: llvm-cov export %S/Inputs/regionMarkers.covmapping -instr-profile %t.profdata 2>&1 | FileCheck %S/Inputs/regionMarkers.json Index: tools/llvm-cov/CodeCoverage.cpp =================================================================== --- tools/llvm-cov/CodeCoverage.cpp +++ tools/llvm-cov/CodeCoverage.cpp @@ -720,7 +720,6 @@ ViewOpts.ShowLineStats = ShowLineExecutionCounts.getNumOccurrences() != 0 || !ShowRegions || ShowBestLineRegionsCounts; ViewOpts.ShowRegionMarkers = ShowRegions || ShowBestLineRegionsCounts; - ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts; ViewOpts.ShowExpandedRegions = ShowExpansions; ViewOpts.ShowFunctionInstantiations = ShowInstantiations; ViewOpts.ShowOutputDirectory = ShowOutputDirectory; Index: tools/llvm-cov/CoverageViewOptions.h =================================================================== --- tools/llvm-cov/CoverageViewOptions.h +++ tools/llvm-cov/CoverageViewOptions.h @@ -27,7 +27,6 @@ bool ShowLineNumbers; bool ShowLineStats; bool ShowRegionMarkers; - bool ShowLineStatsOrRegionMarkers; bool ShowExpandedRegions; bool ShowFunctionInstantiations; bool ShowFullFilenames; Index: tools/llvm-cov/SourceCoverageView.h =================================================================== --- tools/llvm-cov/SourceCoverageView.h +++ tools/llvm-cov/SourceCoverageView.h @@ -236,7 +236,7 @@ static std::string formatCount(uint64_t N); /// \brief Check if region marker output is expected for a line. - bool shouldRenderRegionMarkers(bool LineHasMultipleRegions) const; + bool shouldRenderRegionMarkers(CoverageSegmentArray Segments) const; /// \brief Check if there are any sub-views attached to this view. bool hasSubViews() const; Index: tools/llvm-cov/SourceCoverageView.cpp =================================================================== --- tools/llvm-cov/SourceCoverageView.cpp +++ tools/llvm-cov/SourceCoverageView.cpp @@ -153,9 +153,17 @@ } bool SourceCoverageView::shouldRenderRegionMarkers( - bool LineHasMultipleRegions) const { - return getOptions().ShowRegionMarkers && - (!getOptions().ShowLineStatsOrRegionMarkers || LineHasMultipleRegions); + CoverageSegmentArray Segments) 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; + return false; } bool SourceCoverageView::hasSubViews() const { @@ -261,7 +269,7 @@ ExpansionColumn, ViewDepth); // Show the region markers. - if (shouldRenderRegionMarkers(LineCount.hasMultipleRegions())) + if (shouldRenderRegionMarkers(LineSegments)) renderRegionMarkers(OS, LineSegments, ViewDepth); // Show the expansions and instantiations for this line. Index: tools/llvm-cov/SourceCoverageViewHTML.cpp =================================================================== --- tools/llvm-cov/SourceCoverageViewHTML.cpp +++ tools/llvm-cov/SourceCoverageViewHTML.cpp @@ -518,25 +518,21 @@ // 4. Snippets[1:N+1] correspond to \p Segments[0:N]: use these to generate // sub-line region count tooltips if needed. - bool HasMultipleRegions = [&] { - unsigned RegionCount = 0; - for (const auto *S : Segments) - if (S->HasCount && S->IsRegionEntry) - if (++RegionCount > 1) - return true; - return false; - }(); - - if (shouldRenderRegionMarkers(HasMultipleRegions)) { - for (unsigned I = 0, E = Segments.size(); I < E; ++I) { + if (shouldRenderRegionMarkers(Segments)) { + // 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]; - if (!CurSeg->IsRegionEntry || !CurSeg->HasCount) + if (!CurSeg->IsRegionEntry) continue; Snippets[I + 1] = tag("div", Snippets[I + 1] + tag("span", formatCount(CurSeg->Count), "tooltip-content"), "tooltip"); + + if (getOptions().Debug) + errs() << "Marker at " << CurSeg->Line << ":" << CurSeg->Col << " = " + << formatCount(CurSeg->Count) << "\n"; } } Index: tools/llvm-cov/SourceCoverageViewText.cpp =================================================================== --- tools/llvm-cov/SourceCoverageViewText.cpp +++ tools/llvm-cov/SourceCoverageViewText.cpp @@ -171,6 +171,10 @@ renderLinePrefix(OS, ViewDepth); OS.indent(getCombinedColumnWidth(getOptions())); + // Just consider the segments which start *and* end on this line. + if (Segments.size() > 1) + Segments = Segments.drop_back(); + unsigned PrevColumn = 1; for (const auto *S : Segments) { if (!S->IsRegionEntry) @@ -182,13 +186,12 @@ std::string C = formatCount(S->Count); PrevColumn += C.size(); OS << '^' << C; - } - OS << '\n'; - if (getOptions().Debug) - for (const auto *S : Segments) + if (getOptions().Debug) errs() << "Marker at " << S->Line << ":" << S->Col << " = " - << formatCount(S->Count) << (S->IsRegionEntry ? "\n" : " (pop)\n"); + << formatCount(S->Count) << "\n"; + } + OS << '\n'; } void SourceCoverageViewText::renderExpansionSite(