Cheng Shao pushed to branch wip/rts-fix-missing-untag at Glasgow Haskell Compiler / GHC Commits: e2a53b7d by Cheng Shao at 2026-07-14T07:11:54+00:00 rts: fix missing UNTAG in stg_readTVarIOzh This patch fixes missing UNTAG on the current value closure read from StgTVar. UNTAG is a no-op when it's stg_TREC_HEADER_info which is word aligned; it may be a tagged closure, and reading info table from the tagged address is an unaligned load which may cause issues on platforms with strict alignment requirements. Co-authored-by: Codex <codex@openai.com> - - - - - 4ec65891 by Cheng Shao at 2026-07-14T07:13:02+00:00 rts: fix missing UNTAG in stg_control0zh_ll This patch fixes missing UNTAG on the cont closure returned by captureContinuationAndAbort. In case it's not NULL, captureContinuationAndAbort returns a tagged StgContinuation closure, in which case it must be untagged before accessing the apply_mask_frame field. In the past it worked out of luck: when apply_mask_frame was NULL then mask_frame_offset is also 0 so the control flow didn't diverge to a wrong path. Still, this is horribly wrong and will crash once StgContinuation struct is refactored and fields are shuffled around. Co-authored-by: Codex <codex@openai.com> - - - - - 2 changed files: - rts/ContinuationOps.cmm - rts/PrimOps.cmm Changes: ===================================== rts/ContinuationOps.cmm ===================================== @@ -108,7 +108,7 @@ stg_control0zh_ll // explicit stack } W_ apply_mask_frame; - apply_mask_frame = StgContinuation_apply_mask_frame(cont); + apply_mask_frame = StgContinuation_apply_mask_frame(UNTAG(cont)); // The stack has been updated, so it’s time to apply the input function, // passing the captured continuation and a RealWorld token as arguments. ===================================== rts/PrimOps.cmm ===================================== @@ -1565,7 +1565,10 @@ stg_readTVarIOzh ( P_ tvar /* :: TVar a */ ) again: result = %acquire StgTVar_current_value(tvar); - resultinfo = %INFO_PTR(result); + // when result is stg_TREC_HEADER_info, it's word aligned so UNTAG + // is no-op; if it's a tagged closure we must UNTAG it to avoid an + // unaligned memory access + resultinfo = %INFO_PTR(UNTAG(result)); if (resultinfo == stg_TREC_HEADER_info) { goto again; } View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/16f553d1e4bda2b0026fb73d4b2204e... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/16f553d1e4bda2b0026fb73d4b2204e... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Cheng Shao (@TerrorJack)