Commit c50b65e
committed
Fix issue with branching to swapped stfld -> callvirt
Given the (abridged) psuedo-IL
```asm
ldfld PlayerData ...
ldfld bool ...
brtrue.s :opt
ldfld string ..
br.s :set
opt:
ldfld string ...
set: stfld PlayerData::someField
```
We were patching it to the following:
```asm
ldfld PlayerData ...
ldfld bool ...
brtrue.s :opt
ldfld string ...
br.s :set
opt:
ldfld string ...
ldstr "someField"
set: callvirt instance void PlayerData::SetStringSwappedArgs(string, string)
```
and the way we did this patching is by swapping an `stfld` to a `callvirt`
and then inserting the `ldstr` for the field name (which is the second arg
for our SetStringSwappedArgs) before this `callvirt` we inserted.
However, given this situation, we skip over the ldstr of the field name
when coming from the `false` branch path as it branches directly to
`set` as it had previously branched directly to an `stfld` and branching
is instruction location based.
The fix for this is relatively simple, just swap the `stfld` with the
`ldstr` instead, and then insert our `callvirt` afterwards, which gives
the following:
```asm
ldfld PlayerData ...
ldfld bool ...
brtrue.s :opt
ldfld string ...
br.s :set
opt:
ldfld string ...
set: ldstr "someField"
callvirt instance void PlayerData::SetStringSwappedArgs(string, string)
```1 parent 1472b8f commit c50b65e
1 file changed
+8
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
208 | 208 | | |
209 | 209 | | |
210 | 210 | | |
| 211 | + | |
| 212 | + | |
211 | 213 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 214 | + | |
| 215 | + | |
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
| 262 | + | |
| 263 | + | |
262 | 264 | | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
| 265 | + | |
| 266 | + | |
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
| |||
0 commit comments