Skip to content

Miscompilation with -Zmir-opt-level=2 #67529

Closed
@bjorn3

Description

@bjorn3

Derived from https://github.com/rust-lang/rust/blob/26286c7ad0e8a5efc1e6a8ef88ffd64723112ae8/src/test/ui/dynamically-sized-types/dst-field-align.rs

struct Baz<T: ?Sized> {
    a: T
}

fn main() {
    let d : Baz<[i32; 4]> = Baz { a: [1,2,3,4] };
    assert_eq!([1, 2, 3, 4], d.a);
}
$ rustc -V
rustc 1.42.0-nightly (fc5deca21 2019-12-21)
$ rustc example/dst-field-align.rs && ./dst-field-align
$ rustc -Zmir-opt-level=2 example/dst-field-align.rs && ./dst-field-align
thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `[1, 2, 3, 4]`,
 right: `[0, 0, 0, 0]`', example/dst-field-align.rs:10:5

struct Baz<T: ?Sized> {
    a: T
}

fn main() {
    let d : Baz<[i32; 4]> = Baz { a: [1,2,3,4] };
    println!("{:?}", d.a);
}
$ rustc example/dst-field-align.rs && ./dst-field-align
[1, 2, 3, 4]
$ rustc -Zmir-opt-level=2 example/dst-field-align.rs && ./dst-field-align
[0, 0, 0, 0]

This issue has been assigned to @jumbatm via this comment.

Metadata

Metadata

Assignees

Labels

A-MIRArea: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.htmlC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions