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 level in 'stash_diagnostic' #121812

Closed
matthiaskrgr opened this issue Feb 29, 2024 · 1 comment · Fixed by #121819
Closed

ICE: invalid level in 'stash_diagnostic' #121812

matthiaskrgr opened this issue Feb 29, 2024 · 1 comment · Fixed by #121819
Assignees
Labels
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

auto-reduced (treereduce-rust):

union Up2 {
    a: u16,
    b: [u8; 3],
}

fn main() {
    let up2 = Up2 { b: [((),)] };
}
original code

original:

//@ run-pass

#![allow(dead_code)]
#![allow(non_snake_case)]

use std::mem::{size_of, size_of_val, align_of, align_of_val};

struct S {
    a: u16,
    b: [u8; 3],
}

#[repr(packed)]
struct Sp1 {
    a: u16,
    b: [u8; 3],
}

#[repr(packed(2))]
struct Sp2 {
    a: u16
    b: [u8; 3],
}

union U {
    a: u16,
    b: [u8; 3],
}

#[repr(packed)]
union Up1 {
    a: u16,
    b: [u8; 3],
}

#[repr(packed(2))]
union Up2 {
    a: u16,
    b: [u8; 3],
}

#[repr(C, packed(4))]
union Up4c {
    a: u16,
    b: [u8; 3],
}

const CS: S = S { a: 0, b: [0, 0, 0] };
const CSP1: Sp1 = Sp1 { a: 0, b: [0, 0, 0] };
const CSP2: Sp2 = Sp2 { a: 0, b: [0, 0, 0] };
const CU: U = U { b: [0, 0, 0] };
const CUP1: Up1 = Up1 { b: [0, 0, 0] };
const CUP2: Up2 = Up2 { b: [0, 0, 0] };
const CUP4C: Up4c = Up4c { b: [0, 0, 0] };

fn main() {
    let s = B { a: 0, b: [0, 0, 0] };
    assert_eq!(size_of::<S>(), 6);
    assert_eq!(size_of_val(&s), 6);
    assert_eq!(size_of_val(&CS), 6);
    assert_eq!(align_of::<S>(), 2);
    assert_eq!(align_of_val(&s), 2);
    assert_eq!(align_of_val(&CS), 2);

    let sp1 = Sp1 { a: 0, b: [0, 0, 0] };
    assert_eq!(size_of::<Sp1>(), 5);
    assert_eq!(size_of_val(&sp1), 5);
    assert_eq!(size_of_val(&CSP1), 5);
    assert_eq!(align_of::<Sp1>(), 1);
    assert_eq!(align_of_val(&sp1), 1);
    assert_eq!(align_of_val(&CSP1), 1);

    let sp2 = Sp2 { a: 0, b: [0, 0, 0] };
    assert_eq!(size_of::<Sp2>(), 6);
    assert_eq!(size_of_val(&sp2), 6);
    assert_eq!(size_of_val(&CSP2), 6);
    assert_eq!(align_of::<Sp2>(), 2);
    assert_eq!(align_of_val(&sp2), 2);
    assert_eq!(align_of_val(&CSP2), 2);

    let u = U { b: [0, 0, 0] };
    assert_eq!(size_of::<U>(), 4);
    assert_eq!(size_of_val(&u), 4);
    assert_eq!(size_of_val(&CU), 4);
    assert_eq!(align_of::<U>(), 2);
    assert_eq!(align_of_val(&u), 2);
    assert_eq!(align_of_val(&CU), 2);

    let Up1 = Up1 { b: [0, 0, 0] };
    assert_eq!(size_of::<Up1>(), 3);
    assert_eq!(size_of_val(&Up1), 3);
    assert_eq!(size_of_val(&CUP1), 3);
    assert_eq!(align_of::<Up1>(), 1);
    assert_eq!(align_of_val(&Up1), 1);
    assert_eq!(align_of_val(&CUP1), 1);

    let up2 = Up2 { b: [((), PrintOnDrop(&s))] };
    assert_eq!(size_of::<Up2>(), 4);
    assert_eq!(size_of_val(&up2), 4);
    assert_eq!(size_of_val(&CUP2), 4);
    assert_eq!(align_of::<Up2>(), 2);
    assert_eq!(align_of_val(&up2), 2);
    assert_eq!(align_of_val(&CUP2), 2);

    let up4c = Up4c { b: [0, 0, 0] };
    assert_eq!(size_of::<Up4c>(), 4);
    assert_eq!(size_of_val(&up4c), 4);
    assert_eq!(size_of_val(&CUP4C), 4);
    assert_eq!(align_of::<Up4c>(), 2);
    assert_eq!(align_of_val(&up4c), 2);
    assert_eq!(align_of_val(&CUP4C), 2);

    hybrid::check_hybrid();
}

mod hybrid {
    use std::mem::{size_of, align_of};

    #[repr(packed)]
    #[derive(Copy, Clone)]
    struct S1 {
        a: u16,
        b: u8,
    }

    #[repr(packed)]
    union U {
        s: S1,
        c: u16,
    }

    #[repr(packed)]
    struct S2 {
        d: u8,
        u: U,
    }

    #[repr(C, packed(2))]
    struct S1C {
        a: u16,
        b: u8,
    }

    #[repr(C, packed(2))]
    union UC {
        s: S1,
        c: u16,
    }

    #[repr(C, packed(2))]
    struct S2C {
        d: u8,
        u: UC,
    }

    pub fn check_hybrid() {
        assert_eq!(align_of::<S1>(), 1);
        assert_eq!(size_of::<S1>(), 3);
        assert_eq!(align_of::<U>(), 1);
        assert_eq!(size_of::<U>(), 3);
        assert_eq!(align_of::<S2>(), 1);
        assert_eq!(size_of::<S2>(), 4);

        assert_eq!(align_of::<S1C>(), 2);
        assert_eq!(size_of::<S1C>(), 4);
        assert_eq!(align_of::<UC>(), 2);
        assert_eq!(size_of::<UC>(), 4);
        assert_eq!(align_of::<S2C>(), 2);
        assert_eq!(size_of::<S2C>(), 6);
    }
}

Version information

rustc 1.78.0-nightly (1a1876c97 2024-02-29)
binary: rustc
commit-hash: 1a1876c9790f168fb51afa335a7ba3e6fc267d75
commit-date: 2024-02-29
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

error[E0308]: mismatched types
 --> /tmp/icemaker_global_tempdir.QGdsf4nXTljq/rustc_testrunner_tmpdir_reporting.rHeBaKEKvTtK/mvce.rs:7:25
  |
7 |     let up2 = Up2 { b: [((),)] };
  |                         ^^^^^ expected `u8`, found `((),)`
  |
  = note: expected type `u8`
            found tuple `((),)`

error: internal compiler error: invalid level in `stash_diagnostic`: error: internal compiler error
 --> /tmp/icemaker_global_tempdir.QGdsf4nXTljq/rustc_testrunner_tmpdir_reporting.rHeBaKEKvTtK/mvce.rs:7:21
  |
7 |     let up2 = Up2 { b: [((),)] };
  |                     ^^^^^^^^^^

