llvm.org GIT mirror llvm / c97ab8f
[Coverage] Take filenames into account when loading function records. Summary: Don't skip functions with the same name but from different files. That change makes it possible to generate code coverage reports from different binaries compiled from different sources even if there are functions with non-unique names. Without that change, code coverage for such functions is missing except of the first function processed. Reviewers: vsk, morehouse Reviewed By: vsk Subscribers: llvm-commits, kcc Differential Revision: https://reviews.llvm.org/D46478 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331801 91177308-0d34-0410-b5e6-96231b3b80d8 Max Moroz 1 year, 5 months ago
4 changed file(s) with 34 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
1616
1717 #include "llvm/ADT/ArrayRef.h"
1818 #include "llvm/ADT/DenseMap.h"
19 #include "llvm/ADT/DenseSet.h"
1920 #include "llvm/ADT/Hashing.h"
2021 #include "llvm/ADT/None.h"
2122 #include "llvm/ADT/StringRef.h"
505506 /// This is the main interface to get coverage information, using a profile to
506507 /// fill out execution counts.
507508 class CoverageMapping {
508 StringSet<> FunctionNames;
509 DenseMap> RecordProvenance;
509510 std::vector Functions;
510511 std::vector> FuncHashMismatches;
511512 std::vector> FuncCounterMismatches;
206206 else
207207 OrigFuncName = getFuncNameWithoutPrefix(OrigFuncName, Record.Filenames[0]);
208208
209 // Don't load records for functions we've already seen.
210 if (!FunctionNames.insert(OrigFuncName).second)
209 // Don't load records for (filenames, function) pairs we've already seen.
210 auto FilenamesHash = hash_combine_range(Record.Filenames.begin(),
211 Record.Filenames.end());
212 if (!RecordProvenance[FilenamesHash].insert(hash_value(OrigFuncName)).second)
211213 return Error::success();
212214
213215 CounterMappingContext Ctx(Record.Expressions);
44 REPORT: Filename{{ +}}Regions{{ +}}Missed Regions{{ +}}Cover
55 REPORT-NEXT: ---
66 REPORT-NEXT: header.h{{ +}}25{{ +}}14{{ +}}44.00%
7
8 # Make sure that both use_1.cc and use_2.cc have coverage reported.
9 # Before https://reviews.llvm.org/D46478, only one of them used to be reported.
10 REPORT-NEXT: use_1.cc{{ +}}1{{ +}}0{{ +}}100.00%
11 REPORT-NEXT: use_2.cc{{ +}}2{{ +}}0{{ +}}100.00%
712
813 Instructions for regenerating the test:
914
858858 TEST_P(CoverageMappingTest, skip_duplicate_function_record) {
859859 ProfileWriter.addRecord({"func", 0x1234, {1}}, Err);
860860
861 startFunction("func", 0x1234);
862 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
863
864 startFunction("func", 0x1234);
865 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
861 // This record should be loaded.
862 startFunction("func", 0x1234);
863 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
864
865 // This record should be loaded.
866 startFunction("func", 0x1234);
867 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
868 addCMR(Counter::getCounter(0), "file2", 1, 1, 9, 9);
869
870 // This record should be skipped.
871 startFunction("func", 0x1234);
872 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
873
874 // This record should be loaded.
875 startFunction("func", 0x1234);
876 addCMR(Counter::getCounter(0), "file2", 1, 1, 9, 9);
877 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
878
879 // This record should be skipped.
880 startFunction("func", 0x1234);
881 addCMR(Counter::getCounter(0), "file1", 1, 1, 9, 9);
882 addCMR(Counter::getCounter(0), "file2", 1, 1, 9, 9);
866883
867884 EXPECT_THAT_ERROR(loadCoverageMapping(), Succeeded());
868885
869886 auto Funcs = LoadedCoverage->getCoveredFunctions();
870887 unsigned NumFuncs = std::distance(Funcs.begin(), Funcs.end());
871 ASSERT_EQ(1U, NumFuncs);
888 ASSERT_EQ(3U, NumFuncs);
872889 }
873890
874891 // FIXME: Use ::testing::Combine() when llvm updates its copy of googletest.