rust-lang / rust-lang/rust

debug assertion: Post-projection layout should be non-Ref, but it's...

Open
#149,191 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-codegen A-LLVM A-rustlantis C-bug I-crash I-ICE T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

#![feature(custom_mir, core_intrinsics)]

use std::intrinsics::mir::*;

#[custom_mir(dialect = "runtime", phase = "initial")]
fn main() {
    mir!{
        let _49: (Adt24,);
        let _63: *const Adt24;
        {
            (*_63) = _49.0;
            Return()
        }
    }
}

enum Adt24 {
    Variant1 {
        fld0: f64,
    },
    Variant2 {
        fld0: u64,
    },
}

Will hit a debug assertion:

thread 'rustc' (3695161) panicked at /home/ben/rust/compiler/rustc_codegen_ssa/src/mir/analyze.rs:159:13:
Post-projection (_1.0: Adt24) layout should be non-Ref, but it's TyAndLayout { ty: Adt24, layout: Layout { size: Size(16 bytes), align: AbiAlign { abi: Align(8 bytes) }, backend_repr: Memory { sized: true }, fields: Arbitrary { offsets: [Size(0 bytes)], memory_index: [0] }, largest_niche: Some(Niche { offset: Size(0 bytes), value: Int(I64, false), valid_range: 0..=1 }), uninhabited: false, variants: Multiple { tag: Initialized { value: Int(I64, false), valid_range: 0..=1 }, tag_encoding: Direct, tag_field: 0, variants: [Layout { size: Size(16 bytes), align: AbiAlign { abi: Align(8 bytes) }, backend_repr: Memory { sized: true }, fields: Arbitrary { offsets: [Size(8 bytes)], memory_index: [0] }, largest_niche: None, uninhabited: false, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), randomization_seed: 1530056383329300088 }, Layout { size: Size(16 bytes), align: AbiAlign { abi: Align(8 bytes) }, backend_repr: Memory { sized: true }, fields: Arbitrary { offsets: [Size(8 bytes)], memory_index: [0] }, largest_niche: None, uninhabited: false, variants: Single { index: 1 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), randomization_seed: 1530056379034332792 }] }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), randomization_seed: 4590169132808031073 } }

https://github.com/rust-lang/rust/pull/144347 added the assertion.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied custom MIR program and inspect rustc_codegen_ssa/src/mir/analyze.rs at the assertion location. Read PR 144347 for the change that added the assertion and trace the post-projection layout handling. Done means this reproduction no longer triggers the debug assertion, with the affected layout behavior checked by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.