Skip to content

ICE: write_immediate_to_mplace: invalid Scalar layout: TyAndLayout #124464

New issue

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

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

Already on GitHub? # to your account

Closed
matthiaskrgr opened this issue Apr 28, 2024 · 1 comment · Fixed by #126045
Closed

ICE: write_immediate_to_mplace: invalid Scalar layout: TyAndLayout #124464

matthiaskrgr opened this issue Apr 28, 2024 · 1 comment · Fixed by #126045
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Apr 28, 2024

snippet:

enum TestOption<T> {
    TestSome(T),
    TestSome(T),
}

pub struct Request {
    bar: TestOption<u64>,
    bar: u8,
}

fn default_instance() -> &'static Request {
    static instance: Request = Request { bar: 17 };
    &instance
}

pub fn main() {}

Version information

rustc 1.79.0-nightly (61a1dbd75 2024-04-27)
binary: rustc
commit-hash: 61a1dbd751ab7f3c973be17d7ff3948ffda07c6e
commit-date: 2024-04-27
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0428]: the name `TestSome` is defined multiple times
 --> /tmp/icemaker_global_tempdir.mZAvp7BLyNNo/rustc_testrunner_tmpdir_reporting.HOQFBNQrvTzP/mvce.rs:3:5
  |
2 |     TestSome(T),
  |     ----------- previous definition of the type `TestSome` here
3 |     TestSome(T),
  |     ^^^^^^^^^^^ `TestSome` redefined here
  |
  = note: `TestSome` must be defined only once in the type namespace of this enum

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.mZAvp7BLyNNo/rustc_testrunner_tmpdir_reporting.HOQFBNQrvTzP/mvce.rs:14:2
   |
14 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.mZAvp7BLyNNo/rustc_testrunner_tmpdir_reporting.HOQFBNQrvTzP/mvce.rs`

error[E0124]: field `bar` is already declared
 --> /tmp/icemaker_global_tempdir.mZAvp7BLyNNo/rustc_testrunner_tmpdir_reporting.HOQFBNQrvTzP/mvce.rs:8:5
  |
7 |     bar: TestOption<u64>,
  |     -------------------- `bar` first declared here
8 |     bar: u8,
  |     ^^^^^^^ field already declared

error: internal compiler error: compiler/rustc_const_eval/src/interpret/place.rs:695:21: write_immediate_to_mplace: invalid Scalar layout: TyAndLayout {
                                    ty: TestOption<u64>,
                                    layout: Layout {
                                        size: Size(16 bytes),
                                        align: AbiAndPrefAlign {
                                            abi: Align(8 bytes),
                                            pref: Align(8 bytes),
                                        },
                                        abi: ScalarPair(
                                            Initialized {
                                                value: Int(
                                                    I64,
                                                    false,
                                                ),
                                                valid_range: 0..=1,
                                            },
                                            Initialized {
                                                value: Int(
                                                    I64,
                                                    false,
                                                ),
                                                valid_range: 0..=18446744073709551615,
                                            },
                                        ),
                                        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,
                                            },
                                        ),
                                        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: AbiAndPrefAlign {
                                                        abi: Align(8 bytes),
                                                        pref: Align(8 bytes),
                                                    },
                                                    abi: ScalarPair(
                                                        Initialized {
                                                            value: Int(
                                                                I64,
                                                                false,
                                                            ),
                                                            valid_range: 0..=1,
                                                        },
                                                        Initialized {
                                                            value: Int(
                                                                I64,
                                                                false,
                                                            ),
                                                            valid_range: 0..=18446744073709551615,
                                                        },
                                                    ),
                                                    fields: Arbitrary {
                                                        offsets: [
                                                            Size(8 bytes),
                                                        ],
                                                        memory_index: [
                                                            0,
                                                        ],
                                                    },
                                                    largest_niche: None,
                                                    variants: Single {
                                                        index: 0,
                                                    },
                                                    max_repr_align: None,
                                                    unadjusted_abi_align: Align(8 bytes),
                                                },
                                                Layout {
                                                    size: Size(16 bytes),
                                                    align: AbiAndPrefAlign {
                                                        abi: Align(8 bytes),
                                                        pref: Align(8 bytes),
                                                    },
                                                    abi: ScalarPair(
                                                        Initialized {
                                                            value: Int(
                                                                I64,
                                                                false,
                                                            ),
                                                            valid_range: 0..=1,
                                                        },
                                                        Initialized {
                                                            value: Int(
                                                                I64,
                                                                false,
                                                            ),
                                                            valid_range: 0..=18446744073709551615,
                                                        },
                                                    ),
                                                    fields: Arbitrary {
                                                        offsets: [
                                                            Size(8 bytes),
                                                        ],
                                                        memory_index: [
                                                            0,
                                                        ],
                                                    },
                                                    largest_niche: None,
                                                    variants: Single {
                                                        index: 1,
                                                    },
                                                    max_repr_align: None,
                                                    unadjusted_abi_align: Align(8 bytes),
                                                },
                                            ],
                                        },
                                        max_repr_align: None,
                                        unadjusted_abi_align: Align(8 bytes),
                                    },
                                }
  --> /tmp/icemaker_global_tempdir.mZAvp7BLyNNo/rustc_testrunner_tmpdir_reporting.HOQFBNQrvTzP/mvce.rs:12:32
   |
12 |     static instance: Request = Request { bar: 17 };
   |                                ^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/place.rs:695:21:
Box<dyn Any>
stack backtrace:
   0:     0x7596993ad015 - std::backtrace_rs::backtrace::libunwind::trace::h6158d363611d1453
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7596993ad015 - std::backtrace_rs::backtrace::trace_unsynchronized::h12dc967c8d1dec91
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7596993ad015 - std::sys_common::backtrace::_print_fmt::h40bbbf8d4eaf0656
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7596993ad015 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h862ef14a800157bd
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7596993fc27b - core::fmt::rt::Argument::fmt::h275a6021db05125f
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/core/src/fmt/rt.rs:165:63
   5:     0x7596993fc27b - core::fmt::write::h5cdd42231e80f009
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/core/src/fmt/mod.rs:1157:21
   6:     0x7596993a1bbf - std::io::Write::write_fmt::hc5acdd2d8783f48a
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/io/mod.rs:1832:15
   7:     0x7596993acdee - std::sys_common::backtrace::_print::h275122974a2084b9
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7596993acdee - std::sys_common::backtrace::print::h87a148a259dab94c
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7596993af759 - std::panicking::default_hook::{{closure}}::h6fa5aa86e7f60250
  10:     0x7596993af49d - std::panicking::default_hook::h96ecfa2333ca15ac
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/panicking.rs:298:9
  11:     0x759695c345db - std[38e62313bc239a56]::panicking::update_hook::<alloc[1469ad075796f7fa]::boxed::Box<rustc_driver_impl[8807ebb1224e5aed]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7596993afe56 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h4a767a51eeef82de
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/alloc/src/boxed.rs:2036:9
  13:     0x7596993afe56 - std::panicking::rust_panic_with_hook::he77c771cacb9d53e
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/panicking.rs:799:13
  14:     0x759695c64794 - std[38e62313bc239a56]::panicking::begin_panic::<rustc_errors[af9b09486d396f0e]::ExplicitBug>::{closure#0}
  15:     0x759695c61416 - std[38e62313bc239a56]::sys_common::backtrace::__rust_end_short_backtrace::<std[38e62313bc239a56]::panicking::begin_panic<rustc_errors[af9b09486d396f0e]::ExplicitBug>::{closure#0}, !>
  16:     0x759695c610f6 - std[38e62313bc239a56]::panicking::begin_panic::<rustc_errors[af9b09486d396f0e]::ExplicitBug>
  17:     0x759695c6d5a1 - <rustc_errors[af9b09486d396f0e]::diagnostic::BugAbort as rustc_errors[af9b09486d396f0e]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x759695b8bde8 - <rustc_errors[af9b09486d396f0e]::DiagCtxt>::span_bug::<rustc_span[f1eec7621a4a8a13]::span_encoding::Span, alloc[1469ad075796f7fa]::string::String>
  19:     0x759695babd3d - rustc_middle[fa2df4ac05b0b11]::util::bug::opt_span_bug_fmt::<rustc_span[f1eec7621a4a8a13]::span_encoding::Span>::{closure#0}
  20:     0x759695babf8a - rustc_middle[fa2df4ac05b0b11]::ty::context::tls::with_opt::<rustc_middle[fa2df4ac05b0b11]::util::bug::opt_span_bug_fmt<rustc_span[f1eec7621a4a8a13]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x759695ba1f6b - rustc_middle[fa2df4ac05b0b11]::ty::context::tls::with_context_opt::<rustc_middle[fa2df4ac05b0b11]::ty::context::tls::with_opt<rustc_middle[fa2df4ac05b0b11]::util::bug::opt_span_bug_fmt<rustc_span[f1eec7621a4a8a13]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7596951a2af7 - rustc_middle[fa2df4ac05b0b11]::util::bug::span_bug_fmt::<rustc_span[f1eec7621a4a8a13]::span_encoding::Span>
  23:     0x7596981197ef - rustc_const_eval[e815444167bf77d1]::const_eval::eval_queries::eval_body_using_ecx::<rustc_middle[fa2df4ac05b0b11]::mir::interpret::allocation::ConstAllocation>
  24:     0x759698098d06 - rustc_const_eval[e815444167bf77d1]::const_eval::eval_queries::eval_static_initializer_provider
  25:     0x759698098a99 - rustc_query_impl[22c309853ee5088a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[22c309853ee5088a]::query_impl::eval_static_initializer::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fa2df4ac05b0b11]::query::erase::Erased<[u8; 16usize]>>
  26:     0x759698098a6f - <rustc_query_impl[22c309853ee5088a]::query_impl::eval_static_initializer::dynamic_query::{closure#2} as core[1047681daa7013a7]::ops::function::FnOnce<(rustc_middle[fa2df4ac05b0b11]::ty::context::TyCtxt, rustc_span[f1eec7621a4a8a13]::def_id::DefId)>>::call_once
  27:     0x759697764e99 - rustc_query_system[c9a12d3f23a2fc37]::query::plumbing::try_execute_query::<rustc_query_impl[22c309853ee5088a]::DynamicConfig<rustc_query_system[c9a12d3f23a2fc37]::query::caches::DefIdCache<rustc_middle[fa2df4ac05b0b11]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[22c309853ee5088a]::plumbing::QueryCtxt, false>
  28:     0x759697eab021 - rustc_query_impl[22c309853ee5088a]::query_impl::eval_static_initializer::get_query_non_incr::__rust_end_short_backtrace
  29:     0x759697377b1f - <rustc_middle[fa2df4ac05b0b11]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[5ac7a7d7e1a64a2]::check_crate::{closure#3}>::{closure#0}
  30:     0x7596973760b4 - rustc_hir_analysis[5ac7a7d7e1a64a2]::check_crate
  31:     0x7596973579c7 - rustc_interface[fb867dd4473de059]::passes::analysis
  32:     0x759697357515 - rustc_query_impl[22c309853ee5088a]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[22c309853ee5088a]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fa2df4ac05b0b11]::query::erase::Erased<[u8; 1usize]>>
  33:     0x759697def225 - rustc_query_system[c9a12d3f23a2fc37]::query::plumbing::try_execute_query::<rustc_query_impl[22c309853ee5088a]::DynamicConfig<rustc_query_system[c9a12d3f23a2fc37]::query::caches::SingleCache<rustc_middle[fa2df4ac05b0b11]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[22c309853ee5088a]::plumbing::QueryCtxt, false>
  34:     0x759697deef89 - rustc_query_impl[22c309853ee5088a]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  35:     0x759697c5bbce - rustc_interface[fb867dd4473de059]::interface::run_compiler::<core[1047681daa7013a7]::result::Result<(), rustc_span[f1eec7621a4a8a13]::ErrorGuaranteed>, rustc_driver_impl[8807ebb1224e5aed]::run_compiler::{closure#0}>::{closure#1}
  36:     0x759697c46867 - std[38e62313bc239a56]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[fb867dd4473de059]::util::run_in_thread_with_globals<rustc_interface[fb867dd4473de059]::util::run_in_thread_pool_with_globals<rustc_interface[fb867dd4473de059]::interface::run_compiler<core[1047681daa7013a7]::result::Result<(), rustc_span[f1eec7621a4a8a13]::ErrorGuaranteed>, rustc_driver_impl[8807ebb1224e5aed]::run_compiler::{closure#0}>::{closure#1}, core[1047681daa7013a7]::result::Result<(), rustc_span[f1eec7621a4a8a13]::ErrorGuaranteed>>::{closure#0}, core[1047681daa7013a7]::result::Result<(), rustc_span[f1eec7621a4a8a13]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1047681daa7013a7]::result::Result<(), rustc_span[f1eec7621a4a8a13]::ErrorGuaranteed>>
  37:     0x759697c4662a - <<std[38e62313bc239a56]::thread::Builder>::spawn_unchecked_<rustc_interface[fb867dd4473de059]::util::run_in_thread_with_globals<rustc_interface[fb867dd4473de059]::util::run_in_thread_pool_with_globals<rustc_interface[fb867dd4473de059]::interface::run_compiler<core[1047681daa7013a7]::result::Result<(), rustc_span[f1eec7621a4a8a13]::ErrorGuaranteed>, rustc_driver_impl[8807ebb1224e5aed]::run_compiler::{closure#0}>::{closure#1}, core[1047681daa7013a7]::result::Result<(), rustc_span[f1eec7621a4a8a13]::ErrorGuaranteed>>::{closure#0}, core[1047681daa7013a7]::result::Result<(), rustc_span[f1eec7621a4a8a13]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1047681daa7013a7]::result::Result<(), rustc_span[f1eec7621a4a8a13]::ErrorGuaranteed>>::{closure#2} as core[1047681daa7013a7]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7596993b9c8b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h72407d361096f666
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/alloc/src/boxed.rs:2022:9
  39:     0x7596993b9c8b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3878e789fa4b1285
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/alloc/src/boxed.rs:2022:9
  40:     0x7596993b9c8b - std::sys::pal::unix::thread::Thread::new::thread_start::ha89734ac0973fd52
                               at /rustc/61a1dbd751ab7f3c973be17d7ff3948ffda07c6e/library/std/src/sys/pal/unix/thread.rs:108:17
  41:     0x75969915855a - <unknown>
  42:     0x7596991d5a3c - <unknown>
  43:                0x0 - <unknown>

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please make sure that you have updated to the latest nightly

note: rustc 1.79.0-nightly (61a1dbd75 2024-04-27) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [eval_static_initializer] evaluating initializer of static `default_instance::instance`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0124, E0428, E0601.
For more information about an error, try `rustc --explain E0124`.

@matthiaskrgr matthiaskrgr added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Apr 28, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 28, 2024
@matthiaskrgr
Copy link
Member Author

this bisects to #121087

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label May 9, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label May 10, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 5, 2024
check_expr_struct_fields: taint context with errors if struct definit…

Taint errors while checking `struct { field: 1 }` below if struct definition has duplicated fields so that we don't pass it to const eval.

fixes rust-lang#125842, fixes rust-lang#124464, fixes rust-lang#124552
```rust
struct Struct {
    field: Option<u8>,
    field: u8,
}

static STATIC: Struct = Struct {
    field: 1,
};

pub fn main() {}
```
(This was rust-lang#125947 but i messed something up, sorry)
r? `@compiler-errors`
@bors bors closed this as completed in 3121a5c Jun 6, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 6, 2024
Rollup merge of rust-lang#126045 - olafes:master, r=compiler-errors

check_expr_struct_fields: taint context with errors if struct definit…

Taint errors while checking `struct { field: 1 }` below if struct definition has duplicated fields so that we don't pass it to const eval.

fixes rust-lang#125842, fixes rust-lang#124464, fixes rust-lang#124552
```rust
struct Struct {
    field: Option<u8>,
    field: u8,
}

static STATIC: Struct = Struct {
    field: 1,
};

pub fn main() {}
```
(This was rust-lang#125947 but i messed something up, sorry)
r? ``@compiler-errors``
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
3 participants