mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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
21 lines
429 B
Swift
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)
|
|
|