rust-lang / rust-lang/rustc_codegen_gcc

Another UB found using rustlantis

Open
#691 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
1.2k
Forks
105
Avg merge
8h 20m
Merged PRs (30d)
14

Description

This program has a different result under GCC debug and GCC release.

2 1 //debug
2 -1 // release
fn dump_var(var2: usize, val2: usize, var3: usize) {
    println!("val2:{val2}")
}
#[inline(never)]
fn dump_var2(var2: usize, val2: usize, var3: usize) {
    println!("val2:{val2}")
}
fn fn6(arg: bool, arg2: usize) -> bool {
    dump_var(0, arg2, 0);
    dump_var2(0, !arg as usize, 0);
    true
}
fn main() {
    let mut _1 = false;
    let mut _3 = 2;
    let mut _4 = (&1, 1);
    loop {
        if _4.1 == 0 {
            if _4.1 == 1 {
                _1 = true;
            } else {
                _1 = false;
            }
        } else if fn6(_1, _3) {
            loop {
                _3 = _4.1;
                let mut _6 = 0;
                _6 = 0;
                let tmp2 = _6;
                if tmp2 == 1 {
                    _4.0 = &_4.1
                } else if tmp2 == 0 {
                    return;
                } else {
                    break;
                }
            }
        }
    }
}

It looks like the cast of val as i128 is nonsensical. Since val is a boolean value, one would expect it to be either 1 or 0, and not -1.

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 by compiling and running the supplied Rust reproducer with GCC in debug and release modes, then trace the boolean-to-integer cast mentioned in the report. The issue is resolved when the cast consistently produces the expected boolean values rather than differing between builds.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.