Skip to content

fix(tests): compare the enabled exception query with the environment the host keeps - #10626

Open
maximilianfv wants to merge 1 commit into
boykopovar:mainfrom
maximilianfv:fix/tests-floating-point-enabled-query-rosetta
Open

maximilianfv wants to merge 1 commit into
boykopovar:mainfrom
maximilianfv:fix/tests-floating-point-enabled-query-rosetta

Conversation

@maximilianfv

@maximilianfv maximilianfv commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

What

CheckEnabledExceptions in core/libs/tests/GuestFloatingPoint.cpp (added in #9216, "feat(libc): implement fegetexcept") writes x87 and MXCSR states with some SSE exceptions unmasked, calls fegetexcept, and required the environment afterwards to equal the state it wrote. Under Rosetta 2 MXCSR keeps its six exception masks set, so whenever the test unmasks an SSE exception the environment read back differs from the state written, and guest_floating_point aborted with enabled exception query preserves control modes and flags although fegetexcept changed nothing.

The test now reads the environment back right after the write and compares the environment after the call with that. On a host that keeps MXCSR as written, the read-back equals the state written, so the check is the same as before there. The fegetexcept result check (enabled exceptions use the x87 masks independently of SSE) is unchanged and passes.

Host behaviour, from a standalone probe (x86_64 under Rosetta 2): MXCSR reads 0x1f80; after writing it with the six exception masks (0x3f << 7) cleared, which is 0, it reads back 0x1f80, so the masks stay set. The Rosetta behaviour is already recorded in docs/dev/debt/libc.md, so the debt file is unchanged.

Precedent: mugurc's #8287 adapted two other checks in this file (CheckFlags, CheckTraps) to the same Rosetta behaviour. Its first commit (65ba3a6) reads the environment back after the write in CheckFlags, which is what this PR does in CheckEnabledExceptions; its second (100148f) has CheckTraps expect the SSE masks the host keeps through HostKeepsSseTraps(). This PR uses the read-back because the check is that fegetexcept changes nothing, which comparing with the read-back states directly. CheckEnabledExceptions was merged after #8287, so #8287 does not cover it. The closed whole-port PR #7332 by ycarogabriel-lgtm had the same CheckFlags read-back a few hours earlier (commit 3bb3929, "test(libc): compare effective floating point masks on Rosetta", 2026-10-20); neither touches CheckEnabledExceptions. The whole-port PRs #7201 and #8658, and the PRs split from #8658 (#10362, #10419), do not touch this test. No open PR changes CheckEnabledExceptions.

Tested

Apple M1 Pro, macOS 27.0.1, x86_64 build under Rosetta 2. main alone does not build on macOS, so this was tested in a tree made of mugurc's macOS series (27e9689) merged with main at 1e20650, plus other unopened macOS fixes, toggling only this change.

guest_floating_point:

  • Without the change: aborts with floating-point environment: enabled exception query preserves control modes and flags.
  • With the change: passes.

Not tested on Linux or Windows. This is a test-only change; on a host that keeps MXCSR as written, the comparison is the same as before.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

…the host keeps

CheckEnabledExceptions writes x87 and MXCSR states with some SSE
exceptions unmasked, calls fegetexcept, and expects the environment
afterwards to equal the state it wrote. Under Rosetta 2 MXCSR keeps its
six exception masks set, as CheckTraps already allows for, so whenever
the test unmasks an SSE exception the state read back differs from the
one written, and the check failed although fegetexcept changed nothing.
Compare with the environment read back right after the write instead;
on other hosts the two are the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 7ce21df27a02852f76eb728b14ea0cc104fe2b95. Reading the effective x87/MXCSR state immediately after WriteEnvironment makes the preservation assertion portable to hosts that refuse to unmask SSE exceptions; the independent fegetexcept result assertion still checks x87 mask decoding and errno preservation. The test restores the seeded state before asserting, as before.

git diff --check upstream/main...HEAD and python3 tools/check_conventions.py --base upstream/main --head HEAD pass. Hosted eligibility, conventions, intake, and labels pass; product jobs were skipped. The Rosetta probe and test result in the PR body are author-reported; I did not independently reproduce them. I found no blocking issue in this test-only fix.

@MarcZX10

Copy link
Copy Markdown
Contributor

Follow-up to the new overlap notice for #8863: I fetched both current PR heads and checked their merge. The changes are in separate portions of GuestFloatingPoint.cpp (#10626 adjusts CheckEnabledExceptions; #8863 adds the feholdexcept test and loader), and git merge-tree --write-tree completed cleanly. I found no required ordering dependency from this shared-file overlap.

@ycbuzi

ycbuzi commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Windows run of 7ce21df27a merged onto main c8d34aa8f4 (d7a2f85dc9, clean). Windows 11 Home 10.0.26200, WinLibs MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release. guest_floating_point builds with no warnings and passes both runs of ctest --repeat until-fail:2, so on a host that keeps MXCSR as written the read-back comparison still holds, as the description expects. Not run: Rosetta. AI-assisted: yes (Claude Code)

@oneandonlydean oneandonlydean self-assigned this Oct 25, 2026

@THEMANnt THEMANnt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 7ce21df27a02852f76eb728b14ea0cc104fe2b95 against author merge base aeeaefad98613c63a49ea2daae4d4558304b14cd.

Approve. No actionable findings in the environment-preservation test correction.

The test now records ReadEnvironment immediately after WriteEnvironment, then compares the query's result with that actual host-retained state. This avoids treating host normalization as a query mutation while retaining the independently computed x87 mask expectation, errno check and restoration of seeded state. Reviewed the complete patch and Read/Write/query helpers.

Validation: head/baseline syntax and conventions/whitespace/registration passed. Focused native programs using each revision's exact CheckEnabledExceptions and environment helpers plus the pinned simple query functions passed all 64×64 mask combinations (4,096 each), linked to the existing libc for errno. Both pass on this CPU, so this is compatibility coverage rather than a reproduced normalization regression. The complete suite could not link to the older DLL, and full pinned FloatingPoint.cpp builds hit GCC Windows SEH assembler errors in other functions. No full-suite or cross-host runtime pass is claimed; hosted native jobs were skipped.

This branch has not been deployed

No deployments
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.

5 participants