Skip to content

Commit f29ffbb

Browse files
T-GroCopilot
andcommitted
Fix byref capture in GenStructStateMachine and Env stack tracking
- GenStructStateMachine: use GenGetFreeVarForClosure (like all other closure paths) to properly dereference byrefs when initializing captured variables in struct state machine closures. - GenGetStorageAndSequel Env case: use ilField.ActualType instead of ilTy for the Push annotation so the stack tracking matches the actual type loaded by ldfld (important when byref is stripped by capturedTypeForFreeVar). Co-authored-by: Copilot <[email protected]>
1 parent e2ddcab commit f29ffbb

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

src/Compiler/CodeGen/IlxGen.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6352,7 +6352,7 @@ and GenStructStateMachine cenv cgbuf eenvouter (res: LoweredStateMachine) sequel
63526352
else
63536353
// initialize the captured var
63546354
CG.EmitInstr cgbuf (pop 0) (Push [ ilMachineAddrTy ]) (I_ldloc(uint16 locIdx2))
6355-
GenGetLocalVal cenv cgbuf eenvouter m fv None
6355+
GenGetFreeVarForClosure cenv cgbuf eenvouter m fv
63566356
CG.EmitInstr cgbuf (pop 2) (Push []) (mkNormalStfld (mkILFieldSpecInTy (ilCloTy, ilv.fvName, ilv.fvType)))
63576357

63586358
// Generate the start expression
@@ -9876,7 +9876,7 @@ and GenGetStorageAndSequel (cenv: cenv) cgbuf eenv m (ty, ilTy) storage storeSeq
98769876
CommitGetStorageSequel cenv cgbuf eenv m ty None storeSequel
98779877

98789878
| Env(_, ilField, localCloInfo) ->
9879-
CG.EmitInstrs cgbuf (pop 0) (Push [ ilTy ]) [ mkLdarg0; mkNormalLdfld ilField ]
9879+
CG.EmitInstrs cgbuf (pop 0) (Push [ ilField.ActualType ]) [ mkLdarg0; mkNormalLdfld ilField ]
98809880
CommitGetStorageSequel cenv cgbuf eenv m ty localCloInfo storeSequel
98819881

98829882
/// Load free variables for closure capture, dereferencing byrefs.

0 commit comments

Comments
 (0)