Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.4k stars 155 forks source link

unexpected results from bitwise complement operator `!` #3229

Open nobel-sh opened 1 week ago

nobel-sh commented 1 week ago

The ! operator produces unexpected results.

fn main(){
   let a: i32 = 5;
   let b = !a; // expected -6 gccrs gives 0.
}

Godbolt: https://godbolt.org/z/cKPPz1bYc

nobel-sh commented 1 week ago

I'm not entirely sure, but it seems that the operator is interpreting the least significant bit of the number as a boolean value and complementing it.