rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.69k stars 12.49k forks source link

ICE: `write_immediate_to_mplace: invalid Scalar layout: TyAndLayout` #129109

Open matthiaskrgr opened 4 weeks ago

matthiaskrgr commented 4 weeks ago

auto-reduced (treereduce-rust):

extern "C" {
    pub static mut symbol: [i8];

}

fn main() {
    println!("C", unsafe { &symbol });
}

original:

extern "C" {
    pub static mut symbol: [i8];
    //~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
}

fn main() {
    println!("C", unsafe { &symbol });
    //~^ WARN creating a shared reference to mutable static is discouraged [static_mut_refs]
}

Version information

rustc 1.82.0-nightly (fbce03b19 2024-08-14)
binary: rustc
commit-hash: fbce03b195c02e425fbb12276b8f02349048a75f
commit-date: 2024-08-14
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0

Command: /home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 -Zvalidate-mir

Program output

``` error: argument never used --> /tmp/icemaker_global_tempdir.gKK7s1KquQAJ/rustc_testrunner_tmpdir_reporting.JRe5Vq1I3rjY/mvce.rs:7:19 | 7 | println!("C", unsafe { &symbol }); | --- ^^^^^^^^^^^^^^^^^^ argument never used | | | formatting specifier missing error[E0277]: the size for values of type `[i8]` cannot be known at compilation time --> /tmp/icemaker_global_tempdir.gKK7s1KquQAJ/rustc_testrunner_tmpdir_reporting.JRe5Vq1I3rjY/mvce.rs:2:28 | 2 | pub static mut symbol: [i8]; | ^^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `[i8]` warning: creating a shared reference to mutable static is discouraged --> /tmp/icemaker_global_tempdir.gKK7s1KquQAJ/rustc_testrunner_tmpdir_reporting.JRe5Vq1I3rjY/mvce.rs:7:28 | 7 | println!("C", unsafe { &symbol }); | ^^^^^^^ shared reference to mutable static | = note: for more information, see issue #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 | 7 | println!("C", unsafe { addr_of!(symbol) }); | ~~~~~~~~~ + error: internal compiler error: /rustc/fbce03b195c02e425fbb12276b8f02349048a75f/compiler/rustc_const_eval/src/interpret/place.rs:693:21: write_immediate_to_mplace: invalid Scalar layout: TyAndLayout { ty: &[i8], 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), }, } thread 'rustc' panicked at /rustc/fbce03b195c02e425fbb12276b8f02349048a75f/compiler/rustc_const_eval/src/interpret/place.rs:693:21: Box stack backtrace: 0: 0x7dabe2fb666d - ::fmt::h560b4d28c137b093 1: 0x7dabe3804f2f - core::fmt::write::h99766545c4efef9d 2: 0x7dabe47b0ed1 - std::io::Write::write_fmt::h8e3cbf6208612263 3: 0x7dabe2fb8d4b - std::panicking::default_hook::{{closure}}::h6bf6ccd32e88a7b7 4: 0x7dabe2fb89be - std::panicking::default_hook::ha56d0025017107a4 5: 0x7dabe2146299 - std[265a0665abe5e043]::panicking::update_hook::>::{closure#0} 6: 0x7dabe2fb9667 - std::panicking::rust_panic_with_hook::h53b891e816ad5807 7: 0x7dabe2180b41 - std[265a0665abe5e043]::panicking::begin_panic::::{closure#0} 8: 0x7dabe2173d26 - std[265a0665abe5e043]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 9: 0x7dabe2173aa6 - std[265a0665abe5e043]::panicking::begin_panic:: 10: 0x7dabe2189cc1 - ::emit_producing_guarantee 11: 0x7dabe283efcd - ::span_bug:: 12: 0x7dabe28719f8 - rustc_middle[d7f4792719c666e4]::util::bug::opt_span_bug_fmt::::{closure#0} 13: 0x7dabe2871a2a - rustc_middle[d7f4792719c666e4]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 14: 0x7dabe285dd0b - rustc_middle[d7f4792719c666e4]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 15: 0x7dabe285cb27 - rustc_middle[d7f4792719c666e4]::util::bug::span_bug_fmt:: 16: 0x7dabe42a8335 - >::write_immediate_to_mplace_no_validate 17: 0x7dabe1324a74 - ::run_pass 18: 0x7dabe3802151 - rustc_mir_transform[4b24bac2940eeb7a]::pass_manager::run_passes_inner 19: 0x7dabe432ccb3 - rustc_mir_transform[4b24bac2940eeb7a]::optimized_mir 20: 0x7dabe435039b - rustc_query_impl[c2f5f95cecf69337]::plumbing::__rust_begin_short_backtrace::> 21: 0x7dabe382af27 - rustc_query_system[f8c10878fe801c76]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[c2f5f95cecf69337]::plumbing::QueryCtxt, false> 22: 0x7dabe382a4df - rustc_query_impl[c2f5f95cecf69337]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace 23: 0x7dabe0184814 - ::instance_mir 24: 0x7dabe3bb63f9 - rustc_interface[8b2190a255f69c87]::passes::run_required_analyses 25: 0x7dabe43663de - rustc_interface[8b2190a255f69c87]::passes::analysis 26: 0x7dabe43663b1 - rustc_query_impl[c2f5f95cecf69337]::plumbing::__rust_begin_short_backtrace::> 27: 0x7dabe47706ee - rustc_query_system[f8c10878fe801c76]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[c2f5f95cecf69337]::plumbing::QueryCtxt, false> 28: 0x7dabe477044f - rustc_query_impl[c2f5f95cecf69337]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 29: 0x7dabe45dd169 - rustc_interface[8b2190a255f69c87]::interface::run_compiler::, rustc_driver_impl[18c1de8e11281817]::run_compiler::{closure#0}>::{closure#1} 30: 0x7dabe45025d0 - std[265a0665abe5e043]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[18c1de8e11281817]::run_compiler::{closure#0}>::{closure#1}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#0}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>> 31: 0x7dabe4502c3a - <::spawn_unchecked_, rustc_driver_impl[18c1de8e11281817]::run_compiler::{closure#0}>::{closure#1}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#0}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[12164080e42249fc]::result::Result<(), rustc_span[e524fe640245e945]::ErrorGuaranteed>>::{closure#1} as core[12164080e42249fc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 32: 0x7dabe4502fab - std::sys::pal::unix::thread::Thread::new::thread_start::hbf34cdaead1142d4 33: 0x7dabe5dab39d - 34: 0x7dabe5e3049c - 35: 0x0 - 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.82.0-nightly (fbce03b19 2024-08-14) running on x86_64-unknown-linux-gnu note: compiler flags: -Z mir-opt-level=5 -Z validate-mir -Z dump-mir-dir=dir query stack during panic: #0 [optimized_mir] optimizing MIR for `main` #1 [analysis] running analysis passes on this crate end of query stack error: aborting due to 3 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0277`. ```

jieyouxu commented 4 weeks ago

Seems like improper error tainting, i feel like this should not have reached const eval