You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Miscompile on arm64 at -O: AArch64 load/store optimizer renames a call's swiftself register (x20 → x22) #93360
A miscompile, not a compiler crash: the program built with -O crashes at runtime.
A call to Date.timeIntervalSince1970.getter (resilient struct, self passed by address in x20) is executed with x20 not holding self, so the getter dereferences garbage. Swift's IR is correct. The register is lost in LLVM's AArch64 load/store optimizer: to merge two stores into an stp, its register renaming rewrites the call's implicit $x20 argument to $x22. Disabling that renaming (-Xllvm -aarch64-load-store-renaming=false) fixes it.
* thread #3, name = 'Task 1', queue = 'com.apple.root.default-qos.cooperative', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
* frame #0: 0x000000019ec43e48 Foundation`Foundation.Date.timeIntervalSince1970.getter : Swift.Double + 16
frame #1: 0x00000001000014f0 repro`compute(for:) + 380
frame #2: 0x00000001000027c8 repro`specialized static Main.main()
frame #3: 0x0000000100001aa0 repro`(1) await resume partial function for function signature specialization <Arg[1] = [Constant Propagated Function : async_Main]> of reabstraction thunk helper from @escaping @convention(thin) @async () -> () to @escaping @callee_guaranteed @async () -> (@out (), @error @owned Swift.Error)
Expected behavior
The program prints [[100.0]].
Environment
Xcode 27.0 / 27.1 RC: Apple Swift version 6.4 (swiftlang-6.4.0.34.1 clang-2100.3.34.1)
swift.org swift-6.4.1-RELEASE and swift-6.3.3-RELEASE
macOS 27.0.1, Apple M3 Pro. Same code generation for arm64-apple-ios15.0; originally hit on iOS 26.6.2.
Additional information
MIR around the call before and after aarch64-ldst-opt (the crashing build command plus -Xllvm -print-before=aarch64-ldst-opt -Xllvm -print-after=aarch64-ldst-opt, swift.org 6.4.1):
-opt-bisect-limit confirms this pass on compute(for:) is the first step that produces the crash. At the crash, x20 = 0x0 and x22 holds the correct Date address.
The shape is fragile. In the reproducer, each of these hides the crash: -Onone, -Osize, @inline(never) on group, looping over an array instead of a dictionary, removing the throwing exit, making compute synchronous, or capturing a Double or String instead of the object. Of the other types we tried in place of Date, Measurement also crashes; UUID, URL and Decimal don't, in this shape.
Activity