Skip to content

ARM Big Endian partialEq bug #157239

@NielsOuvrard

Description

@NielsOuvrard

At opt-level=0, derived PartialEq on enums produces incorrect results on armebv7r-none-eabi (big-endian) when built with -Z build-std=core. The comparison returns true for non-equal values. opt-level≥1 or manual match-based PartialEq works correctly.
#[repr(u8)] does not mitigate it.

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum MyEnum { A, B, C, D }

let a = MyEnum::A;

// BUG: returns true at opt-level=0 on armebv7r-none-eabi
if a == MyEnum::B {
    // reached
}

// OK: match always works
match a {
    MyEnum::A => { /* reached correctly */ }
    MyEnum::B => { /* not reached correctly */ }
    _ => {}
}

Minimal error reproduction's repo:

https://github.com/NielsOuvrard/rust-arm-be-partialeq-bug

Workaround

Set opt-level = 1 in Cargo.toml

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.E-needs-bisectionCall for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcI-miscompileIssue: Correct Rust code lowers to incorrect machine codeI-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}O-ArmTarget: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 stateT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    To Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions