llvm.org GIT mirror llvm / 310bfcc
[Coverage] Use the most-recent completed region count (PR35437) This is a fix for the coverage segment builder. If multiple regions must be popped off the active stack at once, and more than one of them end at the same location, emit a segment using the count from the most-recent completed region. Fixes PR35437, rdar://35760630 Testing: invoked llvm-cov on a stage2 build of clang, additional unit tests, check-profile git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319391 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 2 years ago
3 changed file(s) with 35 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
386386 // location as this one.
387387 if (CompletedSegmentLoc == CompletedRegion->endLoc())
388388 continue;
389
390 // Use the count from the next completed region if it ends at the same
391 // location.
392 if (I + 1 < E &&
393 CompletedRegion->endLoc() == ActiveRegions[I + 1]->endLoc())
394 CompletedRegion = ActiveRegions[I + 1];
389395
390396 startSegment(*CompletedRegion, CompletedSegmentLoc, false);
391397 }
4444 break; // CHECK: [[@LINE]]|{{ +}}1|
4545 // CHECK: [[@LINE]]|{{ +}}0|
4646 while (++x < 5) {} // CHECK: [[@LINE]]|{{ +}}0|
47 } // CHECK: [[@LINE]]|{{ +}}1|
47 } // CHECK: [[@LINE]]|{{ +}}0|
4848
4949 if (x == 0) // CHECK: [[@LINE]]|{{ +}}1|
5050 throw Error(); // CHECK: [[@LINE]]|{{ +}}0|
9696 // MARKER-NEXT: Highlighted line 47, 14 -> 21
9797 // MARKER-NEXT: Highlighted line 47, 21 -> 23
9898 // MARKER-NEXT: Highlighted line 47, 23 -> 25
99 // MARKER-NEXT: Highlighted line 47, 25 -> ?
100 // MARKER-NEXT: Highlighted line 48, 1 -> 6
99101 // MARKER-NEXT: Highlighted line 51, 7 -> 20
100102 // MARKER-NEXT: Marker at 53:5 = 1
101103 // MARKER-NEXT: Highlighted line 55, 9 -> 14
465465 EXPECT_EQ(CoverageSegment(9, 9, false), Segments[7]);
466466 }
467467
468 TEST_P(CoverageMappingTest, multiple_completed_segments_at_same_loc) {
469 ProfileWriter.addRecord({"func1", 0x1234, {0, 1, 2}}, Err);
470 startFunction("func1", 0x1234);
471
472 // PR35437
473 addCMR(Counter::getCounter(1), "file1", 2, 1, 18, 2);
474 addCMR(Counter::getCounter(0), "file1", 8, 12, 14, 6);
475 addCMR(Counter::getCounter(1), "file1", 9, 1, 14, 6);
476 addCMR(Counter::getCounter(2), "file1", 11, 13, 11, 14);
477
478 EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
479 const auto FunctionRecords = LoadedCoverage->getCoveredFunctions();
480 const auto &FunctionRecord = *FunctionRecords.begin();
481 CoverageData Data = LoadedCoverage->getCoverageForFunction(FunctionRecord);
482 std::vector Segments(Data.begin(), Data.end());
483
484 ASSERT_EQ(6U, Segments.size());
485 EXPECT_EQ(CoverageSegment(2, 1, 1, true), Segments[0]);
486 EXPECT_EQ(CoverageSegment(8, 12, 0, true), Segments[1]);
487 EXPECT_EQ(CoverageSegment(9, 1, 1, true), Segments[2]);
488 EXPECT_EQ(CoverageSegment(11, 13, 2, true), Segments[3]);
489 // Use count=1 (from 9:1 -> 14:6), not count=0 (from 8:12 -> 14:6).
490 EXPECT_EQ(CoverageSegment(11, 14, 1, false), Segments[4]);
491 EXPECT_EQ(CoverageSegment(18, 2, false), Segments[5]);
492 }
493
468494 TEST_P(CoverageMappingTest, dont_emit_redundant_segments) {
469495 ProfileWriter.addRecord({"func1", 0x1234, {1, 1}}, Err);
470496 startFunction("func1", 0x1234);