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] With wrong rustc_layout_scalar_valid_range_start #82251

Closed
leonardo-m opened this issue Feb 18, 2021 · 2 comments · Fixed by #83054
Closed

[ICE] With wrong rustc_layout_scalar_valid_range_start #82251

leonardo-m opened this issue Feb 18, 2021 · 2 comments · Fixed by #83054
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

@leonardo-m
Copy link

#![feature(rustc_attrs)]
#[rustc_layout_scalar_valid_range_start(u32::MAX)]
struct Foo(u32);
fn main() {
    const N: usize = std::mem::size_of::<Foo>();
}

Gives:

thread 'rustc' panicked at 'attribute takes lit', compiler\rustc_middle\src\ty\context.rs:1082:38
stack backtrace:
   0: rust_begin_unwind
             at /rustc/152f6609246558be5e2582e67376194815e6ba0d\/library\std\src\panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/152f6609246558be5e2582e67376194815e6ba0d\/library\core\src\panicking.rs:92:14
   2: core::option::expect_failed
             at /rustc/152f6609246558be5e2582e67376194815e6ba0d\/library\core\src\option.rs:1292:5
   3: rustc_middle::ty::context::TyCtxt::layout_scalar_valid_range::{{closure}}
   4: rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt>::layout_raw_uncached
   5: rustc_middle::ty::layout::layout_raw
   6: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::layout_raw>::compute
   7: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
   8: rustc_data_structures::stack::ensure_sufficient_stack
   9: rustc_query_system::query::plumbing::force_query_with_job
  10: rustc_query_system::query::plumbing::get_query_impl
  11: <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::query::TyCtxtAt> as rustc_target::abi::LayoutOf>::layout_of
  12: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_rvalue_into_place
  13: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run
  14: rustc_mir::const_eval::eval_queries::eval_to_allocation_raw_provider
  15: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_allocation_raw>::compute
  16: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  17: rustc_data_structures::stack::ensure_sufficient_stack
  18: rustc_query_system::query::plumbing::force_query_with_job
  19: rustc_query_system::query::plumbing::get_query_impl
  20: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  21: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_const_value_raw>::compute
  22: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  23: rustc_data_structures::stack::ensure_sufficient_stack
  24: rustc_query_system::query::plumbing::force_query_with_job
  25: rustc_query_system::query::plumbing::get_query_impl
  26: rustc_mir::const_eval::eval_queries::eval_to_const_value_raw_provider
  27: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::eval_to_const_value_raw>::compute
  28: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  29: rustc_data_structures::stack::ensure_sufficient_stack
  30: rustc_query_system::query::plumbing::force_query_with_job
  31: rustc_query_system::query::plumbing::get_query_impl
  32: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  33: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_poly
  34: <rustc_lint::BuiltinCombinedLateLintPass as rustc_lint::passes::LateLintPass>::check_item
  35: rustc_hir::intravisit::Visitor::visit_nested_item
  36: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_stmt
  37: rustc_hir::intravisit::walk_expr
  38: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_expr
  39: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_nested_body
  40: <rustc_lint::late::LateContextAndPass<T> as rustc_hir::intravisit::Visitor>::visit_fn
  41: rustc_hir::intravisit::walk_item
  42: rustc_hir::intravisit::Visitor::visit_nested_item
  43: rustc_hir::intravisit::walk_crate
  44: rustc_session::utils::<impl rustc_session::session::Session>::time
  45: std::panicking::try
  46: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  47: rustc_session::utils::<impl rustc_session::session::Session>::time
  48: rustc_interface::passes::analysis
  49: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  50: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  51: rustc_data_structures::stack::ensure_sufficient_stack
  52: rustc_query_system::query::plumbing::force_query_with_job
  53: rustc_query_system::query::plumbing::get_query_impl
  54: rustc_interface::passes::QueryContext::enter
  55: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  56: rustc_span::with_source_map
  57: scoped_tls::ScopedKey<T>::set
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.52.0-nightly (152f66092 2021-02-17) running on x86_64-pc-windows-gnu

query stack during panic:
#0 [layout_raw] computing layout of `Foo`
#1 [eval_to_allocation_raw] const-evaluating + checking `main::N`
#2 [eval_to_const_value_raw] simplifying constant for the type system `main::N`
#3 [eval_to_const_value_raw] simplifying constant for the type system `main::N`
#4 [analysis] running analysis passes on this crate
end of query stack
@leonardo-m leonardo-m 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 Feb 18, 2021
@leonardo-m leonardo-m changed the title [ICE [ICE] With wrong rustc_layout_scalar_valid_range_start Feb 18, 2021
@eddyb
Copy link
Member

eddyb commented Feb 18, 2021

cc @oli-obk ICE-ing instead of user error on misuse seems somewhat okay given that it's an internal attribute, IMO.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 18, 2021

agreed. We don't protect against mis-use of rustc internal attributes beyond making sure that you can't trivially create buggy code. I don't think we should put any effort into making this nicer to use and instead create the const-generic based replacement.

@oli-obk oli-obk closed this as completed Feb 18, 2021
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 14, 2021
…ange, r=davidtwco

Validate rustc_layout_scalar_valid_range_{start,end} attributes

Fixes rust-lang#82251, rust-lang#82981.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 15, 2021
…ange, r=davidtwco

Validate rustc_layout_scalar_valid_range_{start,end} attributes

Fixes rust-lang#82251, fixes rust-lang#82981.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 15, 2021
…ange, r=davidtwco

Validate rustc_layout_scalar_valid_range_{start,end} attributes

Fixes rust-lang#82251, fixes rust-lang#82981.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 15, 2021
…ange, r=davidtwco

Validate rustc_layout_scalar_valid_range_{start,end} attributes

Fixes rust-lang#82251, fixes rust-lang#82981.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Mar 15, 2021
…ange, r=davidtwco

Validate rustc_layout_scalar_valid_range_{start,end} attributes

Fixes rust-lang#82251, fixes rust-lang#82981.
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.

3 participants