[SR-10726] Overflow of struct containing variable array #53123
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
optimized only
Flag: An issue whose reproduction requires optimized compilation
Attachment: Download
Environment
MacOS 10.14.4
Xcode 10.2.1 (10E1001)
Apple Swift version 5.0.1 (swiftlang-1001.0.82.4 clang-1001.0.46.5)
Additional Detail from JIRA
md5: dea0191cc38d4e2a231713086830d92b
Issue Description:
We encountered a weird reproducible crash after we submitted a minor bug fix version of our app with latest Xcode. The only change may affect seems to be Xcode and Swift version.
So I tried to make this minimal project to reproduce the issue:
https://github.com/allenhsu/SwiftStructOverflowDemo
The main code is all in ViewController.swift
I think it's straightforward and self-explaining, the issue is that in the `step2` method, the curve.points become invalid, so curve.points.count become an arbitrary large number, and if you iterate over it, it'll crash.
Although I know how to quick fix / work around this issue, I think this may be a issue introduced by the compiler, because:
If I turn "Optimization Level" of "Swift Compiler - Code Generation" to "No Optimization", the output is correct. That's why the issue didn't happen in development environment. Maybe that's also the direction to look into, the optimization part.
The issue can also be resolved if I change the step1 method into:
Also, if I set break point in step1 method, the curve and its points is valid. So the second guess is it may be also related to live cycle and scope of variables when being optimized.
All that said, I'm not 100% percent sure if it's a but of the compiler, or there's anything I'm doing wrong.
The text was updated successfully, but these errors were encountered: