Skip to content

Commit c422461

Browse files
committed
ArrayElementValuePropagation: Don’t create wrong SIL when trying to optimize ContiguousArray
Instead just bail on ContiguousArray. https://bugs.swift.org/browse/SR-5293 rdar://problem/32983212
1 parent dd17de7 commit c422461

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/SILOptimizer/Transforms/ArrayElementValuePropagation.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,14 @@ class ArrayElementPropagation : public SILFunctionTransform {
320320
for (const ArrayAllocation::AppendContentOfReplacement &Repl : Repls) {
321321
ArraySemanticsCall AppendContentsOf(Repl.AppendContentOfCall);
322322
assert(AppendContentsOf && "Must be AppendContentsOf call");
323-
323+
324+
NominalTypeDecl *AppendSelfArray = AppendContentsOf.getSelf()->getType().
325+
getSwiftRValueType()->getAnyNominal();
326+
327+
// In case if it's not an Array, but e.g. an ContiguousArray
328+
if (AppendSelfArray != Ctx.getArrayDecl())
329+
continue;
330+
324331
SILType ArrayType = Repl.Array->getType();
325332
auto *NTD = ArrayType.getSwiftRValueType()->getAnyNominal();
326333
SubstitutionMap ArraySubMap = ArrayType.getSwiftRValueType()

test/SILOptimizer/array_contentof_opt.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,7 @@ public func testString(_ a: inout [String], s: String) {
5353
a += [s]
5454
}
5555

56+
// This is not supported yet. Just check that we don't crash on this.`
57+
public func dontPropagateContiguousArray(_ a: inout ContiguousArray<UInt8>) {
58+
a += [4]
59+
}

0 commit comments

Comments
 (0)