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 bool 0x62 with associated_type_bounds #1433

Closed
matthiaskrgr opened this issue Nov 27, 2023 · 3 comments
Closed

ICE: Invalid bool 0x62 with associated_type_bounds #1433

matthiaskrgr opened this issue Nov 27, 2023 · 3 comments
Labels
C-bug Category: This is a bug.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Nov 27, 2023

rustc src/main.rs -Zcodegen-backend=cranelift -Zmir-opt-level=2

#![feature(associated_type_bounds)]

trait Tr1: Copy {
    type As1: Copy;
}

impl Tr1 for &str {
    type As1 = bool;
}

union Un3<T: Tr1<As1: 'static>> {
    outest: T,
    outer: &'static T::As1,
}

fn main() {
    let mut un3 = Un3 { outest: "baz" };

    assert_eq!(unsafe { *un3.outer }, true);
}
warning: variable does not need to be mutable
  --> src/main.rs:17:9
   |
17 |     let mut un3 = Un3 { outest: "baz" };
   |         ----^^^
   |         |
   |         help: remove this `mut`
   |
   = note: `#[warn(unused_mut)]` on by default

thread 'rustc' panicked at src/value_and_place.rs:318:13:
Invalid bool 0x62
stack backtrace:
   0:     0x7f569798b98c - std::backtrace_rs::backtrace::libunwind::trace::hdfc67f1e7ca3c26b
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f569798b98c - std::backtrace_rs::backtrace::trace_unsynchronized::heaa4a195a32ae345
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f569798b98c - std::sys_common::backtrace::_print_fmt::h4c39da8734214301
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f569798b98c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hbf3d4e80620f48cb
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f56979de9c0 - core::fmt::rt::Argument::fmt::hc8377a2d1190c9aa
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/core/src/fmt/rt.rs:142:9
   5:     0x7f56979de9c0 - core::fmt::write::h92bfd03dd3380be9
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f569797f84f - std::io::Write::write_fmt::hd1ba441fb09101d3
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/io/mod.rs:1766:15
   7:     0x7f569798b774 - std::sys_common::backtrace::_print::hd410e96536a9939b
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f569798b774 - std::sys_common::backtrace::print::h4164b49f6454fc6a
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f569798e407 - std::panicking::default_hook::{{closure}}::ha1a9f4255b168905
  10:     0x7f569798e16f - std::panicking::default_hook::hace399fd6c6ac32c
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/panicking.rs:292:9
  11:     0x7f569a6e48b0 - std[1dc220fc4c0ef824]::panicking::update_hook::<alloc[1aeee6991bd49b3f]::boxed::Box<rustc_driver_impl[45fab285649c23b2]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f569798eb48 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hfb05686be3af21d4
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/alloc/src/boxed.rs:2021:9
  13:     0x7f569798eb48 - std::panicking::rust_panic_with_hook::h687a0dbad3543b4f
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/panicking.rs:783:13
  14:     0x7f569798e89e - std::panicking::begin_panic_handler::{{closure}}::h0e1063442cc3cc04
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/panicking.rs:657:13
  15:     0x7f569798be56 - std::sys_common::backtrace::__rust_end_short_backtrace::h121fc3b3bde77e14
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f569798e602 - rust_begin_unwind
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/panicking.rs:645:5
  17:     0x7f56979db0a5 - core::panicking::panic_fmt::h087e25bd2388ac03
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/core/src/panicking.rs:72:14
  18:     0x7f568e057655 - <rustc_codegen_cranelift[1e1ab29f9bae4b04]::value_and_place::CValue>::const_val
  19:     0x7f568e0188f8 - rustc_codegen_cranelift[1e1ab29f9bae4b04]::constant::codegen_const_value
  20:     0x7f568e011c07 - rustc_codegen_cranelift[1e1ab29f9bae4b04]::base::codegen_operand
  21:     0x7f568e00862f - rustc_codegen_cranelift[1e1ab29f9bae4b04]::base::codegen_fn_body
  22:     0x7f568e02283a - rustc_codegen_cranelift[1e1ab29f9bae4b04]::driver::aot::module_codegen::{closure#0}
  23:     0x7f568e01f9d5 - rustc_codegen_cranelift[1e1ab29f9bae4b04]::driver::aot::module_codegen
  24:     0x7f568e02c17c - rustc_codegen_cranelift[1e1ab29f9bae4b04]::driver::aot::run_aot
  25:     0x7f568e05abda - <rustc_codegen_cranelift[1e1ab29f9bae4b04]::CraneliftCodegenBackend as rustc_codegen_ssa[a0c122d06cf22e6d]::traits::backend::CodegenBackend>::codegen_crate
  26:     0x7f569c391705 - rustc_interface[56e8e5a742480a4b]::passes::start_codegen
  27:     0x7f569c390e5f - <rustc_interface[56e8e5a742480a4b]::queries::Queries>::codegen_and_build_linker
  28:     0x7f569c737e5c - rustc_interface[56e8e5a742480a4b]::interface::run_compiler::<core[d0ccb57ccfd673f9]::result::Result<(), rustc_span[476eee35b566d70f]::ErrorGuaranteed>, rustc_driver_impl[45fab285649c23b2]::run_compiler::{closure#0}>::{closure#0}
  29:     0x7f569c979ad4 - std[1dc220fc4c0ef824]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[56e8e5a742480a4b]::util::run_in_thread_with_globals<rustc_interface[56e8e5a742480a4b]::util::run_in_thread_pool_with_globals<rustc_interface[56e8e5a742480a4b]::interface::run_compiler<core[d0ccb57ccfd673f9]::result::Result<(), rustc_span[476eee35b566d70f]::ErrorGuaranteed>, rustc_driver_impl[45fab285649c23b2]::run_compiler::{closure#0}>::{closure#0}, core[d0ccb57ccfd673f9]::result::Result<(), rustc_span[476eee35b566d70f]::ErrorGuaranteed>>::{closure#0}, core[d0ccb57ccfd673f9]::result::Result<(), rustc_span[476eee35b566d70f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d0ccb57ccfd673f9]::result::Result<(), rustc_span[476eee35b566d70f]::ErrorGuaranteed>>
  30:     0x7f569c9798fd - <<std[1dc220fc4c0ef824]::thread::Builder>::spawn_unchecked_<rustc_interface[56e8e5a742480a4b]::util::run_in_thread_with_globals<rustc_interface[56e8e5a742480a4b]::util::run_in_thread_pool_with_globals<rustc_interface[56e8e5a742480a4b]::interface::run_compiler<core[d0ccb57ccfd673f9]::result::Result<(), rustc_span[476eee35b566d70f]::ErrorGuaranteed>, rustc_driver_impl[45fab285649c23b2]::run_compiler::{closure#0}>::{closure#0}, core[d0ccb57ccfd673f9]::result::Result<(), rustc_span[476eee35b566d70f]::ErrorGuaranteed>>::{closure#0}, core[d0ccb57ccfd673f9]::result::Result<(), rustc_span[476eee35b566d70f]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d0ccb57ccfd673f9]::result::Result<(), rustc_span[476eee35b566d70f]::ErrorGuaranteed>>::{closure#1} as core[d0ccb57ccfd673f9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  31:     0x7f56979989e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h16241ade875ace78
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/alloc/src/boxed.rs:2007:9
  32:     0x7f56979989e5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0d92a7e8b2e21f1b
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/alloc/src/boxed.rs:2007:9
  33:     0x7f56979989e5 - std::sys::unix::thread::Thread::new::thread_start::h9e600b3dd7be7655
                               at /rustc/f5dc2653fdd8b5d177b2ccbd84057954340a89fc/library/std/src/sys/unix/thread.rs:108:17
  34:     0x7f56977899eb - <unknown>
  35:     0x7f569780d7cc - <unknown>
  36:                0x0 - <unknown>

error: 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: please attach the file at `/tmp/im/f/rustc-ice-2023-11-27T10_34_27-3324716.txt` to your bug report

note: compiler flags: -Z codegen-backend=cranelift -Z mir-opt-level=2

query stack during panic:
end of query stack
stmt _3 = const {transmute(0x62): bool}
fn main() -> () {
    let mut _0: ();
    let mut _1: Un3<&str>;
    let mut _2: &bool;
    let _3: bool;
    let mut _4: bool;
    let mut _5: bool;
    let _6: !;
    let mut _7: std::option::Option<std::fmt::Arguments<'_>>;
    scope 1 {
        debug un3 => _1;
        let mut _8: &bool;
        scope 2 {
        }
        scope 3 {
            debug left_val => _2;
            debug right_val => const _;
            scope 4 {
                debug kind => const core::panicking::AssertKind::Eq;
            }
        }
    }

    bb0: {
        _1 = Un3::<&str> { outest: const "baz" };
        _3 = const {transmute(0x62): bool};
        _2 = &_3;
        _8 = const _;
        _5 = (*_2);
        _4 = Eq(move _5, const true);
        switchInt(move _4) -> [0: bb2, otherwise: bb1];
    }

    bb1: {
        return;
    }

    bb2: {
        _7 = std::option::Option::<std::fmt::Arguments<'_>>::None;
        _6 = core::panicking::assert_failed::<bool, bool>(const core::panicking::AssertKind::Eq, move _2, move _8, move _7) -> unwind continue;
    }
}
@matthiaskrgr
Copy link
Member Author

woth noting that miri rejects this as UB

error: Undefined Behavior: constructing invalid value: encountered 0x62, but expected a boolean
--> src/main.rs:19:25
|
19 | assert_eq!(unsafe { *un3.outer }, true);
| ^^^^^^^^^^ constructing invalid value: encountered 0x62, but expected a boolean
|

@matthiaskrgr matthiaskrgr changed the title ICE: Invalid bool 0x62Invalid bool 0x62 with associated_type_bounds ICE: Invalid bool 0x62 with associated_type_bounds Nov 27, 2023
@bjorn3
Copy link
Member

bjorn3 commented Jan 26, 2024

I can't reproduce this with latest cg_clif. I don't know if it is fixed now or if I did something wrong.

@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Jan 27, 2024

fn main() {
    let b = unsafe { std::mem::transmute::<u8, bool>(2) };
    let _x = b == std::hint::black_box(true); //~ ERROR: interpreting an invalid 8-bit value as a bool
}

with Zcodegen-backend=cranelift -Zmir-opt-level=2 still repros this

@bjorn3 bjorn3 added the C-bug Category: This is a bug. label May 11, 2024
@bjorn3 bjorn3 closed this as completed in 9e4e805 May 11, 2024
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.
Projects
None yet
Development

No branches or pull requests

2 participants