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 due to missing struct tail normalization #3282

Closed
lcnr opened this issue Jan 29, 2024 · 2 comments · Fixed by rust-lang/rust#120587
Closed

ICE due to missing struct tail normalization #3282

lcnr opened this issue Jan 29, 2024 · 2 comments · Fixed by rust-lang/rust#120587

Comments

@lcnr
Copy link
Contributor

lcnr commented Jan 29, 2024

Caused by an issue in rustc itself, found here https://github.com/rust-lang/rust/pull/120354/files#r1469154220 from what I can tell this is only testable via MIRI however, so I opened the issue for this here.

trait Id {
    type Assoc: ?Sized;
}

impl<T: ?Sized> Id for T {
    type Assoc = T;
}

#[repr(transparent)]
struct Foo<T: ?Sized> {
    field: <T as Id>::Assoc,
}


fn main() {
    let x = unsafe { std::mem::transmute::<fn(&str), fn(&Foo<str>)>(|_| ()) };
    let foo: &Foo<str> = unsafe { &*("uwu" as *const str as *const Foo<str>) };
    x(foo);
}

results in an ICE

thread 'rustc' panicked at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/compiler/rustc_const_eval/src/interpret/terminator.rs:377:17:
there should be no more 'maybe has that metadata' types during interpretation
stack backtrace:
   0:     0x7f3ccb869706 - std::backtrace_rs::backtrace::libunwind::trace::hab3572c31eb20106
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f3ccb869706 - std::backtrace_rs::backtrace::trace_unsynchronized::h60fe86980a447e1f
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f3ccb869706 - std::sys_common::backtrace::_print_fmt::h94f8d95d56c8f54a
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f3ccb869706 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hcc8bd1ee8b27b1a7
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f3ccb8bc0a0 - core::fmt::rt::Argument::fmt::h53aa1e305ab9c913
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/core/src/fmt/rt.rs:142:9
   5:     0x7f3ccb8bc0a0 - core::fmt::write::h510b9470c0914af3
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f3ccb85d03f - std::io::Write::write_fmt::h324f538b1fa72cf5
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/io/mod.rs:1810:15
   7:     0x7f3ccb8694e4 - std::sys_common::backtrace::_print::h87616c284c3fd658
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f3ccb8694e4 - std::sys_common::backtrace::print::h1a5bdc383314a847
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f3ccb86c277 - std::panicking::default_hook::{{closure}}::h154ee088de97fd79
  10:     0x7f3ccb86bfd9 - std::panicking::default_hook::h255191adadb3bbd3
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/panicking.rs:292:9
  11:     0x7f3cce62a9cc - std[9b9743348aa3637e]::panicking::update_hook::<alloc[bafad8be7e602ddc]::boxed::Box<rustc_driver_impl[15253732b01127ee]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f3ccb86c9c6 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::he0826d83a3d5350a
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/alloc/src/boxed.rs:2029:9
  13:     0x7f3ccb86c9c6 - std::panicking::rust_panic_with_hook::h48fa132e308b8b90
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/panicking.rs:785:13
  14:     0x7f3ccb86c6d9 - std::panicking::begin_panic_handler::{{closure}}::h25d6c93d3d1459db
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/panicking.rs:651:13
  15:     0x7f3ccb869c06 - std::sys_common::backtrace::__rust_end_short_backtrace::h34a894d5da7b6896
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f3ccb86c464 - rust_begin_unwind
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/panicking.rs:647:5
  17:     0x7f3ccb8b87a5 - core::panicking::panic_fmt::he5ea86dee9f7da0f
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/core/src/panicking.rs:72:14
  18:     0x55e0819bae18 - <rustc_const_eval[2871bae7c83aa647]::interpret::eval_context::InterpCx<miri[3c98aef04cce8b4]::machine::MiriMachine>>::layout_compat::{closure#3}
  19:     0x55e0819ea95d - <rustc_const_eval[2871bae7c83aa647]::interpret::eval_context::InterpCx<miri[3c98aef04cce8b4]::machine::MiriMachine>>::check_argument_compat
  20:     0x55e0819988f9 - <rustc_const_eval[2871bae7c83aa647]::interpret::eval_context::InterpCx<miri[3c98aef04cce8b4]::machine::MiriMachine>>::pass_argument::<core[2c84ace8ac8a7133]::iter::adapters::filter::Filter<core[2c84ace8ac8a7133]::iter::adapters::zip::Zip<core[2c84ace8ac8a7133]::slice::iter::Iter<rustc_const_eval[2871bae7c83aa647]::interpret::terminator::FnArg<miri[3c98aef04cce8b4]::machine::Provenance>>, core[2c84ace8ac8a7133]::slice::iter::Iter<rustc_target[22ed814efa7eb6fe]::abi::call::ArgAbi<rustc_middle[16339a7d2af1bee1]::ty::Ty>>>, <rustc_const_eval[2871bae7c83aa647]::interpret::eval_context::InterpCx<miri[3c98aef04cce8b4]::machine::MiriMachine>>::eval_fn_call::{closure#2}>>
  21:     0x55e0819e8a63 - <rustc_const_eval[2871bae7c83aa647]::interpret::eval_context::InterpCx<miri[3c98aef04cce8b4]::machine::MiriMachine>>::eval_fn_call
  22:     0x55e081a542e5 - <rustc_const_eval[2871bae7c83aa647]::interpret::eval_context::InterpCx<miri[3c98aef04cce8b4]::machine::MiriMachine> as miri[3c98aef04cce8b4]::concurrency::thread::EvalContextExt>::run_threads
  23:     0x55e081a625c4 - miri[3c98aef04cce8b4]::eval::eval_entry
  24:     0x55e08189fff3 - <miri[442eb2054b97ae67]::MiriCompilerCalls as rustc_driver_impl[15253732b01127ee]::Callbacks>::after_analysis
  25:     0x7f3cd0614a6c - rustc_interface[2c240f1a557fc091]::interface::run_compiler::<core[2c84ace8ac8a7133]::result::Result<(), rustc_span[f446feb06f8d21a5]::ErrorGuaranteed>, rustc_driver_impl[15253732b01127ee]::run_compiler::{closure#0}>::{closure#0}
  26:     0x7f3cd024a706 - std[9b9743348aa3637e]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2c240f1a557fc091]::util::run_in_thread_with_globals<rustc_interface[2c240f1a557fc091]::util::run_in_thread_pool_with_globals<rustc_interface[2c240f1a557fc091]::interface::run_compiler<core[2c84ace8ac8a7133]::result::Result<(), rustc_span[f446feb06f8d21a5]::ErrorGuaranteed>, rustc_driver_impl[15253732b01127ee]::run_compiler::{closure#0}>::{closure#0}, core[2c84ace8ac8a7133]::result::Result<(), rustc_span[f446feb06f8d21a5]::ErrorGuaranteed>>::{closure#0}, core[2c84ace8ac8a7133]::result::Result<(), rustc_span[f446feb06f8d21a5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2c84ace8ac8a7133]::result::Result<(), rustc_span[f446feb06f8d21a5]::ErrorGuaranteed>>
  27:     0x7f3cd024a533 - <<std[9b9743348aa3637e]::thread::Builder>::spawn_unchecked_<rustc_interface[2c240f1a557fc091]::util::run_in_thread_with_globals<rustc_interface[2c240f1a557fc091]::util::run_in_thread_pool_with_globals<rustc_interface[2c240f1a557fc091]::interface::run_compiler<core[2c84ace8ac8a7133]::result::Result<(), rustc_span[f446feb06f8d21a5]::ErrorGuaranteed>, rustc_driver_impl[15253732b01127ee]::run_compiler::{closure#0}>::{closure#0}, core[2c84ace8ac8a7133]::result::Result<(), rustc_span[f446feb06f8d21a5]::ErrorGuaranteed>>::{closure#0}, core[2c84ace8ac8a7133]::result::Result<(), rustc_span[f446feb06f8d21a5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[2c84ace8ac8a7133]::result::Result<(), rustc_span[f446feb06f8d21a5]::ErrorGuaranteed>>::{closure#1} as core[2c84ace8ac8a7133]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x7f3ccb875fb5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h81eeb26d82351c2e
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/alloc/src/boxed.rs:2015:9
  29:     0x7f3ccb875fb5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha4fb1b693e599c2e
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/alloc/src/boxed.rs:2015:9
  30:     0x7f3ccb875fb5 - std::sys::pal::unix::thread::Thread::new::thread_start::hbbc84e063a1942c6
                               at /rustc/635124704849eeead4e3a7bb6e663c5351571d93/library/std/src/sys/pal/unix/thread.rs:108:17
  31:     0x7f3ccb76b609 - start_thread
  32:     0x7f3ccb541353 - clone
  33:                0x0 - <unknown>

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

note: we would appreciate a bug report: https://github.com/rust-lang/miri/issues/new

note: please attach the file at `/playground/rustc-ice-2024-01-29T07_25_46-13.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 -Z miri-disable-isolation

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack

Miri caused an ICE during evaluation. Here's the interpreter backtrace at the time of the panic:
note: the place in the program where the ICE was triggered
   --> /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
    |
250 |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: inside `<{closure@src/main.rs:16:69: 16:72} as std::ops::FnOnce<(&str,)>>::call_once - shim` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5: 250:71
note: inside `main`
   --> src/main.rs:18:5
    |
18  |     x(foo);
    |     ^^^^^^
    = note: inside `<fn() as std::ops::FnOnce<()>>::call_once - shim(fn())` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5: 250:71
    = note: inside `std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:155:18: 155:21
    = note: inside closure at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:166:18: 166:82
    = note: inside `std::ops::function::impls::<impl std::ops::FnOnce<()> for &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>::call_once` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:284:13: 284:31
    = note: inside `std::panicking::r#try::do_call::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:554:40: 554:43
    = note: inside `std::panicking::r#try::<i32, &dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:518:19: 518:81
    = note: inside `std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:142:14: 142:33
    = note: inside closure at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:148:48: 148:73
    = note: inside `std::panicking::r#try::do_call::<{closure@std::rt::lang_start_internal::{closure#2}}, isize>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:554:40: 554:43
    = note: inside `std::panicking::r#try::<isize, {closure@std::rt::lang_start_internal::{closure#2}}>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:518:19: 518:81
    = note: inside `std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#2}}, isize>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:142:14: 142:33
    = note: inside `std::rt::lang_start_internal` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:148:20: 148:98
    = note: inside `std::rt::lang_start::<()>` at /playground/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:165:17: 170:6
@RalfJung
Copy link
Member

RalfJung commented Jan 29, 2024

To answer the question there:

why do we not normalize here?

Because I had no idea I would have to normalize. ;) The entire normalization thing is largely opaque to me -- in the sense of, I have no idea when things are already normalized and which APIs are dangerous to call because they assume an already-normalized term. I usually just sprinkle random normalization calls across the interpreter until it works. 🤷

@RalfJung
Copy link
Member

Also see the discussion at rust-lang/rust#120354 (comment)

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 3, 2024
…RalfJung

miri: normalize struct tail in ABI compat check

fixes rust-lang/miri#3282
extracted from rust-lang#120354, see rust-lang#120354 (comment) for context

r? `@RalfJung`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 4, 2024
…RalfJung

miri: normalize struct tail in ABI compat check

fixes rust-lang/miri#3282
extracted from rust-lang#120354, see rust-lang#120354 (comment) for context

r? ``@RalfJung``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 5, 2024
Rollup merge of rust-lang#120587 - lukas-code:miri-tail-normalize, r=RalfJung

miri: normalize struct tail in ABI compat check

fixes rust-lang/miri#3282
extracted from rust-lang#120354, see rust-lang#120354 (comment) for context

r? ```@RalfJung```
github-actions bot pushed a commit that referenced this issue Feb 6, 2024
miri: normalize struct tail in ABI compat check

fixes #3282
extracted from rust-lang/rust#120354, see rust-lang/rust#120354 (comment) for context

r? ```@RalfJung```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants