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: "Got a scalar pair where a scalar was expected" -Zmir-opt-level=4 --emit=mir #96169

Closed
matthiaskrgr opened this issue Apr 18, 2022 · 11 comments · Fixed by rust-lang/miri#2336 or #98980
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

Comments

@matthiaskrgr
Copy link
Member

Code

// run-rustfix
#![allow(unused)]
fn a() -> usize { 0 }
//~^ ERROR return types are denoted using `->`

fn bar(_: u32) {}

fn baz() -> *const dyn Fn(u32) { unimplemented!() }

fn foo() {
    match () {
        _ if baz() == &bar as &dyn Fn(u32) => (),
        () => (),
    }
}

fn main() {
}

Meta

rustc --version --verbose:

rustc 1.62.0-nightly (878c7833f 2022-04-16)
binary: rustc
commit-hash: 878c7833f6c1ff10e2fd89074e5bd4ef5ff15936
commit-date: 2022-04-16
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.0

Error output


Backtrace

error: internal compiler error: /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/compiler/rustc_const_eval/src/interpret/operand.rs:77:42: Got a scalar pair where a scalar was expected

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/compiler/rustc_errors/src/lib.rs:1349:9
stack backtrace:
   0:     0x7f0edf49d7fd - std::backtrace_rs::backtrace::libunwind::trace::h533af29c806df9d1
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f0edf49d7fd - std::backtrace_rs::backtrace::trace_unsynchronized::hdb4c2ff88b52ef66
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f0edf49d7fd - std::sys_common::backtrace::_print_fmt::h68495a06222c4efb
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f0edf49d7fd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h91043f683408357d
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f0edf4f8eec - core::fmt::write::hcc15453d8963f001
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/core/src/fmt/mod.rs:1194:17
   5:     0x7f0edf48ef51 - std::io::Write::write_fmt::h5217846c280e1260
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/io/mod.rs:1655:15
   6:     0x7f0edf4a0515 - std::sys_common::backtrace::_print::h88be4bfce1061450
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f0edf4a0515 - std::sys_common::backtrace::print::he017a6566e010988
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f0edf4a0515 - std::panicking::default_hook::{{closure}}::hb793c4d82607bce7
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/panicking.rs:295:22
   9:     0x7f0edf4a0189 - std::panicking::default_hook::hc3c558385f484fdc
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/panicking.rs:314:9
  10:     0x7f0edfcd1421 - rustc_driver[19d608e2c8daf1f4]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f0edf4a0ce6 - std::panicking::rust_panic_with_hook::h28c3b2fc9e3a60cd
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/panicking.rs:702:17
  12:     0x7f0ee0d28881 - std[cd658a55527ed977]::panicking::begin_panic::<rustc_errors[9417c7ccc58903d8]::ExplicitBug>::{closure#0}
  13:     0x7f0ee0d27d96 - std[cd658a55527ed977]::sys_common::backtrace::__rust_end_short_backtrace::<std[cd658a55527ed977]::panicking::begin_panic<rustc_errors[9417c7ccc58903d8]::ExplicitBug>::{closure#0}, !>
  14:     0x7f0ee0cbddef - std[cd658a55527ed977]::panicking::begin_panic::<rustc_errors[9417c7ccc58903d8]::ExplicitBug>
  15:     0x7f0ee0c6f166 - std[cd658a55527ed977]::panic::panic_any::<rustc_errors[9417c7ccc58903d8]::ExplicitBug>
  16:     0x7f0ee0c6afe5 - <rustc_errors[9417c7ccc58903d8]::HandlerInner>::bug::<&alloc[c0e4610846cb0c5f]::string::String>
  17:     0x7f0ee0c6ad50 - <rustc_errors[9417c7ccc58903d8]::Handler>::bug::<&alloc[c0e4610846cb0c5f]::string::String>
  18:     0x7f0ee0d314bd - rustc_middle[77cffc0d0a9caf4f]::ty::context::tls::with_opt::<rustc_middle[77cffc0d0a9caf4f]::util::bug::opt_span_bug_fmt<rustc_span[ae9ba53627e4b7a2]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f0ee0d33f46 - rustc_middle[77cffc0d0a9caf4f]::util::bug::opt_span_bug_fmt::<rustc_span[ae9ba53627e4b7a2]::span_encoding::Span>
  20:     0x7f0ee0d33eb3 - rustc_middle[77cffc0d0a9caf4f]::util::bug::bug_fmt
  21:     0x7f0edfebeecf - <rustc_const_eval[2c45cfb8cbd0596a]::interpret::operand::Immediate>::to_scalar
  22:     0x7f0ee10cd5e2 - <rustc_mir_transform[30431bd415c4c272]::const_prop::ConstPropagator as rustc_middle[77cffc0d0a9caf4f]::mir::visit::MutVisitor>::visit_body
  23:     0x7f0ee10c9264 - <rustc_mir_transform[30431bd415c4c272]::const_prop::ConstProp as rustc_middle[77cffc0d0a9caf4f]::mir::MirPass>::run_pass
  24:     0x7f0ee110903e - rustc_mir_transform[30431bd415c4c272]::pass_manager::run_passes
  25:     0x7f0ee10f43de - rustc_mir_transform[30431bd415c4c272]::optimized_mir
  26:     0x7f0ee16f4720 - rustc_query_system[f27402853dfb6133]::query::plumbing::try_execute_query::<rustc_query_impl[604497a8fc516067]::plumbing::QueryCtxt, rustc_query_system[f27402853dfb6133]::query::caches::DefaultCache<rustc_span[ae9ba53627e4b7a2]::def_id::DefId, &rustc_middle[77cffc0d0a9caf4f]::mir::Body>>
  27:     0x7f0ee17e6d0e - <rustc_query_impl[604497a8fc516067]::Queries as rustc_middle[77cffc0d0a9caf4f]::ty::query::QueryEngine>::optimized_mir
  28:     0x7f0ee1bd753d - <rustc_middle[77cffc0d0a9caf4f]::ty::context::TyCtxt>::instance_mir
  29:     0x7f0ee0c9998f - rustc_middle[77cffc0d0a9caf4f]::mir::pretty::write_mir_pretty
  30:     0x7f0edff0bd10 - rustc_mir_transform[30431bd415c4c272]::dump_mir::emit_mir
  31:     0x7f0ee1d29b86 - <rustc_interface[c2767953942b9161]::queries::Queries>::ongoing_codegen
  32:     0x7f0ee1cf02fb - <rustc_interface[c2767953942b9161]::interface::Compiler>::enter::<rustc_driver[19d608e2c8daf1f4]::run_compiler::{closure#1}::{closure#2}, core[9a854ec5d686c1fc]::result::Result<core[9a854ec5d686c1fc]::option::Option<rustc_interface[c2767953942b9161]::queries::Linker>, rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>
  33:     0x7f0ee1d18ecf - rustc_span[ae9ba53627e4b7a2]::with_source_map::<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_interface[c2767953942b9161]::interface::create_compiler_and_run<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_driver[19d608e2c8daf1f4]::run_compiler::{closure#1}>::{closure#1}>
  34:     0x7f0ee1cf0ee7 - <scoped_tls[673d87c3fad674a0]::ScopedKey<rustc_span[ae9ba53627e4b7a2]::SessionGlobals>>::set::<rustc_interface[c2767953942b9161]::interface::run_compiler<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_driver[19d608e2c8daf1f4]::run_compiler::{closure#1}>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>
  35:     0x7f0ee1d062ff - std[cd658a55527ed977]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c2767953942b9161]::util::run_in_thread_pool_with_globals<rustc_interface[c2767953942b9161]::interface::run_compiler<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_driver[19d608e2c8daf1f4]::run_compiler::{closure#1}>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>
  36:     0x7f0ee1d06439 - <<std[cd658a55527ed977]::thread::Builder>::spawn_unchecked_<rustc_interface[c2767953942b9161]::util::run_in_thread_pool_with_globals<rustc_interface[c2767953942b9161]::interface::run_compiler<core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>, rustc_driver[19d608e2c8daf1f4]::run_compiler::{closure#1}>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>::{closure#0}, core[9a854ec5d686c1fc]::result::Result<(), rustc_errors[9417c7ccc58903d8]::ErrorGuaranteed>>::{closure#1} as core[9a854ec5d686c1fc]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  37:     0x7f0edf4aab93 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha55af26f35189599
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/alloc/src/boxed.rs:1866:9
  38:     0x7f0edf4aab93 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6a841b0f36efd076
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/alloc/src/boxed.rs:1866:9
  39:     0x7f0edf4aab93 - std::sys::unix::thread::Thread::new::thread_start::h4d154f7a3783bf9b
                               at /rustc/878c7833f6c1ff10e2fd89074e5bd4ef5ff15936/library/std/src/sys/unix/thread.rs:108:17
  40:     0x7f0edf2835c2 - start_thread
  41:     0x7f0edf308584 - __clone
  42:                0x0 - <unknown>

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

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: rustc 1.62.0-nightly (878c7833f 2022-04-16) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=4

query stack during panic:
#0 [optimized_mir] optimizing MIR for `foo`
end of query stack
error: aborting due to previous error

@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 18, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 23, 2022
@matthiaskrgr matthiaskrgr added the A-miri Area: The miri tool label Apr 27, 2022
@matthiaskrgr
Copy link
Member Author

Also reproducible in miri:

use std::fmt::Debug;
use std::ptr;

fn main() {
    let a: *const dyn Debug = &1 as &dyn Debug;
    let b: *const dyn Debug = &1 as &dyn Debug;
    let _ = a < b;
}

@RalfJung
Copy link
Member

RalfJung commented May 4, 2022

The second one looks very different from the first. That looks like a bug in the Miri implementation of <, which is not prepared for wide pointers.

@RalfJung
Copy link
Member

RalfJung commented Jul 6, 2022

I cannot reproduce the original example any more. And in fact main is empty so I don't think Miri even did anything. The backtrace points to ConstProp, which would make this a rustc bug, not a Miri bug. Not sure if there is anything actionable here.

The second one still ICEs.

@RalfJung
Copy link
Member

RalfJung commented Jul 6, 2022

@bjorn3 do you know the codegen behavior of < on wide pointers? Does it do anything with the metadata?
(==/!= also compares the metadata, as far as I know).

@RalfJung
Copy link
Member

RalfJung commented Jul 6, 2022

Actually testing indicates that it is... lexicographic?!?

@bjorn3
Copy link
Member

bjorn3 commented Jul 6, 2022

Indeed. This is the actual implementation:

mir::BinOp::Le | mir::BinOp::Lt | mir::BinOp::Ge | mir::BinOp::Gt => {
// a OP b ~ a.0 STRICT(OP) b.0 | (a.0 == b.0 && a.1 OP a.1)
let (op, strict_op) = match op {
mir::BinOp::Lt => (IntPredicate::IntULT, IntPredicate::IntULT),
mir::BinOp::Le => (IntPredicate::IntULE, IntPredicate::IntULT),
mir::BinOp::Gt => (IntPredicate::IntUGT, IntPredicate::IntUGT),
mir::BinOp::Ge => (IntPredicate::IntUGE, IntPredicate::IntUGT),
_ => bug!(),
};
let lhs = bx.icmp(strict_op, lhs_addr, rhs_addr);
let and_lhs = bx.icmp(IntPredicate::IntEQ, lhs_addr, rhs_addr);
let and_rhs = bx.icmp(op, lhs_extra, rhs_extra);
let rhs = bx.and(and_lhs, and_rhs);
bx.or(lhs, rhs)
}

@matthiaskrgr
Copy link
Member Author

Example #1 still crashes with -Zmir-opt-level=4 as noted in the title, reopening.

@matthiaskrgr matthiaskrgr reopened this Jul 6, 2022
@matthiaskrgr matthiaskrgr removed the A-miri Area: The miri tool label Jul 6, 2022
@RalfJung
Copy link
Member

RalfJung commented Jul 6, 2022

I tried it with opt-level 4 and it didn't crash for me... which rustc are you using?

$ rustc --version
rustc 1.64.0-nightly (f342bea9d 2022-07-05)

@matthiaskrgr
Copy link
Member Author

did you also pass --emit=mir ?

@RalfJung
Copy link
Member

RalfJung commented Jul 6, 2022

D'oh, I should read what you are saying, sorry...

@RalfJung
Copy link
Member

RalfJung commented Jul 6, 2022

Wow, that backtrace is completely useless. All the relevant line numbers are missing.

I added some track_caller and tracked it to this line:

let arg_value = const_arg.to_scalar()?.to_bits(const_arg.layout.size)?;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants