Skip to content

test(numerics): build cfenv_test with -frounding-math on GCC - #375

Merged
homer6 merged 1 commit into
devfrom
test/371-cfenv-rint
Nov 3, 2026
Merged

homer6 merged 1 commit into
devfrom
test/371-cfenv-rint

Conversation

@homer6

@homer6 homer6 commented Nov 3, 2026

Copy link
Copy Markdown
Owner

Summary

  • Cfenv.RoundingModes failed in the GCC 16 hardened job. That build is -O2 (RelWithDebInfo), and there GCC on x86-64 expands std::rint inline as the rounded magnitude with the sign copied back, so a volatile -2.5 under FE_UPWARD gives -3.
  • tests/CMakeLists.txt builds numerics/cfenv_test.cpp with -frounding-math on GCC, which is GCC's documented flag for code that changes the rounding mode. The test's header comment no longer claims an -O0 build.
  • docs/examples/numerics/cfenv.md Gotchas: records the finding and says to build such code with -frounding-math on GCC.

Related

Test plan

  • Minimal repro, gcc:16 amd64:
    • -O0: -2;
    • -O2: -3, with or without a separate volatile;
    • -O2 -frounding-math: -2;
    • arm64 -O2: -2.
  • gcc-16-hardened on linux/amd64 (emulated, as CI): Cfenv.* 9/9 pass.
  • Cfenv.* on GCC 15 (Debug) and GCC 16 arm64: 9/9.
  • Snippets on cfenv.md: GCC 15, Clang 22, GCC 16, each 5 checked, 0 failed.

The hardened presets build at -O2, where GCC on x86-64 expands std::rint inline as the rounded magnitude with the sign copied back; rint(-2.5) under FE_UPWARD gave -3. -frounding-math, GCC's documented flag for code that changes the rounding mode, keeps it correct. The cfenv page's Gotchas record the finding.

Related to #371
@homer6 homer6 self-assigned this Nov 3, 2026
@homer6
homer6 merged commit 737995a into dev Nov 3, 2026
@homer6
homer6 deleted the test/371-cfenv-rint branch November 3, 2026 17:30
@homer6

homer6 commented Nov 3, 2026

Copy link
Copy Markdown
Owner Author

Merged into dev as a merge commit (737995a) on Steve's review ("merge all that have no risks"; none found).

Checked: gcc-16-hardened on linux/amd64 (as CI), Cfenv 9/9; Cfenv 9/9 on GCC 15 and GCC 16 arm64; cfenv.md snippets 5 checked/0 failed on GCC 15, Clang 22 and GCC 16. Not re-run during review.

Still owed: the v0.5.0 workflow re-run on dev (#363).

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.

1 participant