Skip to content

[AddressLowering] Create copy_addr after store. #62078

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

Merged

Conversation

nate-chandler
Copy link
Contributor

When rewriting a store, insert the copy_addr after it rather than before
it.

Previously, after the copy_addr is created,

alloc_stack %target_addr $Ty, var, name "something"
...
copy_addr [take] %source_addr to [init] %target_addr
store %instance to [init] %addr

when deleting the store, debug info salvaging may result in a
debug_value instruction being created before the store,

alloc_stack %target_addr $Ty, var, name "something"
...
copy_addr [take] %source_addr to [init] %target_addr
debug_value %source_addr : $*Ty, var, name "something"
store %instance to [init] %addr

using the %source_addr. If the created copy_addr is a [take], this
results in the debug_value being a use-after-consume in the final SIL:

alloc_stack %target_addr $Ty, var, name "something"
...
copy_addr [take] %source_addr to [init] %target_addr
debug_value %source_addr : $*Ty, var, name "something"

Instead, now, the copy_addr is created after:

alloc_stack %target_addr $Ty, var, name "something"
...
store %instance to [init] %addr
copy_addr [take] %source_addr to [init] %target_addr

So when the debug_value instruction is created before the store during
debug info salvaging

alloc_stack %target_addr $Ty, var, name "something"
...
debug_value %source_addr : $*Ty, var, name "something"
store %instance to [init] %addr
copy_addr [take] %source_addr to [init] %target_addr

it is also before the newly added copy_addr. The result is that when
the store is deleted, we have valid SIL:

alloc_stack %target_addr $Ty, var, name "something"
...
debug_value %source_addr : $*Ty, var, name "something"
copy_addr [take] %source_addr to [init] %target_addr

Based on #62074 .

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler
Copy link
Contributor Author

@swift-ci please test linux platform

@nate-chandler nate-chandler marked this pull request as ready for review November 13, 2022 21:10
When rewriting a store, insert the copy_addr after it rather than before
it.

Previously, after the copy_addr is created,

```
alloc_stack %target_addr $Ty, var, name "something"
...
copy_addr [take] %source_addr to [init] %target_addr
store %instance to [init] %addr
```

when deleting the store, debug info salvaging may result in a
debug_value instruction being created before the store,

```
alloc_stack %target_addr $Ty, var, name "something"
...
copy_addr [take] %source_addr to [init] %target_addr
debug_value %source_addr : $*Ty, var, name "something"
store %instance to [init] %addr
```

using the %source_addr.  If the created copy_addr is a [take], this
results in the debug_value being a use-after-consume in the final SIL:

```
alloc_stack %target_addr $Ty, var, name "something"
...
copy_addr [take] %source_addr to [init] %target_addr
debug_value %source_addr : $*Ty, var, name "something"
```

Instead, now, the copy_addr is created after:

```
alloc_stack %target_addr $Ty, var, name "something"
...
store %instance to [init] %addr
copy_addr [take] %source_addr to [init] %target_addr
```

So when the debug_value instruction is created before the store during
debug info salvaging

```
alloc_stack %target_addr $Ty, var, name "something"
...
debug_value %source_addr : $*Ty, var, name "something"
store %instance to [init] %addr
copy_addr [take] %source_addr to [init] %target_addr
```

it is also before the newly added copy_addr.  The result is that when
the store is deleted, we have valid SIL:

```
alloc_stack %target_addr $Ty, var, name "something"
...
debug_value %source_addr : $*Ty, var, name "something"
copy_addr [take] %source_addr to [init] %target_addr
@nate-chandler nate-chandler force-pushed the opaque-values/1/20221112 branch from a9eaaa7 to 1023583 Compare November 16, 2022 18:40
@nate-chandler
Copy link
Contributor Author

@swift-ci please smoke test

@nate-chandler nate-chandler merged commit 781953f into swiftlang:main Nov 17, 2022
@nate-chandler nate-chandler deleted the opaque-values/1/20221112 branch November 17, 2022 19:16
@atrick
Copy link
Contributor

atrick commented Nov 29, 2022

LGTM but it makes me nervous about other places that may also salvage debug_info when deleting the original instruction. Any way to guard against that?

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