Commit 12e5b3b
[clr-interp] Fix handling of continuation return when it is not used by the method (#128403)
Consider the scenario where we are emitting an async method call where
the return value is not used at all by the method and, by the time we
are actually doing the suspend operation, a new live variable is
created. This means that the new variable could share the same offset as
the return offset. Example interp IR:
```
IR_0074: call [64 <- 96], .Program:ThrowsAsync[System.__Canon](System.Func`1[System.Threading.Tasks.Task])
// var at offset 56 was present on the interp execution stack and it gets moved to a temporary that shares the same offset with the dead return
// this means that, when we restore the context and write the continuation return to the interp stack, we overwritte this
IR_0078: mov.8 [64 <- 56],
IR_007b: handle.continuation [72 <- nil], AsyncSuspendData[continuationTypeHnd=0x7fff7980c310, flags=3144, liveLocalsIntervals=[{64, 71},], zeroedLocalsIntervals=[], keepAliveOffset=32], 0x7fff797479c0 (CORINFO_HELP_ALLOC_CONTINUATION)(indirect)
IR_007f: capture.context.on.suspend [80 <- 72], AsyncSuspendData[continuationTypeHnd=0x7fff7980c310, flags=3144, liveLocalsIntervals=[{64, 71},], zeroedLocalsIntervals=[], keepAliveOffset=32]
IR_0083: restore.contexts.on.suspend [72 <- 72 0 16], AsyncSuspendData[continuationTypeHnd=0x7fff7980c310, flags=3144, liveLocalsIntervals=[{64, 71},], zeroedLocalsIntervals=[], keepAliveOffset=32]
IR_0089: handle.continuation.suspend [nil <- 72], AsyncSuspendData[continuationTypeHnd=0x7fff7980c310, flags=3144, liveLocalsIntervals=[{64, 71},], zeroedLocalsIntervals=[], keepAliveOffset=32]
IR_008c: handle.continuation.resume [nil <- nil], AsyncSuspendData[continuationTypeHnd=0x7fff7980c310, flags=3144, liveLocalsIntervals=[{64, 71},], zeroedLocalsIntervals=[], keepAliveOffset=32]
IR_008e: ldind.i8 [96 <- 64], 8
```
This bug was exposed by #127931,
which changed the order of the write to the result var, during resume.
---------
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>1 parent af9da6d commit 12e5b3b
2 files changed
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6451 | 6451 | | |
6452 | 6452 | | |
6453 | 6453 | | |
6454 | | - | |
| 6454 | + | |
| 6455 | + | |
| 6456 | + | |
| 6457 | + | |
| 6458 | + | |
| 6459 | + | |
| 6460 | + | |
| 6461 | + | |
| 6462 | + | |
| 6463 | + | |
| 6464 | + | |
| 6465 | + | |
| 6466 | + | |
6455 | 6467 | | |
6456 | 6468 | | |
6457 | 6469 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4581 | 4581 | | |
4582 | 4582 | | |
4583 | 4583 | | |
4584 | | - | |
| 4584 | + | |
4585 | 4585 | | |
4586 | 4586 | | |
4587 | 4587 | | |
| |||
0 commit comments