Files
swift-mirror/test/SILOptimizer/inline_array_loop_mutation.swift
Erik Eckstein e942ae40b0 AliasAnalysis: correctly handle InlineArray in type-based alias analysis
Fixes a mis-compile where TBAA failed to recurse into `Builtin.FixedArray`'s element type.

rdar://176106882
2026-05-04 10:55:54 +02:00

30 lines
871 B
Swift

// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking)
// RUN: %target-run-simple-swift(-O -Xfrontend -disable-availability-checking)
// REQUIRES: executable_test
// UNSUPPORTED: back_deployment_runtime || use_os_stdlib
// Regression test for a miscompile where TBAA failed to recurse into
// `Builtin.FixedArray`'s element type, allowing LICM to hoist a load out
// of a loop past an aliasing store. The symptom was that a loop calling
// a `mutating` method which wrote to an `InlineArray` element via
// subscript left the effect of only one iteration in the final state.
struct Container {
var values: InlineArray<3, Int>
mutating func step() {
values[0] &+= 1
}
}
var c = Container(values: [0, 0, 0])
for _ in 0 ..< 10 {
c.step()
}
precondition(c.values[0] == 10)
precondition(c.values[1] == 0)
precondition(c.values[2] == 0)