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

panic with "Layout mismatch when copying!" #58742

Closed
mattheww opened this issue Feb 25, 2019 · 5 comments
Closed

panic with "Layout mismatch when copying!" #58742

mattheww opened this issue Feb 25, 2019 · 5 comments
Assignees
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@mattheww
Copy link
Contributor

Running yesterday's nightly rustdoc on the following file panics for me:

const fn one(arr: &[u8; 1]) -> u8 {
    arr[0]
}

const fn two(byte: u8) -> [u8; 1] {[
    byte
]}

const fn three(data: u8) -> u8 {
    one(&two(data))
}

const FOO: u8 = three(0x0);

It says thread 'rustc' panicked at 'Layout mismatch when copying!.

The version is rustdoc 1.34.0-nightly (097c04cf4 2019-02-24).

There isn't a problem compiling the file.

Output including backtrace:

% RUST_BACKTRACE=1 rustdoc +nightly --color=never src/lib.rs
thread 'rustc' panicked at 'Layout mismatch when copying!
src: OpTy {
    op: Indirect(
        MemPlace {
            ptr: Ptr(
                Pointer {
                    alloc_id: AllocId(
                        4
                    ),
                    offset: Size {
                        raw: 0
                    },
                    tag: ()
                }
            ),
            align: Align {
                pow2: 0
            },
            meta: None
        }
    ),
    layout: TyLayout {
        ty: [u8; 1],
        details: LayoutDetails {
            variants: Single {
                index: 0
            },
            fields: Array {
                stride: Size {
                    raw: 1
                },
                count: 1
            },
            abi: Aggregate {
                sized: true
            },
            align: AbiAndPrefAlign {
                abi: Align {
                    pow2: 0
                },
                pref: Align {
                    pow2: 0
                }
            },
            size: Size {
                raw: 1
            }
        }
    }
}
dest: PlaceTy {
    place: Local {
        frame: 0,
        local: _2
    },
    layout: TyLayout {
        ty: u8,
        details: LayoutDetails {
            variants: Single {
                index: 0
            },
            fields: Union(
                0
            ),
            abi: Scalar(
                Scalar {
                    value: Int(
                        I8,
                        false
                    ),
                    valid_range: 0..=255
                }
            ),
            align: AbiAndPrefAlign {
                abi: Align {
                    pow2: 0
                },
                pref: Align {
                    pow2: 0
                }
            },
            size: Size {
                raw: 1
            }
        }
    }
}', src/librustc_mir/interpret/place.rs:826:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   5: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:385
   6: std::panicking::begin_panic_fmt
             at src/libstd/panicking.rs:340
   7: rustc_mir::interpret::place::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::copy_op_no_validate
   8: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::run
   9: rustc_mir::const_eval::eval_body_using_ecx
  10: rustc_mir::const_eval::const_eval_raw_provider
  11: rustc::ty::query::__query_compute::const_eval_raw
  12: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval_raw<'tcx>>::compute
  13: rustc::dep_graph::graph::DepGraph::with_task_impl
  14: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  15: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::const_eval_raw
  16: rustc_mir::interpret::place::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::eval_place_to_mplace
  17: rustc_mir::interpret::place::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::eval_place
  18: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::run
  19: rustc_mir::const_eval::eval_body_using_ecx
  20: rustc_mir::const_eval::const_eval_raw_provider
  21: rustc::ty::query::__query_compute::const_eval_raw
  22: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval_raw<'tcx>>::compute
  23: rustc::dep_graph::graph::DepGraph::with_task_impl
  24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  25: rustc_mir::const_eval::const_eval_provider
  26: rustc::ty::query::__query_compute::const_eval
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval<'tcx>>::compute
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  30: rustc_lint::builtin::check_const
  31: <rustc_lint::register_builtins::BuiltinCombinedLateLintPass as rustc::lint::LateLintPass<'a, 'tcx>>::check_item
  32: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  33: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
  34: rustc::hir::intravisit::walk_crate
  35: rustc::lint::context::check_crate
  36: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::{{closure}}
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc_driver/driver.rs:1333
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/util/common.rs:150
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/util/common.rs:144
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc_driver/driver.rs:1333
  37: rustc::util::common::time
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/util/common.rs:150
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/util/common.rs:144
  38: <std::thread::local::LocalKey<T>>::with
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc_driver/driver.rs:1321
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:2000
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:1966
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:1899
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:1965
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:1999
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:1954
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/libstd/thread/local.rs:300
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/libstd/thread/local.rs:246
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:1946
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/libstd/thread/local.rs:300
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/libstd/thread/local.rs:246
  39: rustc::ty::context::TyCtxt::create_and_enter
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:1938
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:1977
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc/ty/context.rs:1290
  40: rustc_driver::driver::phase_3_run_analysis_passes
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc_driver/driver.rs:1213
  41: <scoped_tls::ScopedKey<T>>::set
             at src/librustdoc/core.rs:494
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc_driver/driver.rs:65
             at /cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-0.1.2/src/lib.rs:155
  42: <scoped_tls::ScopedKey<T>>::set
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/librustc_driver/driver.rs:64
             at src/librustdoc/core.rs:400
             at src/librustdoc/lib.rs:434
             at /cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-0.1.2/src/lib.rs:155
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/libsyntax/lib.rs:100
             at /cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-0.1.2/src/lib.rs:155
  43: syntax::with_globals
             at /rustc/097c04cf433048585dd9e3f63b30e03cc3509e4b/src/libsyntax/lib.rs:99

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.0-nightly (097c04cf4 2019-02-24) running on i686-unknown-linux-gnu
@matthewjasper matthewjasper added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-const-eval Area: Constant evaluation (MIR interpretation) labels Feb 25, 2019
@matthewjasper
Copy link
Contributor

This applies when compiling as well.

Possibly due to #58511 cc @oli-obk @RalfJung

@matthewjasper matthewjasper changed the title rustdoc panics with "Layout mismatch when copying!" panic with "Layout mismatch when copying!" Feb 25, 2019
@Centril Centril added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Feb 26, 2019
@Centril
Copy link
Contributor

Centril commented Feb 26, 2019

This doesn't yet apply to beta but will soon.

@RalfJung
Copy link
Member

So copy_op complains that a [u8; 1] gets copied to a u8. But where does the layout mismatch come from? Almost looks like we fail to adjust the layout when indexing the slice?

@pnkfelix
Copy link
Member

triage: P-high. Speculatively assigning to @oli-obk

@pnkfelix pnkfelix added the P-high High priority label Feb 28, 2019
mattheww added a commit to mattheww/rmicrobit that referenced this issue Mar 10, 2019
This reverts commit 6c1bdf3.

At present this change breaks nightly builds and nightly rustdoc:
rust-lang/rust#58742
@oli-obk
Copy link
Contributor

oli-obk commented Mar 11, 2019

Fixed by #58784

@oli-obk oli-obk closed this as completed Mar 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants