Skip to content
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

rustc_apfloat: Panic in Double::mul_add_r #93224

Closed
mjdr opened this issue Jan 23, 2022 · 4 comments · Fixed by rust-lang/rustc_apfloat#1 or #113843
Closed

rustc_apfloat: Panic in Double::mul_add_r #93224

mjdr opened this issue Jan 23, 2022 · 4 comments · Fixed by rust-lang/rustc_apfloat#1 or #113843
Labels
C-bug Category: This is a bug.

Comments

@mjdr
Copy link

mjdr commented Jan 23, 2022

I tried this code and get a panic:

#[test]
fn issue_93224() {
    let r1 = Double::from_bits(0x000000000000002D as u128);
    let r2 = Double::from_bits(0xC2D6C16C166666DE as u128);
    let r3 = Double::from_bits(0x0000000000000055 as u128);

    let _ = r1.mul_add_r(r2, r3, Round::NearestTiesToEven);
}

Meta

Commit: master 17d29dc

Backtrace

thread 'issue_93224' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`', compiler/rustc_apfloat/src/ieee.rs:2545:17
stack backtrace:
   0: rust_begin_unwind
             at /rustc/092e1c9d23158d81be27bb6f71bdd0c6282478fb/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/092e1c9d23158d81be27bb6f71bdd0c6282478fb/library/core/src/panicking.rs:110:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
   4: rustc_apfloat::ieee::sig::add_or_sub
   5: <rustc_apfloat::ieee::IeeeFloat<S> as rustc_apfloat::Float>::mul_add_r
   6: ieee::issue_93224
   7: ieee::issue_93224::{{closure}}
   8: core::ops::function::FnOnce::call_once
   9: core::ops::function::FnOnce::call_once
             at /rustc/092e1c9d23158d81be27bb6f71bdd0c6282478fb/library/core/src/ops/function.rs:227:5

@eddyb
Copy link
Member

eddyb commented Jan 23, 2022

Can you reproduce with LLVM's APFloat? Might even be able to trigger it by getting LLVM to constant-fold FMA (assuming they have as many checks as we do).

@mjdr
Copy link
Author

mjdr commented Jan 25, 2022

This test passes

Add to unittests/ADT/APFloatTest.cpp

TEST(APFloatTest, FMA_issue_93224) {
    uint64_t u1 = 0x000000000000002D;
    uint64_t u2 = 0xC2D6C16C166666DE;
    uint64_t u3 = 0x0000000000000055;

    APFloat f1(*((double*)&u1));
    APFloat f2(*((double*)&u2));
    APFloat f3(*((double*)&u3));
    f1.fusedMultiplyAdd(f2, f3, APFloat::rmNearestTiesToEven);
}

@eddyb
Copy link
Member

eddyb commented Jul 11, 2023

This test passes

@mjdr Did you enable LLVM assertions? I think I independently (re)investigated this bug just now (because fuzzing found it again), and a C++ assert would trigger once I got rid of NDEBUG - see #100233 (comment)

EDIT: forgot it's not fixed yet, but will be once I advance the port enough to reach the upstream fix.

@eddyb
Copy link
Member

eddyb commented Jul 13, 2023

I posted a longer update to #55993 (comment) regarding the progress with the whole rustc_apfloat situation, but of note for this issue is that the WIP repo already has this bug fixed.

@ChrisDenton ChrisDenton added the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Jul 16, 2023
@wesleywiser wesleywiser reopened this Jul 18, 2023
@bors bors closed this as completed in 0d95f91 Jul 26, 2023
@fmease fmease removed the needs-triage-legacy Old issue that were never triaged. Remove this label once the issue has been sufficiently triaged. label Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
5 participants