Add -Zmips-nan2008 to enable IEEE 754-2008 NaN encoding on MIPS#159565
Draft
fo40225 wants to merge 1 commit into
Draft
Add -Zmips-nan2008 to enable IEEE 754-2008 NaN encoding on MIPS#159565fo40225 wants to merge 1 commit into
fo40225 wants to merge 1 commit into
Conversation
This comment has been minimized.
This comment has been minimized.
Add a new unstable flag -Zmips-nan2008 that injects the LLVM nan2008 subtarget feature on MIPS targets, selecting the IEEE 754-2008 NaN encoding instead of the legacy MIPS encoding. This makes it possible to link against MIPS libraries and toolchains built with GCC's -mnan=2008. The option is registered as a target modifier, so mixing crates compiled with different values of the flag is a hard error at link time, bypassable with -Cunsafe-allow-abi-mismatch=mips-nan2008. Using the flag on non-MIPS architectures is a fatal error.
fo40225
force-pushed
the
fix_mips_nan2008_tm
branch
from
July 19, 2026 15:22
4a684cf to
5b0f115
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add a new unstable compiler flag
-Zmips-nan2008that enables the IEEE 754-2008 NaN encoding on MIPS targets by injecting the LLVM+nan2008target feature.Motivation
MIPS hardware and software ecosystems can be built with either the legacy MIPS NaN encoding or the IEEE 754-2008 NaN encoding. GCC's
-mnan=2008flag selects the 2008 encoding, and some system ABIs (particularly for MIPS Release 6 cores and certain vendor toolchains) mandate it. When linking Rust code against C libraries or system code compiled with-mnan=2008, the NaN encoding must match across the entire binary to avoid runtime failures and undefined behavior.Currently, Rust has no way to select the 2008 NaN encoding, making it impossible to interoperate with such ecosystems without resorting to custom target JSON specifications. This PR adds an explicit, architecture-gated unstable flag to enable the feature safely.
What this PR does
-Zmips-nan2008(unstable): when set, injects+nan2008into the LLVM feature string for MIPS targets. The flag is only accepted onmips,mips32r6,mips64, andmips64r6architectures; attempting to use it on other architectures emits a fatal diagnostic (MipsNan2008InvalidArch).[TRACKED] { TARGET_MODIFIER: MipsNan2008 }inoptions.rs, so linking crates compiled with different values is a hard error by default (leveraging the existing target-modifier machinery). The error can be bypassed with-Cunsafe-allow-abi-mismatch=mips-nan2008if the user knows the ABIs are actually compatible.llvm_util.rs, thellvm_features_by_flags()function now checkssess.opts.unstable_opts.mips_nan2008and appends+nan2008to the feature vector when the target architecture is a MIPS variant; otherwise it emits the fatal diagnostic.compiler-flags/mips-nan2008.mdwith usage examples and ABI compatibility warnings.Tests
tests/ui/target_modifiers/incompatible_mips_nan2008.rs(+ auxiliary cratemips_nan2008.rs): verifies the target-modifier mismatch error is emitted when linking crates with conflicting-Zmips-nan2008settings, the error can be suppressed with-Cunsafe-allow-abi-mismatch=mips-nan2008, and matching settings compile cleanly. Mirrors the structure ofincompatible_fixedx18.rs.tests/codegen-llvm/mips-nan2008.rs: checks that the+nan2008feature appears (or does not appear) in the LLVM"target-features"function attribute depending on whether the flag is set.compiler/rustc_interface/src/tests.rsto track the newmips_nan2008option in the tracked-options test.