Skip to content

ICE after cast to *const _ #99122

Closed
Closed
@jannic

Description

@jannic

Code

pub unsafe fn test() {
    let pointer = 1u32 as *const _;
    core::arch::asm!(
        "nop",
        in("eax") pointer,
    );
}

https://godbolt.org/z/dYEEEMddq

Meta

rustc --version --verbose:

rustc 1.63.0-beta.4 (94811fdc2 2022-07-06)
binary: rustc
commit-hash: 94811fdc269d23dd9f1dff88f165bc2d6f5f85d4
commit-date: 2022-07-06
host: x86_64-unknown-linux-gnu
release: 1.63.0-beta.4
LLVM version: 14.0.5

Also happens with nightly, but not with stable (1.62.0)

Error output

$ RUST_BACKTRACE=1 cargo check
    Checking ice v0.1.0 (/home/jan/debug/ice)
error[E0641]: cannot cast to a pointer of an unknown kind
 --> src/lib.rs:2:27
  |
2 |     let pointer = 1u32 as *const _;
  |                           ^^^^^^^^ needs more type information
  |
  = note: the type information given here is insufficient to check whether the pointer cast is valid


Backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 3', /cargo/registry/src/github.com-1ecc6299db9ec823/ena-0.14.0/src/snapshot_vec.rs:199:10
stack backtrace:
   0: rust_begin_unwind
             at /rustc/94811fdc269d23dd9f1dff88f165bc2d6f5f85d4/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/94811fdc269d23dd9f1dff88f165bc2d6f5f85d4/library/core/src/panicking.rs:142:14
   2: core::panicking::panic_bounds_check
             at /rustc/94811fdc269d23dd9f1dff88f165bc2d6f5f85d4/library/core/src/panicking.rs:84:5
   3: <rustc_infer::infer::canonical::canonicalizer::Canonicalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
   4: <rustc_infer::infer::canonical::canonicalizer::Canonicalizer as rustc_middle::ty::fold::FallibleTypeFolder>::try_fold_predicate
   5: rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions
   6: <rustc_infer::infer::InferCtxtBuilder>::enter::<bool, rustc_ty_utils::common_traits::is_item_raw::{closure#0}>
   7: rustc_ty_utils::common_traits::is_item_raw
   8: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Ty>, bool>
   9: 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::ty::Ty>, bool>>
  10: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::is_sized_raw, rustc_query_impl::plumbing::QueryCtxt>
  11: <rustc_middle::ty::Ty>::is_sized
  12: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_asm_operand_type
  13: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_asm
  14: <rustc_infer::infer::InferCtxtBuilder>::enter::<&rustc_middle::ty::context::TypeckResults, <rustc_typeck::check::inherited::InheritedBuilder>::enter<rustc_typeck::check::typeck_with_fallback<rustc_typeck::check::typeck::{closure#0}>::{closure#1}, &rustc_middle::ty::context::TypeckResults>::{closure#0}>
  15: rustc_typeck::check::typeck
  16: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>
  17: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
  18: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  19: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_typeck::check::typeck_item_bodies::{closure#0}>
  20: rustc_typeck::check::typeck_item_bodies
  21: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), ()>
  22: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), ()>>
  23: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
  24: <rustc_session::session::Session>::time::<(), rustc_typeck::check_crate::{closure#7}>
  25: rustc_typeck::check_crate
  26: rustc_interface::passes::analysis
  27: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  28: 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>>>
  29: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  30: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  31: <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>>
  32: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  33: <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>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: 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: rustc 1.63.0-beta.4 (94811fdc2 2022-07-06) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [is_sized_raw] computing whether `_` is `Sized`
#1 [typeck] type-checking `test`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
For more information about this error, try `rustc --explain E0641`.
error: could not compile `ice` due to previous error

Metadata

Metadata

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions