llvm.org GIT mirror llvm / 11acfd4
Fix use-after-free with profile remapping. We need to keep the underlying profile reader alive as long as the profile data, because the profile data may contain StringRefs referring to strings in the reader's name table. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349600 91177308-0d34-0410-b5e6-96231b3b80d8 Richard Smith 1 year, 10 months ago
2 changed file(s) with 8 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
547547 : SampleProfileReader(std::move(B), C, Underlying->getFormat()) {
548548 Profiles = std::move(Underlying->getProfiles());
549549 Summary = takeSummary(*Underlying);
550 // Keep the underlying reader alive; the profile data may contain
551 // StringRefs referencing names in its name table.
552 UnderlyingReader = std::move(Underlying);
550553 }
551554
552555 /// Create a remapped sample profile from the given remapping file and
568571 private:
569572 SymbolRemappingReader Remappings;
570573 DenseMap SampleMap;
574 std::unique_ptr UnderlyingReader;
571575 };
572576
573577 } // end namespace sampleprof
127127
128128 FunctionSamples *ReadFooSamples = Reader->getSamplesFor(FooName);
129129 ASSERT_TRUE(ReadFooSamples != nullptr);
130 if (Format != SampleProfileFormat::SPF_Compact_Binary)
131 ASSERT_EQ("_Z3fooi", ReadFooSamples->getName());
130132 ASSERT_EQ(7711u, ReadFooSamples->getTotalSamples());
131133 ASSERT_EQ(610u, ReadFooSamples->getHeadSamples());
132134
133135 FunctionSamples *ReadBarSamples = Reader->getSamplesFor(BarName);
134136 ASSERT_TRUE(ReadBarSamples != nullptr);
137 if (Format != SampleProfileFormat::SPF_Compact_Binary)
138 ASSERT_EQ("_Z3bari", ReadBarSamples->getName());
135139 ASSERT_EQ(20301u, ReadBarSamples->getTotalSamples());
136140 ASSERT_EQ(1437u, ReadBarSamples->getHeadSamples());
137141 ErrorOr CTMap =