Skip to content

Unaligned raw references are considered UB #1339

Closed
@RalfJung

Description

@RalfJung

The following program should pass, but is incorrectly considered UB:

#![feature(raw_ref_op)]

fn main() {
    #[repr(packed)]
    struct S {
        fill: u8,
        a: i32,
        b: i64,
    }

    let mut x = S {
        fill: 0,
        a: 42,
        b: 99,
    };

    assert_eq!(unsafe { (&raw const x.a).read_unaligned() }, 42);
    assert_eq!(unsafe { (&raw const x.b).read_unaligned() }, 99);
}

The error source seems to be related to Stacked Borrows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-aliasingArea: This affects the aliasing model (Stacked/Tree Borrows)A-interpreterArea: affects the core interpreterC-bugCategory: This is a bug.I-false-UBImpact: makes Miri falsely report UB, i.e., a false positive (with default settings)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions