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: invalid asymmetric binary op #121534

Closed
matthiaskrgr opened this issue Feb 24, 2024 · 4 comments · Fixed by #121628
Closed

ICE: invalid asymmetric binary op #121534

matthiaskrgr opened this issue Feb 24, 2024 · 4 comments · Fixed by #121628
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Feb 24, 2024

auto-reduced (treereduce-rust):

union union {
    union: u32,
    inion: i32,
    u8ion: u8,
    i64on: i64,
    u64on: u64,
}

pub fn main() {
    let union = union { union: 2 };
    let inion = union { inion: -2 };
    let mut mnion = union { inion: -16 };
    let m1 = unsafe { mnion.union };

    let u1 = unsafe { union.union };

    let u2 = unsafe { inion.union };

    let _r1 = u2 - u1 - m1;
}

original (gcc/testsuite/rust/compile/torture/union_union.rs) :

union union
{
  union: u32,
  inion: i32,
  u8ion: u8,
  i64on: i64,
  u64on: u64
}

pub fn main ()
{
  let union = union { union: 2 };
  let inion = union { inion: -2 };
  let mut mnion = union { inion: -16 };
  let m1 = unsafe { mnion.union };
  unsafe { mnion.union = union.union };
  let m2 = unsafe { mnion.inion };
  let u1 = unsafe { union.union };
  let i1 = unsafe { union.inion };
  let u2 = unsafe { inion.union };
  let i2 = unsafe { inion.inion };
  let _r1 = u2 - u1 - m1;
  let _r2 = i1 + i2 + m2;
  let _u8 = unsafe { union.u8ion };
  let _i64 = unsafe { union.i64on };
  let _u64 = unsafe { union.u64on };
}

Version information

rustc 1.78.0-nightly (8f359beca 2024-02-23)
binary: rustc
commit-hash: 8f359beca4e58bc3ae795a666301a8f47023044c
commit-date: 2024-02-23
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

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

Program output

warning: type `union` should have an upper camel case name
 --> /tmp/icemaker_global_tempdir.lpSPfcSJdDgv/rustc_testrunner_tmpdir_reporting.PtvKbcdNLvuk/mvce.rs:1:7
  |
