rust-lang / rust-lang/rust

ARM Big Endian partialEq bug

Open
#157,239 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug E-needs-bisection I-miscompile I-prioritize O-Arm T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproduction repository and build it for armebv7r-none-eabi with opt-level=0, then compare the derived PartialEq behavior with opt-level≥1 and the manual match workaround. Trace the Rust compiler path that lowers derived enum comparisons on big-endian targets; done means non-equal enum values compare unequal at opt-level=0 and the behavior has regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.