Skip to content

The test f16::test_total_cmp fails in debug mode #141503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
antoyo opened this issue May 24, 2025 · 2 comments · Fixed by #141676
Closed

The test f16::test_total_cmp fails in debug mode #141503

antoyo opened this issue May 24, 2025 · 2 comments · Fixed by #141676
Labels
A-floating-point Area: Floating point numbers and arithmetic A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@antoyo
Copy link
Contributor

antoyo commented May 24, 2025

Hi.
I noticed that the core test f16::test_total_cmp fails when ran in debug mode.
And it passes in release mode.

Here's a small reproducer:

I tried this code:

#![feature(f16)]

use std::cmp::Ordering;

fn q_nan() -> f16 {
    f16::from_bits(f16::NAN.to_bits() | quiet_bit_mask())
}

fn s_nan() -> f16 {
    f16::from_bits((f16::NAN.to_bits() & !quiet_bit_mask()) + 42)
}

fn quiet_bit_mask() -> u16 {
    1 << (f16::MANTISSA_DIGITS - 2)
}

fn main() {
    assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-s_nan()));
}

I expected to see this happen: this test should pass

Instead, this happened: the test fails with:

thread 'main' panicked at src/main.rs:18:5:
assertion `left == right` failed
  left: Less
 right: Greater
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Meta

rustc --version --verbose:

rustc 1.89.0-nightly (3e674b06b 2025-05-23)
binary: rustc
commit-hash: 3e674b06b5c74adea662bd0b0b06450757994b16
commit-date: 2025-05-23
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
Backtrace

thread 'main' panicked at src/main.rs:19:5:
assertion `left == right` failed
  left: Less
 right: Greater
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/3e674b06b5c74adea662bd0b0b06450757994b16/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/3e674b06b5c74adea662bd0b0b06450757994b16/library/core/src/panicking.rs:75:14
   2: core::panicking::assert_failed_inner
             at /rustc/3e674b06b5c74adea662bd0b0b06450757994b16/library/core/src/panicking.rs:432:17
   3: core::panicking::assert_failed
             at /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:387:5
   4: rust_test::main
             at ./src/main.rs:19:5
   5: core::ops::function::FnOnce::call_once
             at /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@antoyo antoyo added the C-bug Category: This is a bug. label May 24, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 24, 2025
@antoyo
Copy link
Contributor Author

antoyo commented May 24, 2025

cc @tgross35

@jieyouxu jieyouxu added T-libs Relevant to the library team, which will review and decide on the PR/issue. A-floating-point Area: Floating point numbers and arithmetic A-testsuite Area: The testsuite used to check the correctness of rustc labels May 24, 2025
tgross35 added a commit to tgross35/rust that referenced this issue May 28, 2025
There is an LLVM bug with lowering of basic `f16` operations that mean a
round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple
`abs` calls or bitcasts [1]. This is problematic because the round trip
quiets signaling NaNs. For most operations this is acceptable, but it is
causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is
resolved.

Fixes: llvm/llvm-project#104915
Fixes: rust-lang#141503

[1]: llvm/llvm-project#104915
@tgross35
Copy link
Contributor

Thanks, this was recently discovered at rust-lang/rustc_codegen_cranelift#1578 too. I opened #141676 with a workaround.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 29, 2025
…workingjubilee

float: Disable `total_cmp` sNaN tests for `f16`

There is an LLVM bug with lowering of basic `f16` operations that mean a round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple `abs` calls or bitcasts [1]. This is problematic because the round trip quiets signaling NaNs. For most operations this is acceptable, but it is causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is resolved.

Fixes: rust-lang/rustc_codegen_cranelift#1578
Fixes: rust-lang#141503

[1]: llvm/llvm-project#104915
@bors bors closed this as completed in 19fd098 May 30, 2025
rust-timer added a commit that referenced this issue May 30, 2025
Rollup merge of #141676 - tgross35:f16-disable-total-cmp, r=workingjubilee

float: Disable `total_cmp` sNaN tests for `f16`

There is an LLVM bug with lowering of basic `f16` operations that mean a round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple `abs` calls or bitcasts [1]. This is problematic because the round trip quiets signaling NaNs. For most operations this is acceptable, but it is causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is resolved.

Fixes: rust-lang/rustc_codegen_cranelift#1578
Fixes: #141503

[1]: llvm/llvm-project#104915
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 30, 2025
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Jun 3, 2025
There is an LLVM bug with lowering of basic `f16` operations that mean a
round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple
`abs` calls or bitcasts [1]. This is problematic because the round trip
quiets signaling NaNs. For most operations this is acceptable, but it is
causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is
resolved.

Fixes: rust-lang/rustc_codegen_cranelift#1578
Fixes: rust-lang#141503

[1]: llvm/llvm-project#104915
github-actions bot pushed a commit to model-checking/verify-rust-std that referenced this issue Jun 3, 2025
…workingjubilee

float: Disable `total_cmp` sNaN tests for `f16`

There is an LLVM bug with lowering of basic `f16` operations that mean a round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple `abs` calls or bitcasts [1]. This is problematic because the round trip quiets signaling NaNs. For most operations this is acceptable, but it is causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is resolved.

Fixes: rust-lang/rustc_codegen_cranelift#1578
Fixes: rust-lang#141503

[1]: llvm/llvm-project#104915
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-floating-point Area: Floating point numbers and arithmetic A-testsuite Area: The testsuite used to check the correctness of rustc C-bug Category: This is a bug. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants