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: could not find allocation for alloc3 #126393

Closed
matthiaskrgr opened this issue Jun 13, 2024 · 4 comments · Fixed by #126426
Closed

ICE: could not find allocation for alloc3 #126393

matthiaskrgr opened this issue Jun 13, 2024 · 4 comments · Fixed by #126426
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` 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):

extern "C" {
    pub type ExternType;
}

pub struct Wrapper(ExternType);
pub static MAGIC_FFI_REF: &'static Wrapper = unsafe {
    std::mem::transmute(&{
        let y = 42;
        y
    })
};

original:

//@ check-pass

// Test that we can handle newtypes wrapping extern types

#![feature(extern_types)]

use std::marker::PhantomData;

extern "C" {
  pub type ExternType;
}
unsafe impl Sync for ExternType {}
static MAGIC_FFI_STATIC: u8 = 42;

#[repr(transparent)]
pub struct Wrapper(ExternType);
pub static MAGIC_FFI_REF: &'static Wrapper = unsafe {
  std::mem::transmute(&{ //~ ERROR temporary value dropped while borrowed
        let y = 42;
        y
    })
};

#[repr(MAGIC_FFI_REF2)]
pub struct Wrapper2(PhantomData<Vec<i32>>, ExternType);
pub static MAGIC_FFI_REF2: &'static Wrapper2 = unsafe {
  std::mem::transmute(&MAGIC_FFI_STATIC)
};

fn main() {}

Version information

rustc 1.81.0-nightly (c25ac9d6c 2024-06-12)
binary: rustc
commit-hash: c25ac9d6cc285e57e1176dc2da6848b9d0163810
commit-date: 2024-06-12
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

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

Program output

error[E0658]: extern types are experimental
 --> /tmp/icemaker_global_tempdir.SZuuVndvH6Hc/rustc_testrunner_tmpdir_reporting.sWVUdMqkpzcR/mvce.rs:2:5
  |
2 |     pub type ExternType;
  |     ^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #43467 <https://github.com/rust-lang/rust/issues/43467> for more information
  = help: add `#![feature(extern_types)]` to the crate attributes to enable
  = note: this compiler was built on 2024-06-12; consider upgrading it if it is out of date

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.SZuuVndvH6Hc/rustc_testrunner_tmpdir_reporting.sWVUdMqkpzcR/mvce.rs:11:3
   |
11 | };
   |   ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.SZuuVndvH6Hc/rustc_testrunner_tmpdir_reporting.sWVUdMqkpzcR/mvce.rs`

error[E0277]: `ExternType` cannot be shared between threads safely
 --> /tmp/icemaker_global_tempdir.SZuuVndvH6Hc/rustc_testrunner_tmpdir_reporting.sWVUdMqkpzcR/mvce.rs:6:27
  |
6 | pub static MAGIC_FFI_REF: &'static Wrapper = unsafe {
  |                           ^^^^^^^^^^^^^^^^ `ExternType` cannot be shared between threads safely
  |
  = help: within `&'static Wrapper`, the trait `Sync` is not implemented for `ExternType`, which is required by `&'static Wrapper: Sync`
note: required because it appears within the type `Wrapper`
 --> /tmp/icemaker_global_tempdir.SZuuVndvH6Hc/rustc_testrunner_tmpdir_reporting.sWVUdMqkpzcR/mvce.rs:5:12
  |
5 | pub struct Wrapper(ExternType);
  |            ^^^^^^^
  = note: required because it appears within the type `&'static Wrapper`
  = note: shared static variables must have a type that implements `Sync`

