From 1c14dc4c5a3b0f17672a121f026e96a15f93dd4a Mon Sep 17 00:00:00 2001 From: Igor Kudrin Date: Mon, 18 Apr 2016 15:36:30 +0000 Subject: Reapply "[Coverage] Prevent detection of false instantiations in case of macro expansion." The root of the problem was that findMainViewFileID(File, Function) could return some ID for any given file, even though that file was not the main file for that function. This patch ensures that the result of this function is conformed with the result of findMainViewFileID(Function). This commit reapplies r266436, which was reverted by r266458, with the .covmapping file serialized in v1 format. Differential Revision: http://reviews.llvm.org/D18787 llvm-svn: 266620 --- llvm/unittests/ProfileData/CoverageMappingTest.cpp | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'llvm/unittests/ProfileData/CoverageMappingTest.cpp') diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp index b98da8be72c..5983d709158 100644 --- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp +++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp @@ -454,6 +454,44 @@ TEST_P(MaybeSparseCoverageMappingTest, strip_unknown_filename_prefix) { ASSERT_EQ("func", Names[0]); } +TEST_P(MaybeSparseCoverageMappingTest, dont_detect_false_instantiations) { + InstrProfRecord Record1("foo", 0x1234, {10}); + InstrProfRecord Record2("bar", 0x2345, {20}); + ProfileWriter.addRecord(std::move(Record1)); + ProfileWriter.addRecord(std::move(Record2)); + + startFunction("foo", 0x1234); + addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10); + addExpansionCMR("main", "expanded", 4, 1, 4, 5); + + startFunction("bar", 0x2345); + addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10); + addExpansionCMR("main", "expanded", 9, 1, 9, 5); + + loadCoverageMapping(); + + std::vector Instantiations = + LoadedCoverage->getInstantiations("expanded"); + ASSERT_TRUE(Instantiations.empty()); +} + +TEST_P(MaybeSparseCoverageMappingTest, load_coverage_for_expanded_file) { + InstrProfRecord Record("func", 0x1234, {10}); + ProfileWriter.addRecord(std::move(Record)); + + startFunction("func", 0x1234); + addCMR(Counter::getCounter(0), "expanded", 1, 1, 1, 10); + addExpansionCMR("main", "expanded", 4, 1, 4, 5); + + loadCoverageMapping(); + + CoverageData Data = LoadedCoverage->getCoverageForFile("expanded"); + std::vector Segments(Data.begin(), Data.end()); + ASSERT_EQ(2U, Segments.size()); + EXPECT_EQ(CoverageSegment(1, 1, 10, true), Segments[0]); + EXPECT_EQ(CoverageSegment(1, 10, false), Segments[1]); +} + INSTANTIATE_TEST_CASE_P(MaybeSparse, MaybeSparseCoverageMappingTest, ::testing::Bool()); -- cgit v1.2.3