Files
swift-mirror/test/SILOptimizer/array_element_propagation_crash.swift
Erik Eckstein 4acffab173 SILOptimizer: fix a crash in ArrayElementValuePropagation.
This optimization is doing 2 things: replacing getElement calls and replacing append(contentOf:) calls.
Now if the argument to a append(contentOf:) is a previously replaced getElement call, we ended up in a use-after-free crash.

The main change here is to do the transformations immediately after gathering the data (and that means: separately) and not collecting all the data and do both transformation afterwards
The pass does not use any Analysis (where invalidation could be a problem). Also iterator invalidation is not a problem here.

SR-10003
rdar://problem/48445856
2019-02-28 14:38:45 -08:00

21 lines
429 B
Swift

// RUN: %empty-directory(%t)
// RUN: %target-build-swift -O %s -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
// Check that ArrayElementPropagation does not crash when compiling this function.
@inline(never)
func testit(_ arr: inout [Int]) {
let a = [28]
arr += [a[0]]
}
var a = [27]
testit(&a)
// As a bonus, also check if the code works as expected.
// CHECK: [27, 28]
print(a)