Skip to content

Commit 0d44d09

Browse files
committed
[4.2] ASTContext: Recompute the insert position in getSpecializedConformance
after the SpecializedProtocolConformance constructor The constructor can modify the SpecializedConformances FoldingSet so that the insertPos is no longer valid. It calls computeConditionalRequirements which calls Type::subst which recursively can call getSpecializedConformance again. Therefore, we need to recompute the insertPos after calling the constructor. This bug manifest itself either as memory error with libgmalloc or as spurious errors later on. * Explanation: Memory errors causing spurious failure later in the compiler on our CI tests * Scope: Memory errors are bad. This bug dates back to when conditional conformance were added sometime during 2017. * Risk: Low. A call to recompute the insertion point (a map lookup) is added. *Testing: Existing Swift CI test caught this rdar://42082352
1 parent b27a34b commit 0d44d09

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,6 +1871,9 @@ ASTContext::getSpecializedConformance(Type type,
18711871
auto result
18721872
= new (*this, arena) SpecializedProtocolConformance(type, generic,
18731873
substitutions);
1874+
auto node = specializedConformances.FindNodeOrInsertPos(id, insertPos);
1875+
(void)node;
1876+
assert(!node);
18741877
specializedConformances.InsertNode(result, insertPos);
18751878
return result;
18761879
}

0 commit comments

Comments
 (0)