diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 4bea04d2616..f3800e8374c 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -833,13 +833,19 @@ void Serializer::writeSubstitutions(ArrayRef substitutions, addTypeRef(sub.Archetype), addTypeRef(sub.Replacement), sub.Archetype->getConformsTo().size()); + ArrayRef conformances = sub.Conformance; + // For archetypes the conformance information is context dependent, // the conformance array is either empty or full of nulls and can be // ignored. We use an array of null pointers for conformances to satisfy // the requirement in writeConformances: the first and second arguments // have the same size. - SmallVector conformances( - sub.Archetype->getConformsTo().size(), nullptr); + SmallVector conformancesBuf; + if (sub.Conformance.empty() && !sub.Archetype->getConformsTo().empty()) { + conformancesBuf.resize(sub.Archetype->getConformsTo().size(), + nullptr); + conformances = conformancesBuf; + } writeConformances(sub.Archetype->getConformsTo(), conformances, nullptr, abbrCodes); }