Skip to content

f16 -> i128 cast has wrong behavior on aarch64-linux #164972

Open

Description

@RalfJung

The Miri tests/pass/float.rs test fails on aarch64-Linux:

  thread 'main' (17742) panicked at tests/pass/float.rs:581:5:
  assertion `left == right` failed: f16 -> i128: negative one
    left: 18446744073709551615
   right: -1

Seems like LLVM is miscompiling that cast.

@folkertdev wrote

LLVM is doing something weird for saturating conversions on -O0 (which for aarch64 uses GISel, while higher levels, and most other backends, use SelectionDAG). Fun.

https://godbolt.org/z/PM1Y4nx6x

Cc @nikic

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 26, 2026
  2. changed the title [-]f16 -> i128 has wrong behavior on aarch64-linux[/-] [+]f16 -> i128 cast has wrong behavior on aarch64-linux[/+] on Oct 26, 2026
  3. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    WG-llvmWorking group: LLVM backend code generation
    on Oct 26, 2026
  4. folkertdev commented on Oct 26, 2026

    @folkertdev
    Contributor

    Looks to me like an incorrect copy of logic from the non-saturating to the saturating version, I've opened

    Which should fix this and can hopefully be backported.

  5. added
    I-miscompileIssue: Correct Rust code lowers to incorrect machine code
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 26, 2026
  6. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.F-f16_and_f128`#![feature(f16)]`, `#![feature(f128)]`I-miscompileIssue: Correct Rust code lowers to incorrect machine codeT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-llvmWorking group: LLVM backend code generation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions