llvm.org GIT mirror llvm / 665e18d
Revert "[Coverage] Prevent detection of false instantiations in case of macro expansion." This reverts commit r266436 as it broke buildbot. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@266458 91177308-0d34-0410-b5e6-96231b3b80d8 Igor Kudrin 4 years ago
7 changed file(s) with 19 addition(s) and 102 deletion(s). Raw diff Collapse all Expand all
374374 return FilenameEquivalence;
375375 }
376376
377 /// Return the ID of the file where the definition of the function is located.
377 static Optional findMainViewFileID(StringRef SourceFile,
378 const FunctionRecord &Function) {
379 SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);
380 SmallBitVector FilenameEquivalence = gatherFileIDs(SourceFile, Function);
381 for (const auto &CR : Function.CountedRegions)
382 if (CR.Kind == CounterMappingRegion::ExpansionRegion &&
383 FilenameEquivalence[CR.FileID])
384 IsNotExpandedFile[CR.ExpandedFileID] = false;
385 IsNotExpandedFile &= FilenameEquivalence;
386 int I = IsNotExpandedFile.find_first();
387 if (I == -1)
388 return None;
389 return I;
390 }
391
378392 static Optional findMainViewFileID(const FunctionRecord &Function) {
379393 SmallBitVector IsNotExpandedFile(Function.Filenames.size(), true);
380394 for (const auto &CR : Function.CountedRegions)
386400 return I;
387401 }
388402
389 /// Check if SourceFile is the file that contains the definition of
390 /// the Function. Return the ID of the file in that case or None otherwise.
391 static Optional findMainViewFileID(StringRef SourceFile,
392 const FunctionRecord &Function) {
393 Optional I = findMainViewFileID(Function);
394 if (I && SourceFile == Function.Filenames[*I])
395 return I;
396 return None;
397 }
398
399403 /// Sort a nested sequence of regions from a single file.
400404 template static void sortNestedRegions(It First, It Last) {
401405 std::sort(First, Last,
417421
418422 for (const auto &Function : Functions) {
419423 auto MainFileID = findMainViewFileID(Filename, Function);
424 if (!MainFileID)
425 continue;
420426 auto FileIDs = gatherFileIDs(Filename, Function);
421427 for (const auto &CR : Function.CountedRegions)
422428 if (FileIDs.test(CR.FileID)) {
423429 Regions.push_back(CR);
424 if (MainFileID && isExpansion(CR, *MainFileID))
430 if (isExpansion(CR, *MainFileID))
425431 FileCoverage.Expansions.emplace_back(CR, Function);
426432 }
427433 }
test/tools/llvm-cov/Inputs/prevent_false_instantiations.covmapping less more
Binary diff not shown
+0
-15
test/tools/llvm-cov/Inputs/prevent_false_instantiations.cpp less more
None #include "prevent_false_instantiations.h"
1
2 void func1() {
3 DO_SOMETHING();
4 }
5
6 void func2() {
7 DO_SOMETHING();
8 }
9
10 int main() {
11 func1();
12 func2();
13 return 0;
14 }
+0
-26
test/tools/llvm-cov/Inputs/prevent_false_instantiations.proftext less more
None _Z5func1v
1 # Func Hash:
2 3
3 # Num Counters:
4 2
5 # Counter Values:
6 1
7 0
8
9 _Z5func2v
10 # Func Hash:
11 3
12 # Num Counters:
13 2
14 # Counter Values:
15 1
16 0
17
18 main
19 # Func Hash:
20 0
21 # Num Counters:
22 1
23 # Counter Values:
24 1
25
None config.suffixes = ['.test', '.m', '.cpp', '.c', '.h']
0 config.suffixes = ['.test', '.m', '.cpp', '.c']
+0
-10
test/tools/llvm-cov/prevent_false_instantiations.h less more
None // Checks that function instantiations don't go to a wrong file.
1
2 // CHECK-NOT: {{_Z5func[1,2]v}}
3
4 // RUN: llvm-profdata merge %S/Inputs/prevent_false_instantiations.proftext -o %t.profdata
5 // RUN: llvm-cov show %S/Inputs/prevent_false_instantiations.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck %s
6
7 #define DO_SOMETHING() \
8 do { \
9 } while (0)
453453 ASSERT_EQ("func", Names[0]);
454454 }
455455
456 TEST_P(MaybeSparseCoverageMappingTest, dont_detect_false_instantiations) {
457 InstrProfRecord Record1("foo", 0x1234, {10});
458 InstrProfRecord Record2("bar", 0x2345, {20});
459 ProfileWriter.addRecord(std::move(Record1));
460 ProfileWriter.addRecord(std::move(Record2));
461
462 startFunction("foo", 0x1234);
463 addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
464 addExpansionCMR("main", "expanded", 4, 1, 4, 5);
465
466 startFunction("bar", 0x2345);
467 addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
468 addExpansionCMR("main", "expanded", 9, 1, 9, 5);
469
470 loadCoverageMapping();
471
472 std::vector Instantiations =
473 LoadedCoverage->getInstantiations("expanded");
474 ASSERT_TRUE(Instantiations.empty());
475 }
476
477 TEST_P(MaybeSparseCoverageMappingTest, load_coverage_for_expanded_file) {
478 InstrProfRecord Record("func", 0x1234, {10});
479 ProfileWriter.addRecord(std::move(Record));
480
481 startFunction("func", 0x1234);
482 addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10);
483 addExpansionCMR("main", "expanded", 4, 1, 4, 5);
484
485 loadCoverageMapping();
486
487 CoverageData Data = LoadedCoverage->getCoverageForFile("expanded");
488 std::vector Segments(Data.begin(), Data.end());
489 ASSERT_EQ(2U, Segments.size());
490 EXPECT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]);
491 EXPECT_EQ(CoverageSegment(1, 10, false), Segments[1]);
492 }
493
494456 INSTANTIATE_TEST_CASE_P(MaybeSparse, MaybeSparseCoverageMappingTest,
495457 ::testing::Bool());
496458