Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unaligned raw references are considered UB #1339

Closed
RalfJung opened this issue Apr 16, 2020 · 1 comment · Fixed by #1348
Closed

Unaligned raw references are considered UB #1339

RalfJung opened this issue Apr 16, 2020 · 1 comment · Fixed by #1348
Labels
A-aliasing Area: This affects the aliasing model (Stacked/Tree Borrows) A-interpreter Area: affects the core interpreter C-bug Category: This is a bug. I-false-UB Impact: makes Miri falsely report UB, i.e., a false positive (with default settings)

Comments

@RalfJung
Copy link
Member

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.

@RalfJung RalfJung added C-bug Category: This is a bug. A-aliasing Area: This affects the aliasing model (Stacked/Tree Borrows) A-interpreter Area: affects the core interpreter labels Apr 16, 2020
@RalfJung
Copy link
Member Author

The last two executed MIR statements are:

[INFO  rustc_mir::interpret::step] _170 = &raw const (_1.1: i32)
[INFO  rustc_mir::interpret::step] Retag([raw] _170)

So the issue is that raw retags incorrectly assert proper alignment.

@RalfJung RalfJung added the I-false-UB Impact: makes Miri falsely report UB, i.e., a false positive (with default settings) label Apr 16, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Apr 22, 2020
Miri: mplace_access_checked: offer option to force different alignment on place

Required to solve rust-lang/miri#1339 in rust-lang/miri#1348.

r? @oli-obk
@bors bors closed this as completed in 26baf87 Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-aliasing Area: This affects the aliasing model (Stacked/Tree Borrows) A-interpreter Area: affects the core interpreter C-bug Category: This is a bug. I-false-UB Impact: makes Miri falsely report UB, i.e., a false positive (with default settings)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant