Rust-GCC / Rust-GCC/gccrs

miscompiling i32 overflow

Open
#404 17 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug GCC
Dominant language
C++
Stars
2.9k
Forks
230
Avg merge
19h 55m
Merged PRs (30d)
67

Description

https://rust.godbolt.org/z/coK3hz5aE

pub fn f(a: i32) -> i32 {
    if a + 1 == -0x80000000i32 {
        1
    } else {
        0
    }
}

is miscompiled to:

__f:
        xorl    %eax, %eax
        ret

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 Rust example and compiler output in the linked Godbolt case. Reproduce the function and compare its generated assembly with the expected behavior for i32 overflow. Done means the compiler no longer reduces this case to an unconditional zero result.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.