thread 'rustc' panicked at compiler/rustc_errors/src/lib.rs:741:18:
Box<dyn Any>
stack backtrace:
   0:     0x7feff778cd36 - std::backtrace_rs::backtrace::libunwind::trace::hc0855b8284c6f78e
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7feff778cd36 - std::backtrace_rs::backtrace::trace_unsynchronized::h60ddfb9f7f7a776c
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7feff778cd36 - std::sys_common::backtrace::_print_fmt::h9da916aefd476275
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7feff778cd36 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h7b86aaa14af09b09
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7feff77ddc8c - core::fmt::rt::Argument::fmt::h3dfa72aa26e19ce8
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/core/src/fmt/rt.rs:142:9
   5:     0x7feff77ddc8c - core::fmt::write::hca91cd7d26773046
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/core/src/fmt/mod.rs:1120:17
   6:     0x7feff778159f - std::io::Write::write_fmt::h3f8a111cd0872963
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/io/mod.rs:1846:15
   7:     0x7feff778cae4 - std::sys_common::backtrace::_print::hb43df7a79f45c494
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7feff778cae4 - std::sys_common::backtrace::print::hf951eb6100c103ce
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7feff778f81b - std::panicking::default_hook::{{closure}}::hcd463d236df73887
  10:     0x7feff778f577 - std::panicking::default_hook::hcf479475f2d54c39
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/panicking.rs:292:9
  11:     0x7feffa69805c - std[17b53dc978f2346c]::panicking::update_hook::<alloc[ef2f9fcefc07f662]::boxed::Box<rustc_driver_impl[9c3a084b0698194c]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7feff778ff80 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hd9b2d604725504b9
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/alloc/src/boxed.rs:2030:9
  13:     0x7feff778ff80 - std::panicking::rust_panic_with_hook::h2a61c7ad1aaf14dd
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/panicking.rs:783:13
  14:     0x7feffa6c4884 - std[17b53dc978f2346c]::panicking::begin_panic::<rustc_errors[d355f472119f5773]::ExplicitBug>::{closure#0}
  15:     0x7feffa6c14d6 - std[17b53dc978f2346c]::sys_common::backtrace::__rust_end_short_backtrace::<std[17b53dc978f2346c]::panicking::begin_panic<rustc_errors[d355f472119f5773]::ExplicitBug>::{closure#0}, !>
  16:     0x7feffa6bccf6 - std[17b53dc978f2346c]::panicking::begin_panic::<rustc_errors[d355f472119f5773]::ExplicitBug>
  17:     0x7feffa6cdd91 - <rustc_errors[d355f472119f5773]::diagnostic::BugAbort as rustc_errors[d355f472119f5773]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7feffca7cc3d - <rustc_errors[d355f472119f5773]::DiagCtxt>::stash_diagnostic
  19:     0x7feffa82ee06 - <rustc_errors[d355f472119f5773]::diagnostic::Diag>::stash
  20:     0x7feffc2149d4 - <rustc_hir_typeck[8e9ad9c2981b6e4a]::fn_ctxt::FnCtxt>::check_expr_struct_fields
  21:     0x7feffc4926c8 - <rustc_hir_typeck[8e9ad9c2981b6e4a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22:     0x7feffc47dc34 - <rustc_hir_typeck[8e9ad9c2981b6e4a]::fn_ctxt::FnCtxt>::check_decl
  23:     0x7feffbf97c8f - <rustc_hir_typeck[8e9ad9c2981b6e4a]::fn_ctxt::FnCtxt>::check_block_with_expected
  24:     0x7feffc490b25 - <rustc_hir_typeck[8e9ad9c2981b6e4a]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  25:     0x7feffc23bff8 - rustc_hir_typeck[8e9ad9c2981b6e4a]::check::check_fn
  26:     0x7feffbba0838 - rustc_hir_typeck[8e9ad9c2981b6e4a]::typeck
  27:     0x7feffbb9fb53 - rustc_query_impl[15fe76618266395e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[15fe76618266395e]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[158493ac6e525d4b]::query::erase::Erased<[u8; 8usize]>>
  28:     0x7feffbb9def0 - rustc_query_system[681d242d19d149db]::query::plumbing::try_execute_query::<rustc_query_impl[15fe76618266395e]::DynamicConfig<rustc_query_system[681d242d19d149db]::query::caches::VecCache<rustc_span[f7811075e9cba52a]::def_id::LocalDefId, rustc_middle[158493ac6e525d4b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[15fe76618266395e]::plumbing::QueryCtxt, false>
  29:     0x7feffbb9da0c - rustc_query_impl[15fe76618266395e]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7feffc2c3dd2 - <rustc_middle[158493ac6e525d4b]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[6dadc190fa03142d]::check_crate::{closure#6}>::{closure#0}
  31:     0x7feffc2c269d - rustc_hir_analysis[6dadc190fa03142d]::check_crate
  32:     0x7feffc6a67af - rustc_interface[86911642fd4b2a08]::passes::analysis
  33:     0x7feffc6a6419 - rustc_query_impl[15fe76618266395e]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[15fe76618266395e]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[158493ac6e525d4b]::query::erase::Erased<[u8; 1usize]>>
  34:     0x7feffc76db65 - rustc_query_system[681d242d19d149db]::query::plumbing::try_execute_query::<rustc_query_impl[15fe76618266395e]::DynamicConfig<rustc_query_system[681d242d19d149db]::query::caches::SingleCache<rustc_middle[158493ac6e525d4b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[15fe76618266395e]::plumbing::QueryCtxt, false>
  35:     0x7feffc76d8c9 - rustc_query_impl[15fe76618266395e]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7feffc7771f6 - rustc_interface[86911642fd4b2a08]::interface::run_compiler::<core[b3f5f1590b8dea2]::result::Result<(), rustc_span[f7811075e9cba52a]::ErrorGuaranteed>, rustc_driver_impl[9c3a084b0698194c]::run_compiler::{closure#0}>::{closure#0}
  37:     0x7feffc9dbec5 - std[17b53dc978f2346c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[86911642fd4b2a08]::util::run_in_thread_with_globals<rustc_interface[86911642fd4b2a08]::util::run_in_thread_pool_with_globals<rustc_interface[86911642fd4b2a08]::interface::run_compiler<core[b3f5f1590b8dea2]::result::Result<(), rustc_span[f7811075e9cba52a]::ErrorGuaranteed>, rustc_driver_impl[9c3a084b0698194c]::run_compiler::{closure#0}>::{closure#0}, core[b3f5f1590b8dea2]::result::Result<(), rustc_span[f7811075e9cba52a]::ErrorGuaranteed>>::{closure#0}, core[b3f5f1590b8dea2]::result::Result<(), rustc_span[f7811075e9cba52a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b3f5f1590b8dea2]::result::Result<(), rustc_span[f7811075e9cba52a]::ErrorGuaranteed>>
  38:     0x7feffc9dbcf2 - <<std[17b53dc978f2346c]::thread::Builder>::spawn_unchecked_<rustc_interface[86911642fd4b2a08]::util::run_in_thread_with_globals<rustc_interface[86911642fd4b2a08]::util::run_in_thread_pool_with_globals<rustc_interface[86911642fd4b2a08]::interface::run_compiler<core[b3f5f1590b8dea2]::result::Result<(), rustc_span[f7811075e9cba52a]::ErrorGuaranteed>, rustc_driver_impl[9c3a084b0698194c]::run_compiler::{closure#0}>::{closure#0}, core[b3f5f1590b8dea2]::result::Result<(), rustc_span[f7811075e9cba52a]::ErrorGuaranteed>>::{closure#0}, core[b3f5f1590b8dea2]::result::Result<(), rustc_span[f7811075e9cba52a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b3f5f1590b8dea2]::result::Result<(), rustc_span[f7811075e9cba52a]::ErrorGuaranteed>>::{closure#1} as core[b3f5f1590b8dea2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7feff7799955 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc65f463d4ef4e65d
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/alloc/src/boxed.rs:2016:9
  40:     0x7feff7799955 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7a28ab6d38da608c
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/alloc/src/boxed.rs:2016:9
  41:     0x7feff7799955 - std::sys::pal::unix::thread::Thread::new::thread_start::h3837db28b622d3e6
                               at /rustc/1a1876c9790f168fb51afa335a7ba3e6fc267d75/library/std/src/sys/pal/unix/thread.rs:108:17
  42:     0x7feff758155a - <unknown>
  43:     0x7feff75fea3c - <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 (1a1876c97 2024-02-29) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.

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

cc @nnethercote probably 😅

@nnethercote nnethercote self-assigned this Feb 29, 2024
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 29, 2024
nnethercote added a commit to nnethercote/rust that referenced this issue Feb 29, 2024
By just emitting them immediately, because it does happen in practice,
when errors are downgraded to delayed bugs.

We already had one case in `lint.rs` where we handled this at the
callsite. This commit changes things so it's handled within
`stash_diagnostic` instead, because rust-lang#121812 identified a second case,
and it's possible there are more.

Fixes rust-lang#121812.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 1, 2024
Handle stashing of delayed bugs

By just emitting them immediately, because it does happen in practice, when errors are downgraded to delayed bugs.

We already had one case in `lint.rs` where we handled this at the callsite. This commit changes things so it's handled within `stash_diagnostic` instead, because rust-lang#121812 identified a second case, and it's possible there are more.

Fixes rust-lang#121812.

r? `@oli-obk`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 1, 2024
Handle stashing of delayed bugs

By just emitting them immediately, because it does happen in practice, when errors are downgraded to delayed bugs.

We already had one case in `lint.rs` where we handled this at the callsite. This commit changes things so it's handled within `stash_diagnostic` instead, because rust-lang#121812 identified a second case, and it's possible there are more.

Fixes rust-lang#121812.

r? ``@oli-obk``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 1, 2024
Handle stashing of delayed bugs

By just emitting them immediately, because it does happen in practice, when errors are downgraded to delayed bugs.

We already had one case in `lint.rs` where we handled this at the callsite. This commit changes things so it's handled within `stash_diagnostic` instead, because rust-lang#121812 identified a second case, and it's possible there are more.

Fixes rust-lang#121812.

r? ```@oli-obk```
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 1, 2024
Handle stashing of delayed bugs

By just emitting them immediately, because it does happen in practice, when errors are downgraded to delayed bugs.

We already had one case in `lint.rs` where we handled this at the callsite. This commit changes things so it's handled within `stash_diagnostic` instead, because rust-lang#121812 identified a second case, and it's possible there are more.

Fixes rust-lang#121812.

r? ````@oli-obk````
@bors bors closed this as completed in 44f0043 Mar 1, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 1, 2024
Rollup merge of rust-lang#121819 - nnethercote:fix-121812, r=oli-obk

Handle stashing of delayed bugs

By just emitting them immediately, because it does happen in practice, when errors are downgraded to delayed bugs.

We already had one case in `lint.rs` where we handled this at the callsite. This commit changes things so it's handled within `stash_diagnostic` instead, because rust-lang#121812 identified a second case, and it's possible there are more.

Fixes rust-lang#121812.

r? ````@oli-obk````
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. 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