Skip to content

Conversation

@jamieQ
Copy link
Contributor

@jamieQ jamieQ commented Oct 19, 2025

like #84951 but with diagnosis attempted in Sema rather than SILGen or DI

Previously it was possible to reference uninitialized memory if a
closure that was part of a variable binding initializer referenced the
name of the uninitialized value. DI was ignoring these cases before
because no mark_uninitialized instruction was produced. Instead of
trying to skip emitting that instruction sometimes, just always emit it
if a temporary allocation is used so DI will catch liveness issues.
@jamieQ
Copy link
Contributor Author

jamieQ commented Oct 19, 2025

@swift-ci please smoke test macos

Copy link
Contributor

@slavapestov slavapestov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Detecting these problems in Sema might be difficult because of how local functions can forward-reference captures (and local functions can also be mutually recursive), but if you think you can sort it out, go ahead :)

@jamieQ
Copy link
Contributor Author

jamieQ commented Oct 20, 2025

Detecting these problems in Sema might be difficult because of how local functions can forward-reference captures (and local functions can also be mutually recursive), but if you think you can sort it out, go ahead :)

ugh, i did not realize this was allowed:

func weird(_ a: Any) {
    func local() -> Any { bad }
    let bad = local()
    print("bad: \(bad)")
}

@jamieQ jamieQ closed this Oct 23, 2025
@jamieQ jamieQ deleted the fix-address-only-DI-Sema branch October 23, 2025 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants