diff --git a/test/tools/llvm-cov/Inputs/ifdef.covmapping b/test/tools/llvm-cov/Inputs/ifdef.covmapping new file mode 100644 index 00000000000..212a1bae833 Binary files /dev/null and b/test/tools/llvm-cov/Inputs/ifdef.covmapping differ diff --git a/test/tools/llvm-cov/Inputs/ifdef.profdata b/test/tools/llvm-cov/Inputs/ifdef.profdata new file mode 100644 index 00000000000..e71240b984a Binary files /dev/null and b/test/tools/llvm-cov/Inputs/ifdef.profdata differ diff --git a/test/tools/llvm-cov/ifdef.c b/test/tools/llvm-cov/ifdef.c new file mode 100644 index 00000000000..9fd73db9743 --- /dev/null +++ b/test/tools/llvm-cov/ifdef.c @@ -0,0 +1,16 @@ +// RUN: llvm-cov show -instr-profile %S/Inputs/ifdef.profdata %S/Inputs/ifdef.covmapping -dump -path-equivalence=/tmp,%S %s > %t.out 2>&1 +// RUN: FileCheck %s -input-file %t.out -check-prefix=LINE +// RUN: FileCheck %s -input-file %t.out -check-prefix=HIGHLIGHT + + +int main() { + if (0) { // LINE: [[@LINE]]|{{ +}}1| +#if 0 // LINE-NEXT: [[@LINE]]|{{ +}}| +#endif // LINE-NEXT: [[@LINE]]|{{ +}}| + } + return 0; +} + +// HIGHLIGHT: Highlighted line [[@LINE-7]], 10 -> ? +// HIGHLIGHT-NEXT: Highlighted line [[@LINE-7]], 1 -> 1 +// HIGHLIGHT-NEXT: Highlighted line [[@LINE-6]], 1 -> 4 diff --git a/tools/llvm-cov/SourceCoverageView.cpp b/tools/llvm-cov/SourceCoverageView.cpp index 3806ee9c795..08a1c75a6f9 100644 --- a/tools/llvm-cov/SourceCoverageView.cpp +++ b/tools/llvm-cov/SourceCoverageView.cpp @@ -95,9 +95,15 @@ LineCoverageStats::LineCoverageStats( if (isStartOfRegion(LineSegments[I])) ++MinRegionCount; + bool StartOfSkippedRegion = !LineSegments.empty() && + !LineSegments.front()->HasCount && + LineSegments.front()->IsRegionEntry; + ExecutionCount = 0; HasMultipleRegions = MinRegionCount > 1; - Mapped = (WrappedSegment && WrappedSegment->HasCount) || (MinRegionCount > 0); + Mapped = + !StartOfSkippedRegion && + ((WrappedSegment && WrappedSegment->HasCount) || (MinRegionCount > 0)); if (!Mapped) return;