error: internal compiler error: compiler/rustc_const_eval/src/interpret/validity.rs:708:19: could not find allocation for alloc2

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/validity.rs:708:19:
Box<dyn Any>
stack backtrace:
   0:     0x77051b809ae5 - std::backtrace_rs::backtrace::libunwind::trace::h6be50cef0e090531
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x77051b809ae5 - std::backtrace_rs::backtrace::trace_unsynchronized::h84167074cb4f1713
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x77051b809ae5 - std::sys_common::backtrace::_print_fmt::hb5cf039fd1f30b07
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x77051b809ae5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h01adaba1565f117f
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x77051b85a77b - core::fmt::rt::Argument::fmt::h2910e36f4e21d32d
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/core/src/fmt/rt.rs:165:63
   5:     0x77051b85a77b - core::fmt::write::h6d9d2f7ff8571b34
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/core/src/fmt/mod.rs:1168:21
   6:     0x77051b7fe6bf - std::io::Write::write_fmt::hd882c0f914f56bf0
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/io/mod.rs:1835:15
   7:     0x77051b8098be - std::sys_common::backtrace::_print::hcc6c907dafd9aacb
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x77051b8098be - std::sys_common::backtrace::print::h2c716a051c9b24be
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x77051b80c2f9 - std::panicking::default_hook::{{closure}}::he8ad829f77bd4e23
  10:     0x77051b80c09c - std::panicking::default_hook::heb22a1402d2cff23
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/panicking.rs:292:9
  11:     0x7705180b2c9f - std[5c07af62f3786d14]::panicking::update_hook::<alloc[eebcfc85002bd7db]::boxed::Box<rustc_driver_impl[2b4723ede88f52b1]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x77051b80cbff - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hd8f0fcaec26c179e
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/alloc/src/boxed.rs:2076:9
  13:     0x77051b80cbff - std::panicking::rust_panic_with_hook::hc9dbad8884217847
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/panicking.rs:801:13
  14:     0x7705180e3621 - std[5c07af62f3786d14]::panicking::begin_panic::<rustc_errors[d9dad43edaa48690]::ExplicitBug>::{closure#0}
  15:     0x7705180e03d6 - std[5c07af62f3786d14]::sys_common::backtrace::__rust_end_short_backtrace::<std[5c07af62f3786d14]::panicking::begin_panic<rustc_errors[d9dad43edaa48690]::ExplicitBug>::{closure#0}, !>
  16:     0x7705180e00b6 - std[5c07af62f3786d14]::panicking::begin_panic::<rustc_errors[d9dad43edaa48690]::ExplicitBug>
  17:     0x7705180ecb71 - <rustc_errors[d9dad43edaa48690]::diagnostic::BugAbort as rustc_errors[d9dad43edaa48690]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7705185da21c - rustc_middle[f645b954b6a941ee]::util::bug::opt_span_bug_fmt::<rustc_span[9012e0e35e67507c]::span_encoding::Span>::{closure#0}
  19:     0x7705185c328a - rustc_middle[f645b954b6a941ee]::ty::context::tls::with_opt::<rustc_middle[f645b954b6a941ee]::util::bug::opt_span_bug_fmt<rustc_span[9012e0e35e67507c]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7705185c310b - rustc_middle[f645b954b6a941ee]::ty::context::tls::with_context_opt::<rustc_middle[f645b954b6a941ee]::ty::context::tls::with_opt<rustc_middle[f645b954b6a941ee]::util::bug::opt_span_bug_fmt<rustc_span[9012e0e35e67507c]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x770515fdddb0 - rustc_middle[f645b954b6a941ee]::util::bug::bug_fmt
  22:     0x77051aa9a7bd - rustc_const_eval[6538e0f20481f9b7]::interpret::validity::mutability::<rustc_const_eval[6538e0f20481f9b7]::const_eval::machine::CompileTimeInterpreter>.cold
  23:     0x770519b54b22 - <rustc_const_eval[6538e0f20481f9b7]::interpret::validity::ValidityVisitor<rustc_const_eval[6538e0f20481f9b7]::const_eval::machine::CompileTimeInterpreter>>::check_safe_pointer
  24:     0x770519b6f0c9 - <rustc_const_eval[6538e0f20481f9b7]::interpret::eval_context::InterpCx<rustc_const_eval[6538e0f20481f9b7]::const_eval::machine::CompileTimeInterpreter>>::validate_operand_internal
  25:     0x77051a5c1ae9 - rustc_const_eval[6538e0f20481f9b7]::const_eval::eval_queries::eval_body_using_ecx::<rustc_middle[f645b954b6a941ee]::mir::interpret::allocation::ConstAllocation>
  26:     0x77051a581705 - rustc_const_eval[6538e0f20481f9b7]::const_eval::eval_queries::eval_static_initializer_provider
  27:     0x77051a5814a7 - rustc_query_impl[860f4585269295fe]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[860f4585269295fe]::query_impl::eval_static_initializer::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f645b954b6a941ee]::query::erase::Erased<[u8; 16usize]>>
  28:     0x77051a581489 - <rustc_query_impl[860f4585269295fe]::query_impl::eval_static_initializer::dynamic_query::{closure#2} as core[207868f0da9fe1eb]::ops::function::FnOnce<(rustc_middle[f645b954b6a941ee]::ty::context::TyCtxt, rustc_span[9012e0e35e67507c]::def_id::DefId)>>::call_once
  29:     0x770519a1cc80 - rustc_query_system[88bb5c8529314a04]::query::plumbing::try_execute_query::<rustc_query_impl[860f4585269295fe]::DynamicConfig<rustc_query_system[88bb5c8529314a04]::query::caches::DefIdCache<rustc_middle[f645b954b6a941ee]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[860f4585269295fe]::plumbing::QueryCtxt, false>
  30:     0x77051a2416c3 - rustc_query_impl[860f4585269295fe]::query_impl::eval_static_initializer::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7705196b868a - <rustc_middle[f645b954b6a941ee]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[f165ce28b444ebe1]::check_crate::{closure#3}>::{closure#0}
  32:     0x7705196b69a2 - rustc_hir_analysis[f165ce28b444ebe1]::check_crate
  33:     0x770519e4f13e - rustc_interface[8465b2f8b714accd]::passes::analysis
  34:     0x770519e4ec87 - rustc_query_impl[860f4585269295fe]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[860f4585269295fe]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f645b954b6a941ee]::query::erase::Erased<[u8; 1usize]>>
  35:     0x77051a1f7d25 - rustc_query_system[88bb5c8529314a04]::query::plumbing::try_execute_query::<rustc_query_impl[860f4585269295fe]::DynamicConfig<rustc_query_system[88bb5c8529314a04]::query::caches::SingleCache<rustc_middle[f645b954b6a941ee]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[860f4585269295fe]::plumbing::QueryCtxt, false>
  36:     0x77051a1f7a8f - rustc_query_impl[860f4585269295fe]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  37:     0x77051a0d0952 - rustc_interface[8465b2f8b714accd]::interface::run_compiler::<core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>, rustc_driver_impl[2b4723ede88f52b1]::run_compiler::{closure#0}>::{closure#1}
  38:     0x77051a0ef649 - std[5c07af62f3786d14]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[8465b2f8b714accd]::util::run_in_thread_with_globals<rustc_interface[8465b2f8b714accd]::util::run_in_thread_pool_with_globals<rustc_interface[8465b2f8b714accd]::interface::run_compiler<core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>, rustc_driver_impl[2b4723ede88f52b1]::run_compiler::{closure#0}>::{closure#1}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#0}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>
  39:     0x77051a0ef3fa - <<std[5c07af62f3786d14]::thread::Builder>::spawn_unchecked_<rustc_interface[8465b2f8b714accd]::util::run_in_thread_with_globals<rustc_interface[8465b2f8b714accd]::util::run_in_thread_pool_with_globals<rustc_interface[8465b2f8b714accd]::interface::run_compiler<core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>, rustc_driver_impl[2b4723ede88f52b1]::run_compiler::{closure#0}>::{closure#1}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#0}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[207868f0da9fe1eb]::result::Result<(), rustc_span[9012e0e35e67507c]::ErrorGuaranteed>>::{closure#2} as core[207868f0da9fe1eb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  40:     0x77051b816a7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd64233370b4bbb13
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/alloc/src/boxed.rs:2062:9
  41:     0x77051b816a7b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8b9a0bf226b4eb10
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/alloc/src/boxed.rs:2062:9
  42:     0x77051b816a7b - std::sys::pal::unix::thread::Thread::new::thread_start::h25e4cee516ffa27e
                               at /rustc/c25ac9d6cc285e57e1176dc2da6848b9d0163810/library/std/src/sys/pal/unix/thread.rs:108:17
  43:     0x770514ca6ded - <unknown>
  44:     0x770514d2a0dc - <unknown>
  45:                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: please make sure that you have updated to the latest nightly

note: rustc 1.81.0-nightly (c25ac9d6c 2024-06-12) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [eval_static_initializer] evaluating initializer of static `MAGIC_FFI_REF`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0277, E0601, E0658.
For more information about an error, try `rustc --explain E0277`.

@rustbot label +F-extern_types

@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 Jun 13, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-extern_types `#![feature(extern_types)]` labels Jun 13, 2024
@matthiaskrgr
Copy link
Member Author

Regression in nightly-2024-05-23

#117329 cc @RalfJung 🤔

@RalfJung
Copy link
Member

#[repr(MAGIC_FFI_REF2)]

But why?^^
Anyway it doesn't seem to affect the test.

@RalfJung
Copy link
Member

This is not a recent regression, here's a reproducer on stable:

pub struct Wrapper;
pub static MAGIC_FFI_REF: &'static Wrapper = unsafe {
    std::mem::transmute(&{
        let y = 42;
        y
    })
};

@matthiaskrgr
Copy link
Member Author

But why?^^

lol XD its just side effect of the fuzzing I guess :D

@bors bors closed this as completed in aebd794 Jun 14, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 14, 2024
Rollup merge of rust-lang#126426 - RalfJung:dangling-zst-ice, r=oli-obk

const validation: fix ICE on dangling ZST reference

Fixes rust-lang#126393
I'm not super happy with this fix but I can't think of a better one.

r? `@oli-obk`
@saethlin saethlin added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 15, 2024
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, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` 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