rustc_codegen_gcc: Some mirunsafeck and thirunsafeck tests failing with weird assert failure

---- [ui] ui/union/union-overwrite.rs#mirunsafeck stdout ----

error in revision `mirunsafeck`: test run failed!
status: signal: 6 (core dumped)
command: "/Projets/rustc_codegen_gccjit/rust/build/x86_64-unknown-linux-gnu/test/ui/union/union-overwrite.mirunsafeck/a"
stdout:
------------------------------------------

------------------------------------------
stderr:
------------------------------------------
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `57022`,
 right: `57022`', /Projets/rustc_codegen_gccjit/rust/src/test/ui/union/union-overwrite.rs:34:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

That happens only when compiled in release mode, not in debug mode.

Example:

union U {
    a: (u8, u8),
    b: u16,
}

union W {
    a: u32,
    b: f32,
}

fn main() {
    unsafe {
        let mut u = U { a: (1, 1) };
        assert_eq!(u.b, (1 << 8) + 1);
        u.b = (2 << 8) + 2;
        assert_eq!(u.a, (2, 2));

        let mut w = W { a: 0b0_11111111_00000000000000000000000 };
        assert_eq!(w.b, f32::INFINITY);
        w.b = f32::NEG_INFINITY;
        assert_eq!(w.a, 0b1_11111111_00000000000000000000000);
    }
}

gives:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `(2, 2)`,
 right: `(2, 2)`', src/main.rs:16:9

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

Does -fno-strict-aliasing fix this?

Maybe minimized it a bit more:

fn main() {
    unsafe {
        let mut u = 0xDE_DE_u16;
        *(&mut u as *mut _ as *mut u8) = 0xBE;
        let a = &u;
        let b = *a;
        println!("a={:?}, *a={:?}, b={:?}", a, *a, b);
    }
}

prints:

a=57022, *a=57022, b=57054