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 when creating a reference to an (extern?) value of an extern type in a static context #104685

Open
CheaterCodes opened this issue Nov 21, 2022 · 5 comments
Labels
C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CheaterCodes
Copy link

CheaterCodes commented Nov 21, 2022

Also on Rust Playground:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=5602ca55d70c4f28705a4740310228f4

Code

#![feature(extern_types)]

extern {
    pub type ExternType;
}

extern "C" {
    pub static EXTERN: ExternType;
}

pub static EMPTY: () = unsafe { &EXTERN; };

fn main() {}

Meta

rustc --version --verbose:

rustc 1.67.0-nightly (a28f3c88e 2022-11-20)
binary: rustc
commit-hash: a28f3c88e50a77bc2a91889241248c4543854e61
commit-date: 2022-11-20
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4

Error output

thread '<unnamed>' panicked at 'assertion failed: layout.is_sized()', compiler/rustc_const_eval/src/interpret/memory.rs:685:17
Backtrace

   0: rust_begin_unwind
             at /rustc/a28f3c88e50a77bc2a91889241248c4543854e61/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/a28f3c88e50a77bc2a91889241248c4543854e61/library/core/src/panicking.rs:65:14
   2: core::panicking::panic
             at /rustc/a28f3c88e50a77bc2a91889241248c4543854e61/library/core/src/panicking.rs:114:5
   3: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::run
   4: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
   5: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, core::result::Result<rustc_middle::mir::interpret::value::ConstAlloc, rustc_middle::mir::interpret::error::ErrorHandled>>>
   6: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::eval_to_allocation_raw
   7: rustc_const_eval::const_eval::eval_queries::eval_to_allocation_raw_provider
   8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::ParamEnvAnd<rustc_middle::mir::interpret::GlobalId>, core::result::Result<rustc_middle::mir::interpret::value::ConstAlloc, rustc_middle::mir::interpret::error::ErrorHandled>>>
   9: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::eval_to_allocation_raw
  10: <rustc_middle::ty::query::TyCtxtEnsure>::eval_static_initializer
  11: <rustc_lint::BuiltinCombinedModuleLateLintPass as rustc_lint::passes::LateLintPass>::check_item
  12: rustc_hir::intravisit::walk_mod::<rustc_lint::late::LateContextAndPass<rustc_lint::BuiltinCombinedModuleLateLintPass>>
  13: rustc_lint::late::late_lint_mod::<rustc_lint::BuiltinCombinedModuleLateLintPass>
  14: rustc_lint::lint_mod
  15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  16: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::lint_mod, rustc_query_impl::plumbing::QueryCtxt>
  17: rustc_data_structures::sync::par_for_each_in::<&[rustc_hir::hir_id::OwnerId], <rustc_middle::hir::map::Map>::par_for_each_module<rustc_lint::late::check_crate<rustc_lint::BuiltinCombinedLateLintPass, rustc_interface::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}::{closure#0}>::{closure#0}>
  18: <rustc_session::session::Session>::time::<(), rustc_lint::late::check_crate<rustc_lint::BuiltinCombinedLateLintPass, rustc_interface::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}::{closure#0}>::{closure#1}::{closure#0}>
  19: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#5}::{closure#1}::{closure#2}::{closure#0}>
  20: <core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::passes::analysis::{closure#5}::{closure#1}> as core::ops::function::FnOnce<()>>::call_once
  21: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#5}>
  22: rustc_interface::passes::analysis
  23: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  24: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  25: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  26: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  27: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}::{closure#1}>
  28: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>

@CheaterCodes CheaterCodes added 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. labels Nov 21, 2022
@riking
Copy link

riking commented Nov 22, 2022

Note that the static EMPTY takes the reference and then tosses it out.

@CheaterCodes
Copy link
Author

I originally encountered this when casting the reference to a pointer and then storing it in a static (via a wrapper), but since this wasn't needed for the crash, I simplified the example.
Also just to mention it: This obviously doesn't happen when using e.g. u8 instead of ExternType.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 21, 2022
@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 16, 2023
@CheaterCodes
Copy link
Author

This appears to be fixed in current nightly, so I think this can be closed

@matthiaskrgr matthiaskrgr removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 9, 2024
@matthiaskrgr
Copy link
Member

This still crashes with -Zextra-const-ub-checks cc @RalfJung maybe?

@RalfJung
Copy link
Member

Should we really allow extern static of unsized types? I don't think we should, that makes fairly little sense to me.

Note that we reject this:

extern "C" {
    pub static EXTERN: [i32];
}

saying

error[E0277]: the size for values of type `[i32]` cannot be known at compilation time
 --> src/main.rs:2:24
  |
2 |     pub static EXTERN: [i32];
  |                        ^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `[i32]`

we should make the same error show up for extern types. This is just a bug somewhere in the (unstable) extern type feature.

@RalfJung RalfJung added the F-extern_types `#![feature(extern_types)]` label Jan 11, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 20, 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. F-extern_types `#![feature(extern_types)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants