-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Runtime crash when using unsafeUninitializedCapacity incorrectly #70323
Comments
|
A simpler example: func foo(_ fn: () -> [Int]) -> [Int] { fn() }
var x: [Int] = foo {
var result = x
result.append(1)
return result
}
print(x)SIL analyses are smart enough to reject this in a local context, but not at the top level. Related to #69535. |
|
I'll try to take it, if it's okay with anyone. |
|
I wasn't able to reproduce this immediately using |
|
Speaking of the original example, I can reproduce a segfault with both a
|
|
More examples from dupes: let x: Any = x
print(a) // Outputs "0" or "45" with -O
let a = 45cc @atrick |
|
There is a discussion about variables in top-level code from 2021 (without clear conclusion) – https://forums.swift.org/t/on-the-behavior-of-variables-in-top-level-code/52230 |
|
Note that the stack dump says: |
|
This looks like #70356 Which is just one manifestation of the fact that Swift top-level code is fundamentally broken, and could be fixed simply by treating top-level variables as locals. |
Description
I accidentally attempted to access the list I was initializing in the body of the unsafeUninitializedCapacity block and found a compiler crash.
Reproduction
Stack dump
Expected behavior
I expected a compiler error.
Environment
swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5)
Target: arm64-apple-macosx14.0
Additional information
No response
The text was updated successfully, but these errors were encountered: