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

ICE: write_immediate_to_mplace: invalid Scalar layout: TyAndLayout{ ... #123153

Closed
Naserume opened this issue Mar 28, 2024 · 2 comments · Fixed by #123675
Closed

ICE: write_immediate_to_mplace: invalid Scalar layout: TyAndLayout{ ... #123153

Naserume opened this issue Mar 28, 2024 · 2 comments · Fixed by #123675
Assignees
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) 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

@Naserume
Copy link

Code

(reduced)

pub struct wl_interface {
    pub version: str,
}

pub struct Interface {
    pub other_interfaces: &'static [&'static Interface],
    pub c_ptr: Option<&'static wl_interface>,
}

pub static mut wl_callback_interface: wl_interface = wl_interface { version: 0 };

pub static WL_CALLBACK_INTERFACE: Interface =
    Interface { other_interfaces: &[], c_ptr: Some(unsafe { &wl_callback_interface }) };


fn main() {}
Original

//@ check-pass

#![allow(non_camel_case_types, non_upper_case_globals, static_mut_refs)]

pub struct wl_interface {
    pub version: str,
}

pub struct Interface {
    pub other_interfaces: &'static [&'static Interface],
    pub c_ptr: Option<&'static wl_interface>,
}

pub static mut wl_callback_interface: wl_interface = wl_interface { version: 0 };

pub static WL_CALLBACK_INTERFACE: Interface =
    Interface { other_interfaces: &[], c_ptr: Some(unsafe { &wl_callback_interface }) };

// This static contains a promoted that points to a static that points to a mutable static.
pub static WL_SURFACE_INTERFACE: Interface =
    Interface { other_interfaces: &[&WL_CALLBACK_INTERFACE], c_ptr: None };

// And another variant of the same thing, this time with interior mutability.
use std::sync::OnceLock;
static LAZY_INIT: OnceLock<u32> = OnceLock::new();
static LAZY_INIT_REF: &[&OnceLock<u32>] = &[&LAZY_INIT];

fn main() {}

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (c9f8f3438 2024-03-27)
binary: rustc
commit-hash: c9f8f3438a8134a413aa5d4903e0196e44e37bbc
commit-date: 2024-03-27
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2

Error output

warning: type `wl_interface` should have an upper camel case name
 --> ./BEB38A0A15213C9CE5B8787BC181755D57883904AF16A34597AD27154F0E23BD.rs:1:12
  |
1 | pub struct wl_interface {
  |            ^^^^^^^^^^^^ help: convert the identifier to upper camel case: `WlInterface`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

error[E0277]: the size for values of type `str` cannot be known at compilation time
  --> ./BEB38A0A15213C9CE5B8787BC181755D57883904AF16A34597AD27154F0E23BD.rs:10:39
   |
10 | pub static mut wl_callback_interface: wl_interface = wl_interface { version: 0 };
   |                                       ^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: within `wl_interface`, the trait `Sized` is not implemented for `str`, which is required by `wl_interface: Sized`
note: required because it appears within the type `wl_interface`
  --> ./BEB38A0A15213C9CE5B8787BC181755D57883904AF16A34597AD27154F0E23BD.rs:1:12
   |
1  | pub struct wl_interface {
   |            ^^^^^^^^^^^^

error[E0277]: the size for values of type `str` cannot be known at compilation time
  --> ./BEB38A0A15213C9CE5B8787BC181755D57883904AF16A34597AD27154F0E23BD.rs:10:54
   |
10 | pub static mut wl_callback_interface: wl_interface = wl_interface { version: 0 };
   |                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
   = help: within `wl_interface`, the trait `Sized` is not implemented for `str`, which is required by `wl_interface: Sized`
note: required because it appears within the type `wl_interface`
  --> ./BEB38A0A15213C9CE5B8787BC181755D57883904AF16A34597AD27154F0E23BD.rs:1:12
   |
1  | pub struct wl_interface {
   |            ^^^^^^^^^^^^
   = note: constant expressions must have a statically known size

error[E0308]: mismatched types
  --> ./BEB38A0A15213C9CE5B8787BC181755D57883904AF16A34597AD27154F0E23BD.rs:10:78
   |
10 | pub static mut wl_callback_interface: wl_interface = wl_interface { version: 0 };
   |                                                                              ^ expected `str`, found integer

warning: creating a shared reference to mutable static is discouraged
  --> ./BEB38A0A15213C9CE5B8787BC181755D57883904AF16A34597AD27154F0E23BD.rs:13:61
   |
13 |     Interface { other_interfaces: &[], c_ptr: Some(unsafe { &wl_callback_interface }) };
   |                                                             ^^^^^^^^^^^^^^^^^^^^^^ shared reference to mutable static
   |
   = note: for more information, see issue #114447 <https://github.com/rust-lang/rust/issues/114447>
   = note: this will be a hard error in the 2024 edition
   = note: this shared reference has lifetime `'static`, but if the static ever gets mutated, or a mutable reference is created, then any further use of this shared reference is Undefined Behavior
   = note: `#[warn(static_mut_refs)]` on by default
help: use `addr_of!` instead to create a raw pointer
   |
13 |     Interface { other_interfaces: &[], c_ptr: Some(unsafe { addr_of!(wl_callback_interface) }) };
   |                                                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: internal compiler error: compiler/rustc_const_eval/src/interpret/place.rs:695:21: write_immediate_to_mplace: invalid Scalar layout: TyAndLayout {
                                    ty: &wl_interface,
                                    layout: Layout {
                                        size: Size(16 bytes),
                                        align: AbiAndPrefAlign {
                                            abi: Align(8 bytes),
                                            pref: Align(8 bytes),
                                        },
                                        abi: ScalarPair(
                                            Initialized {
                                                value: Pointer(
                                                    AddressSpace(
                                                        0,
                                                    ),
                                                ),
                                                valid_range: 1..=18446744073709551615,
                                            },
                                            Initialized {
                                                value: Int(
                                                    I64,
                                                    false,
                                                ),
                                                valid_range: 0..=18446744073709551615,
                                            },
                                        ),
                                        fields: Arbitrary {
                                            offsets: [
                                                Size(0 bytes),
                                                Size(8 bytes),
                                            ],
                                            memory_index: [
                                                0,
                                                1,
                                            ],
                                        },
                                        largest_niche: Some(
                                            Niche {
                                                offset: Size(0 bytes),
                                                value: Pointer(
                                                    AddressSpace(
                                                        0,
                                                    ),
                                                ),
                                                valid_range: 1..=18446744073709551615,
                                            },
                                        ),
                                        variants: Single {
                                            index: 0,
                                        },
                                        max_repr_align: None,
                                        unadjusted_abi_align: Align(8 bytes),
                                    },
                                }
  --> ./BEB38A0A15213C9CE5B8787BC181755D57883904AF16A34597AD27154F0E23BD.rs:13:47
   |
13 |     Interface { other_interfaces: &[], c_ptr: Some(unsafe { &wl_callback_interface }) };
   |                                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/place.rs:695:21:
Box<dyn Any>
stack backtrace:
   0:        0x1066aee93 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8622fa9b8f01ae29
   1:        0x1066fccab - core::fmt::write::hfef1e936b89e9e59
   2:        0x1066a4fee - std::io::Write::write_fmt::h6a176982c498677c
   3:        0x1066aec81 - std::sys_common::backtrace::print::hc48f34eaebaf416f
   4:        0x1066b1ca9 - std::panicking::default_hook::{{closure}}::h3b950a0bf2b644e8
   5:        0x1066b1a10 - std::panicking::default_hook::he2d3412695f2d7b9
   6:        0x10f24d97d - std[a2ca1e908c4c108d]::panicking::update_hook::<alloc[8ecff88a291c7d81]::boxed::Box<rustc_driver_impl[629facdbd27b12dd]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x1066b27db - std::panicking::rust_panic_with_hook::h46c3037f3fbe8331
   8:        0x10f2b4cea - std[a2ca1e908c4c108d]::panicking::begin_panic::<rustc_errors[32bc04fe0ab51647]::ExplicitBug>::{closure#0}
   9:        0x10f2ad229 - std[a2ca1e908c4c108d]::sys_common::backtrace::__rust_end_short_backtrace::<std[a2ca1e908c4c108d]::panicking::begin_panic<rustc_errors[32bc04fe0ab51647]::ExplicitBug>::{closure#0}, !>
  10:        0x113993ac9 - std[a2ca1e908c4c108d]::panicking::begin_panic::<rustc_errors[32bc04fe0ab51647]::ExplicitBug>
  11:        0x10f2c85b6 - <rustc_errors[32bc04fe0ab51647]::diagnostic::BugAbort as rustc_errors[32bc04fe0ab51647]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:        0x10f0e7dcc - <rustc_errors[32bc04fe0ab51647]::DiagCtxt>::span_bug::<rustc_span[8dae231bb2118e0f]::span_encoding::Span, alloc[8ecff88a291c7d81]::string::String>
  13:        0x10f12665e - rustc_middle[d0b008c68dae455]::util::bug::opt_span_bug_fmt::<rustc_span[8dae231bb2118e0f]::span_encoding::Span>::{closure#0}
  14:        0x10f127f77 - rustc_middle[d0b008c68dae455]::ty::context::tls::with_opt::<rustc_middle[d0b008c68dae455]::util::bug::opt_span_bug_fmt<rustc_span[8dae231bb2118e0f]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:        0x10f112c45 - rustc_middle[d0b008c68dae455]::ty::context::tls::with_context_opt::<rustc_middle[d0b008c68dae455]::ty::context::tls::with_opt<rustc_middle[d0b008c68dae455]::util::bug::opt_span_bug_fmt<rustc_span[8dae231bb2118e0f]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:        0x113980342 - rustc_middle[d0b008c68dae455]::util::bug::span_bug_fmt::<rustc_span[8dae231bb2118e0f]::span_encoding::Span>
  17:        0x10f194fea - <rustc_const_eval[933ace3783df84a7]::interpret::eval_context::InterpCx<rustc_const_eval[933ace3783df84a7]::const_eval::machine::CompileTimeInterpreter>>::write_immediate_to_mplace_no_validate
  18:        0x10f1948b7 - <rustc_const_eval[933ace3783df84a7]::interpret::eval_context::InterpCx<rustc_const_eval[933ace3783df84a7]::const_eval::machine::CompileTimeInterpreter>>::write_immediate_no_validate::<rustc_const_eval[933ace3783df84a7]::interpret::place::PlaceTy>
  19:        0x10f1e769b - <rustc_const_eval[933ace3783df84a7]::interpret::eval_context::InterpCx<rustc_const_eval[933ace3783df84a7]::const_eval::machine::CompileTimeInterpreter>>::copy_op_no_validate::<rustc_const_eval[933ace3783df84a7]::interpret::operand::OpTy, rustc_const_eval[933ace3783df84a7]::interpret::place::PlaceTy>
  20:        0x10f19b123 - <rustc_const_eval[933ace3783df84a7]::interpret::eval_context::InterpCx<rustc_const_eval[933ace3783df84a7]::const_eval::machine::CompileTimeInterpreter>>::statement
  21:        0x10f1d6b1b - rustc_const_eval[933ace3783df84a7]::const_eval::eval_queries::eval_static_initializer_provider
  22:        0x110697a52 - rustc_query_impl[7ec918e69dd505e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7ec918e69dd505e]::query_impl::eval_static_initializer::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d0b008c68dae455]::query::erase::Erased<[u8; 16usize]>>
  23:        0x11065150e - <rustc_query_impl[7ec918e69dd505e]::query_impl::eval_static_initializer::dynamic_query::{closure#2} as core[d5cb36deb602d542]::ops::function::FnOnce<(rustc_middle[d0b008c68dae455]::ty::context::TyCtxt, rustc_span[8dae231bb2118e0f]::def_id::DefId)>>::call_once
  24:        0x11045ece8 - rustc_query_system[40399bf5d3ff25f]::query::plumbing::try_execute_query::<rustc_query_impl[7ec918e69dd505e]::DynamicConfig<rustc_query_system[40399bf5d3ff25f]::query::caches::DefIdCache<rustc_middle[d0b008c68dae455]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[7ec918e69dd505e]::plumbing::QueryCtxt, false>
  25:        0x1106c174d - rustc_query_impl[7ec918e69dd505e]::query_impl::eval_static_initializer::get_query_non_incr::__rust_end_short_backtrace
  26:        0x10f485cab - <rustc_middle[d0b008c68dae455]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[2d5e89c8dacd405d]::check_crate::{closure#3}>::{closure#0}
  27:        0x10f58d24c - rustc_hir_analysis[2d5e89c8dacd405d]::check_crate
  28:        0x10fa04c40 - rustc_interface[cb93122c76eb07a8]::passes::analysis
  29:        0x110698eaa - rustc_query_impl[7ec918e69dd505e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7ec918e69dd505e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d0b008c68dae455]::query::erase::Erased<[u8; 1usize]>>
  30:        0x11047fdde - rustc_query_system[40399bf5d3ff25f]::query::plumbing::try_execute_query::<rustc_query_impl[7ec918e69dd505e]::DynamicConfig<rustc_query_system[40399bf5d3ff25f]::query::caches::SingleCache<rustc_middle[d0b008c68dae455]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7ec918e69dd505e]::plumbing::QueryCtxt, false>
  31:        0x1106a3287 - rustc_query_impl[7ec918e69dd505e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  32:        0x10f1fb942 - <rustc_interface[cb93122c76eb07a8]::queries::QueryResult<&rustc_middle[d0b008c68dae455]::ty::context::GlobalCtxt>>::enter::<core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>, rustc_driver_impl[629facdbd27b12dd]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  33:        0x10f25464b - rustc_interface[cb93122c76eb07a8]::interface::run_compiler::<core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>, rustc_driver_impl[629facdbd27b12dd]::run_compiler::{closure#0}>::{closure#0}
  34:        0x10f243d36 - std[a2ca1e908c4c108d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cb93122c76eb07a8]::util::run_in_thread_with_globals<rustc_interface[cb93122c76eb07a8]::util::run_in_thread_pool_with_globals<rustc_interface[cb93122c76eb07a8]::interface::run_compiler<core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>, rustc_driver_impl[629facdbd27b12dd]::run_compiler::{closure#0}>::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>
  35:        0x10f25a3a8 - <<std[a2ca1e908c4c108d]::thread::Builder>::spawn_unchecked_<rustc_interface[cb93122c76eb07a8]::util::run_in_thread_with_globals<rustc_interface[cb93122c76eb07a8]::util::run_in_thread_pool_with_globals<rustc_interface[cb93122c76eb07a8]::interface::run_compiler<core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>, rustc_driver_impl[629facdbd27b12dd]::run_compiler::{closure#0}>::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d5cb36deb602d542]::result::Result<(), rustc_span[8dae231bb2118e0f]::ErrorGuaranteed>>::{closure#1} as core[d5cb36deb602d542]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:        0x1066bbab9 - std::sys::pal::unix::thread::Thread::new::thread_start::h78e3183c2153313c
  37:     0x7ff818270202 - __pthread_start

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 attach the file at `/Users/sal/Documents/240326버전(240328검토)/rustc-ice-2024-03-28T05_49_51-68848.txt` to your bug report

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

Some errors have detailed explanations: E0277, E0308.
For more information about an error, try `rustc --explain E0277`.

@Naserume Naserume added C-bug Category: This is a bug. 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. labels Mar 28, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 28, 2024
@Naserume Naserume changed the title ICE: write_immediate_to_mplace: invalid ScalarPair layout: TyAndLayout{ ... ICE: write_immediate_to_mplace: invalid Scalar layout: TyAndLayout{ ... Mar 28, 2024
@GrigorenkoPV
Copy link
Contributor

Bisects to #121087, but I guess it just made the ICE easier to reach.

cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Mar 28, 2024

Nope 😆 unfortunately this one only reproduces with statics, and thus can't be reached on stable or before that PR. It's still not useful to look at #121087 to figure out why it's ICEing now, as the ICE is happening somewhere else entirely.

@oli-obk oli-obk added A-const-eval Area: Constant evaluation (MIR interpretation) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Mar 28, 2024
@oli-obk oli-obk self-assigned this Apr 9, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 2024
@bors bors closed this as completed in 4885ddf Apr 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 17, 2024
Rollup merge of rust-lang#123675 - oli-obk:static_wf_ice, r=compiler-errors

Taint const qualifs if a static is referenced that didn't pass wfcheck

It is correct to only check the signature here, as the ICE is caused by `USE_WITH_ERROR` trying to allocate memory to store the result of `WITH_ERROR` before evaluating it.

fixes rust-lang#123153
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) 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
Development

Successfully merging a pull request may close this issue.

5 participants