Skip to content

Rustc test exhibits UB? (or MIR optimizations are broken) #43358

@oli-obk

Description

@oli-obk

https://github.com/rust-lang/rust/blob/b1363a73ede57ae595f3a1be2bb75d308ba4f7f6/src/test/run-pass/cast-rfc0401-vtable-kinds.rs prints nothing if run without mir optimizations and triggers assert_eq!(fl, (43+4)); if run with mir optimizations.

The critical code is

unsafe fn round_trip_and_call<'a>(t: *const (Foo<u32>+'a)) -> u32 {
    let foo_e : *const Foo<u16> = t as *const _;
    let r_1 = foo_e as *mut Foo<u32>;

    (&*r_1).foo(0)
}

Found by miri

cc @arielb1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions