Open aaron-foreflight opened 11 months ago
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 swiftc
from the command line using either the 5.9.2 compiler (from Xcode 15.2) or using a newly-built compiler from top-of-tree. Can anyone provide more details on how to reproduce this?
Speaking of the original example, I can reproduce a segfault with both a swiftc
-emitted binary and the interpreter, using a 6d66211dea41ca6 compiler:
swiftc -o main -sdk $(xcrun --show-sdk-path) file.swift && ./main
swift file.swift
More examples from dupes:
let x: Any = x
print(a) // Outputs "0" or "45" with -O
let a = 45
cc @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: While running user code "swiftcrasher.swift"
This looks like https://github.com/apple/swift/issues/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