1 | union union {
  |       ^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Union`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

warning: variable does not need to be mutable
  --> /tmp/icemaker_global_tempdir.lpSPfcSJdDgv/rustc_testrunner_tmpdir_reporting.PtvKbcdNLvuk/mvce.rs:12:9
   |
12 |     let mut mnion = union { inion: -16 };
   |         ----^^^^^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

error: internal compiler error: /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/compiler/rustc_const_eval/src/interpret/operator.rs:210:13: invalid asymmetric binary op Sub: 4294967294 (i32), 2 (u32)
 --> /tmp/icemaker_global_tempdir.lpSPfcSJdDgv/rustc_testrunner_tmpdir_reporting.PtvKbcdNLvuk/mvce.rs:9:1
  |
9 | pub fn main() {
  | ^^^^^^^^^^^^^

thread 'rustc' panicked at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/compiler/rustc_middle/src/util/bug.rs:34:50:
Box<dyn Any>
stack backtrace:
   0:     0x7fdc99bd4af6 - std::backtrace_rs::backtrace::libunwind::trace::h4d16db2f784877bc
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7fdc99bd4af6 - std::backtrace_rs::backtrace::trace_unsynchronized::h584b4a9b0240fa46
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7fdc99bd4af6 - std::sys_common::backtrace::_print_fmt::hd30229489add2f78
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7fdc99bd4af6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h2c0d00d6b7d69808
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7fdc99c25a7c - core::fmt::rt::Argument::fmt::hff9bfb4853f651d7
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/core/src/fmt/rt.rs:142:9
   5:     0x7fdc99c25a7c - core::fmt::write::h3421d3f24b10b162
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/core/src/fmt/mod.rs:1120:17
   6:     0x7fdc99bc94bf - std::io::Write::write_fmt::hec18e9e87db322bb
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/io/mod.rs:1846:15
   7:     0x7fdc99bd48a4 - std::sys_common::backtrace::_print::hec336a3777e68e7b
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7fdc99bd48a4 - std::sys_common::backtrace::print::hde3a6d5d13170337
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7fdc99bd75eb - std::panicking::default_hook::{{closure}}::h4a4905d59aca1811
  10:     0x7fdc99bd7339 - std::panicking::default_hook::h33a18ce8d018f6fd
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/panicking.rs:292:9
  11:     0x7fdc9688467c - std[d1f7731e2ff5974d]::panicking::update_hook::<alloc[6711342ad6595d8]::boxed::Box<rustc_driver_impl[db1009755931a507]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7fdc99bd7d50 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h923e5082c0e2f790
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/alloc/src/boxed.rs:2030:9
  13:     0x7fdc99bd7d50 - std::panicking::rust_panic_with_hook::he294011ca89c3e63
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/panicking.rs:783:13
  14:     0x7fdc968b0d24 - std[d1f7731e2ff5974d]::panicking::begin_panic::<rustc_errors[8efb6f95facf2fed]::ExplicitBug>::{closure#0}
  15:     0x7fdc968adc46 - std[d1f7731e2ff5974d]::sys_common::backtrace::__rust_end_short_backtrace::<std[d1f7731e2ff5974d]::panicking::begin_panic<rustc_errors[8efb6f95facf2fed]::ExplicitBug>::{closure#0}, !>
  16:     0x7fdc968ad926 - std[d1f7731e2ff5974d]::panicking::begin_panic::<rustc_errors[8efb6f95facf2fed]::ExplicitBug>
  17:     0x7fdc968ba711 - <rustc_errors[8efb6f95facf2fed]::diagnostic::BugAbort as rustc_errors[8efb6f95facf2fed]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7fdc96e55340 - rustc_middle[10e0138f1f482b76]::util::bug::opt_span_bug_fmt::<rustc_span[6ccc48fe7a4f1f83]::span_encoding::Span>::{closure#0}
  19:     0x7fdc96e5536a - rustc_middle[10e0138f1f482b76]::ty::context::tls::with_opt::<rustc_middle[10e0138f1f482b76]::util::bug::opt_span_bug_fmt<rustc_span[6ccc48fe7a4f1f83]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7fdc96e4e208 - rustc_middle[10e0138f1f482b76]::ty::context::tls::with_context_opt::<rustc_middle[10e0138f1f482b76]::ty::context::tls::with_opt<rustc_middle[10e0138f1f482b76]::util::bug::opt_span_bug_fmt<rustc_span[6ccc48fe7a4f1f83]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7fdc96e472e4 - rustc_middle[10e0138f1f482b76]::util::bug::span_bug_fmt::<rustc_span[6ccc48fe7a4f1f83]::span_encoding::Span>
  22:     0x7fdc9877d951 - <rustc_const_eval[57762c5f80ab379e]::interpret::eval_context::InterpCx<rustc_mir_transform[a8066d1d7333d1a3]::dataflow_const_prop::DummyMachine>>::overflowing_binary_op
  23:     0x7fdc98246015 - <rustc_mir_transform[a8066d1d7333d1a3]::known_panics_lint::ConstPropagator>::check_binary_op
  24:     0x7fdc95415d60 - <rustc_mir_transform[a8066d1d7333d1a3]::known_panics_lint::ConstPropagator as rustc_middle[10e0138f1f482b76]::mir::visit::Visitor>::visit_assign
  25:     0x7fdc9824765b - <rustc_mir_transform[a8066d1d7333d1a3]::known_panics_lint::ConstPropagator as rustc_middle[10e0138f1f482b76]::mir::visit::Visitor>::visit_body
  26:     0x7fdc9540de69 - <rustc_mir_transform[a8066d1d7333d1a3]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[a8066d1d7333d1a3]::pass_manager::MirLint>::run_lint
  27:     0x7fdc97c12289 - rustc_mir_transform[a8066d1d7333d1a3]::pass_manager::run_passes_inner
  28:     0x7fdc98363e06 - rustc_mir_transform[a8066d1d7333d1a3]::mir_drops_elaborated_and_const_checked
  29:     0x7fdc9836373d - rustc_query_impl[5f3fca9184d705d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5f3fca9184d705d1]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[10e0138f1f482b76]::query::erase::Erased<[u8; 8usize]>>
  30:     0x7fdc97e6bc30 - rustc_query_system[3c44b3ad726fdf36]::query::plumbing::try_execute_query::<rustc_query_impl[5f3fca9184d705d1]::DynamicConfig<rustc_query_system[3c44b3ad726fdf36]::query::caches::VecCache<rustc_span[6ccc48fe7a4f1f83]::def_id::LocalDefId, rustc_middle[10e0138f1f482b76]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5f3fca9184d705d1]::plumbing::QueryCtxt, false>
  31:     0x7fdc97e6b50c - rustc_query_impl[5f3fca9184d705d1]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7fdc987ee1fa - rustc_interface[94ec20dfe64cdcea]::passes::analysis
  33:     0x7fdc987ed9d9 - rustc_query_impl[5f3fca9184d705d1]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5f3fca9184d705d1]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[10e0138f1f482b76]::query::erase::Erased<[u8; 1usize]>>
  34:     0x7fdc98925643 - rustc_query_system[3c44b3ad726fdf36]::query::plumbing::try_execute_query::<rustc_query_impl[5f3fca9184d705d1]::DynamicConfig<rustc_query_system[3c44b3ad726fdf36]::query::caches::SingleCache<rustc_middle[10e0138f1f482b76]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[5f3fca9184d705d1]::plumbing::QueryCtxt, false>
  35:     0x7fdc989253bf - rustc_query_impl[5f3fca9184d705d1]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7fdc98934896 - rustc_interface[94ec20dfe64cdcea]::interface::run_compiler::<core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>, rustc_driver_impl[db1009755931a507]::run_compiler::{closure#0}>::{closure#0}
  37:     0x7fdc98bcaa4d - std[d1f7731e2ff5974d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[94ec20dfe64cdcea]::util::run_in_thread_with_globals<rustc_interface[94ec20dfe64cdcea]::util::run_in_thread_pool_with_globals<rustc_interface[94ec20dfe64cdcea]::interface::run_compiler<core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>, rustc_driver_impl[db1009755931a507]::run_compiler::{closure#0}>::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>
  38:     0x7fdc98bca87a - <<std[d1f7731e2ff5974d]::thread::Builder>::spawn_unchecked_<rustc_interface[94ec20dfe64cdcea]::util::run_in_thread_with_globals<rustc_interface[94ec20dfe64cdcea]::util::run_in_thread_pool_with_globals<rustc_interface[94ec20dfe64cdcea]::interface::run_compiler<core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>, rustc_driver_impl[db1009755931a507]::run_compiler::{closure#0}>::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[bd87c62ae3a7b4ee]::result::Result<(), rustc_span[6ccc48fe7a4f1f83]::ErrorGuaranteed>>::{closure#1} as core[bd87c62ae3a7b4ee]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7fdc99be1725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h11737601996c7bc7
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/alloc/src/boxed.rs:2016:9
  40:     0x7fdc99be1725 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb64bc4a2c7899523
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/alloc/src/boxed.rs:2016:9
  41:     0x7fdc99be1725 - std::sys::pal::unix::thread::Thread::new::thread_start::h9f6bca54366231ee
                               at /rustc/8f359beca4e58bc3ae795a666301a8f47023044c/library/std/src/sys/pal/unix/thread.rs:108:17
  42:     0x7fdc9387355a - <unknown>
  43:     0x7fdc938f0a3c - <unknown>
  44:                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: rustc 1.78.0-nightly (8f359beca 2024-02-23) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_drops_elaborated_and_const_checked] elaborating drops for `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error; 2 warnings emitted


@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 Feb 24, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 24, 2024
@matthiaskrgr
Copy link
Member Author

#119627 cc @oli-obk

@matthiaskrgr matthiaskrgr added the A-const-eval Area: constant evaluation (mir interpretation) label Feb 24, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Feb 24, 2024

Const prop 💀

We need to make it not do union field accesses

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 25, 2024
@gurry
Copy link
Contributor

gurry commented Feb 26, 2024

Reduced a bit further:

union union {
    union: u32,
    inion: i32,
}

pub fn main() {
    let union = union { union: 2 };
    let mnion = union { inion: 3 };
    let m1 = unsafe { mnion.union };
    let u1 = unsafe { union.union };
    
    let _r1 = u1 - m1;
}

@gurry
Copy link
Contributor

gurry commented Feb 26, 2024

@rustbot claim

@bors bors closed this as completed in 218be27 Feb 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 26, 2024
Rollup merge of rust-lang#121628 - gurry:121534-ice-asymm-binop, r=oli-obk

Do not const prop unions

Unions can produce values whose types don't match their underlying layout types which can lead to ICEs on eval.

Fixes rust-lang#121534
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) ❄️ 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