Skip to content

f64::round doesn't work properly on arm-unknown-linux-gnueabi #122294

Open
@vklachkov

Description

@vklachkov

I'm cross-compiling for target arm-unknown-linux-gnueabi, and I encountered that f64::round() does not work correctly. I tried this code:

fn main() {
    let value: f64 = 15.44;
    dbg!(value);
    dbg!(value.round());
}

I expected to see:

[bug/src/main.rs:3:5] value = 15.44
[bug/src/main.rs:4:5] value.round() = 15.0

But instead, in the debug build I see:

[bug/src/main.rs:3:5] value = 15.44
[bug/src/main.rs:4:5] value.round() = 0.0

In the release build, as a rule, the output is correct, but sometimes f64::round() returning 0 or 1 instead of the correct rounding. I can't reliably reproduce this bug in release build.

I build this code in docker container. See more details under the spoiler.

Build details

I build code with this command:

docker build -f Dockerfile -t build_image .

docker run \
  -v $HOME/.cargo/registry:/root/.cargo/registry \
  -v $(pwd):/src \
  -t build_image

Dockerfile:

FROM debian:11-slim

# Install Rust
RUN apt-get update && apt-get install -y curl
RUN curl https://sh.rustup.rs -sSf | bash -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Install tools
RUN apt-get update && apt-get install -y \
    crossbuild-essential-armel

# Install target for ARMv6
RUN rustup target add arm-unknown-linux-gnueabi

# Build
RUN mkdir -p /src
WORKDIR /src

# Remove --release for debug build
CMD cargo build --release --target=arm-unknown-linux-gnueabi

Cargo.toml:

[package]
name = "bug"
version = "0.1.0"
edition = "2021"

[dependencies]

[profile.release]
opt-level = 3
strip = "debuginfo"
panic = "abort"

.cargo/config.toml:

[target.arm-unknown-linux-gnueabi]
linker = "arm-linux-gnueabi-gcc"
rustflags = ["-L", "/usr/lib/arm-linux-gnueabi"]

binaries.tar.gz
source.tar.gz

Meta

rustc --version --verbose:

rustc 1.76.0 (07dca489a 2024-02-04)                                                                                                                                                           
binary: rustc                                                                                                                                                                                 
commit-hash: 07dca489ac2d933c78d3c5158e3f43beefeb02ce                                                                                                                                         
commit-date: 2024-02-04                                                                                                                                                                       
host: x86_64-unknown-linux-gnu
release: 1.76.0
LLVM version: 17.0.6

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.E-needs-investigationCall for partcipation: This issues needs some investigation to determine current statusI-miscompileIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-ArmTarget: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 stateP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions