Skip to content

Conversation

atrick
Copy link
Contributor

@atrick atrick commented Oct 2, 2025

When a non-Escapable value depends on the address of a trivial value, we use a
special computeAddressableRange analysis to compute the trivial value's
scope. Extend that analysis to include unreachable paths.

Fixes this pattern:

  inlineStorage.span.withUnsafeBytes

where inlineStorage is a trivial type defined in the user module. This
does not reproduce directly with InlineArray, but it is a problem for
user modules that have their own trivial wrapper around an InlineArray.

Fixes rdar://161630684 (Incorrect diagnostic: error: lifetime-dependent value escapes its scope)

@atrick atrick requested a review from eeckstein as a code owner October 2, 2025 03:46
@atrick atrick requested a review from meg-gupta October 2, 2025 03:50
@atrick
Copy link
Contributor Author

atrick commented Oct 2, 2025

@swift-ci test

Copy link
Contributor

@meg-gupta meg-gupta left a comment

Choose a reason for hiding this comment

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

LGTM - I added another test suggestion. So far, I thought we don't disable dealloc_stack emission on unreachable paths.

@atrick
Copy link
Contributor Author

atrick commented Oct 2, 2025

LGTM - I added another test suggestion. So far, I thought we don't disable dealloc_stack emission on unreachable paths.

@meg-gupta yes, omitting dealloc_stack is very problematic for computing the scope of address dependencies. It would be much simpler to enforce a dealloc on all paths. @eeckstein @nate-chandler technically this is not required by OSSA but it requires a very similar CFG analysis of lifetime end points and it's strange to complete lifetimes without also completing allocations.

@nate-chandler
Copy link
Contributor

nate-chandler commented Oct 2, 2025

Neither lifetimes of values nor "lifetimes" of alloc_stacks are currently complete throughout the pipeline, so such completeness cannot be relied on. But I agree that it may make sense to complete of the former when completing of the latter.

@atrick
Copy link
Contributor Author

atrick commented Oct 2, 2025

@swift-ci smoke test

@atrick
Copy link
Contributor Author

atrick commented Oct 3, 2025

@swift-ci smoke test

@atrick atrick force-pushed the lifedep-tempaddress-unreachable branch from ac9a5b6 to 3469879 Compare October 4, 2025 03:44
atrick added 2 commits October 3, 2025 20:47
When a non-Escapable value depends on the address of a trivial value, we use a
special computeAddressableRange analysis to compute the trivial value's
scope. Extend that analysis to include unreachable paths.

Fixes this pattern:

    inlineStorage.span.withUnsafeBytes

where inlineStorage is a trivial type defined in the user module. This
does not reproduce directly with InlineArray, but it is a problem for
user modules that have their own trivial wrapper around an InlineArray.

Fixes rdar://161630684 (Incorrect diagnostic: lifetime-dependent value escapes its scope)
@atrick atrick force-pushed the lifedep-tempaddress-unreachable branch from 3469879 to bed80ee Compare October 4, 2025 03:48
@atrick
Copy link
Contributor Author

atrick commented Oct 4, 2025

@swift-ci smoke test

@atrick
Copy link
Contributor Author

atrick commented Oct 4, 2025

@swift-ci smoke test linux

1 similar comment
@atrick
Copy link
Contributor Author

atrick commented Oct 4, 2025

@swift-ci smoke test linux

@atrick atrick merged commit c1e1ef6 into swiftlang:main Oct 5, 2025
3 checks passed
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.

4 participants