@@ -200,6 +200,8 @@ enum class LineType {
200200 VirtualCallTypeProfile,
201201};
202202
203+ // Parse `Input` as a white-space separated list of `vtable:count` pairs. An
204+ // example input line is `_ZTVbar:1471 _ZTVfoo:630`.
203205static bool parseTypeCountMap (StringRef Input,
204206 DenseMap<StringRef, uint64_t > &TypeCountMap) {
205207 for (size_t Index = Input.find_first_not_of (' ' ); Index != StringRef::npos;) {
@@ -312,7 +314,6 @@ static bool ParseLine(const StringRef &Input, LineType &LineTy, uint32_t &Depth,
312314 n4 = AfterColon.find_first_of (' ' );
313315 n4 = (n4 != StringRef::npos) ? n3 + n4 + 1 : Rest.size ();
314316 StringRef WordAfterColon = Rest.substr (n3 + 1 , n4 - n3 - 1 );
315- // Break the loop if parsing integer succeeded.
316317 if (!WordAfterColon.getAsInteger (10 , count))
317318 break ;
318319
@@ -642,17 +643,25 @@ SampleProfileReaderBinary::readVTableTypeCountMap(TypeCountMap &M) {
642643 auto VTableSamples = readNumber<uint64_t >();
643644 if (std::error_code EC = VTableSamples.getError ())
644645 return EC;
645-
646- if (!M.insert (std::make_pair (*VTableType, *VTableSamples)).second )
647- return sampleprof_error::duplicate_vtable_type;
646+ // The source profile should not have duplicate vtable records at the same
647+ // location. In case duplicate vtables are found, reader can emit a warning
648+ // but continue processing the profile.
649+ if (!M.insert (std::make_pair (*VTableType, *VTableSamples)).second ) {
650+ Ctx.diagnose (DiagnosticInfoSampleProfile (
651+ Buffer->getBufferIdentifier (), 0 ,
652+ " Duplicate vtable type " + VTableType->str () +
653+ " at the same location. Additional counters will be ignored." ,
654+ DS_Warning));
655+ continue ;
656+ }
648657 }
649658 return sampleprof_error::success;
650659}
651660
652661std::error_code
653662SampleProfileReaderBinary::readCallsiteVTableProf (FunctionSamples &FProfile) {
654- if (! ReadVTableProf)
655- return sampleprof_error::success ;
663+ assert ( ReadVTableProf &&
664+ " Cannot read vtable profiles if ReadVTableProf is false " ) ;
656665
657666 // Read the vtable type profile for the callsite.
658667 auto NumCallsites = readNumber<uint32_t >();
@@ -761,7 +770,10 @@ SampleProfileReaderBinary::readProfile(FunctionSamples &FProfile) {
761770 return EC;
762771 }
763772
764- return readCallsiteVTableProf (FProfile);
773+ if (ReadVTableProf)
774+ return readCallsiteVTableProf (FProfile);
775+
776+ return sampleprof_error::success;
765777}
766778
767779std::error_code
0 commit comments