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 after cast to *const _ #99122

Closed
jannic opened this issue Jul 10, 2022 · 5 comments
Closed

ICE after cast to *const _ #99122

jannic opened this issue Jul 10, 2022 · 5 comments
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jannic
Copy link
Contributor

jannic commented Jul 10, 2022

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.aaakk.us.kg-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

@jannic jannic 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 Jul 10, 2022
@jannic
Copy link
Contributor Author

jannic commented Jul 10, 2022

@rustbot modify labels: +regression-from-stable-to-beta

@rustbot rustbot added regression-from-stable-to-beta Performance or correctness regression from stable to beta. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 10, 2022
@compiler-errors
Copy link
Member

searched nightlies: from nightly-2022-03-01 to nightly-2022-07-02
regressed nightly: nightly-2022-05-28
searched commit range: 490324f...ebbcbfc
regressed commit: 56fd680

bisected with cargo-bisect-rustc v0.6.3

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start 2022-03-01 --regress ice 

@compiler-errors
Copy link
Member

Anyways I put up a fix in #99124.

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jul 11, 2022
Fix sized check ICE in asm check

Fixes (beta nominated, so doesn't close) rust-lang#99122
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 11, 2022
Fix sized check ICE in asm check

Fixes (beta nominated, so doesn't close) rust-lang#99122
@compiler-errors compiler-errors self-assigned this Jul 11, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 11, 2022
Fix sized check ICE in asm check

Fixes (beta nominated, so doesn't close) rust-lang#99122

1. Moves a check for unresolved inference variables to _before_ other checks that could possibly ICE. We're not changing behavior here, just doing the same thing earlier in the function.
2. Erases region variables in sized check (which are not resolved at this point) because rustc will also ICE when region vars are passed to a query which does not canonicalize them.
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 13, 2022
@compiler-errors
Copy link
Member

This was merged into beta so I will close it now. Expect it to be fixed next beta release :)

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) ❄️ P-medium Medium priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. 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

4 participants