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 on invalid rustc_layout_scalar_valid_range_start attribute #82981

Closed
chengniansun opened this issue Mar 10, 2021 · 4 comments · Fixed by #83054
Closed

ICE on invalid rustc_layout_scalar_valid_range_start attribute #82981

chengniansun opened this issue Mar 10, 2021 · 4 comments · Fixed by #83054
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself A-diagnostics Area: Messages for errors, warnings, and lints glacier ICE tracked in rust-lang/glacier. 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

@chengniansun
Copy link

Code

#![feature(rustc_attrs)]
use std::num::NonZeroU8;
#[rustc_layout_scalar_valid_range_start(C)]
union MaybeUninit<T: Copy> {
    uninit: (),
    init: T,
}
const UNINIT: NonZeroU8 = MaybeUninit { uninit: () }.init;

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (3a5d45f68 2021-03-09)
binary: rustc
commit-hash: 3a5d45f68cadc8fff4fbb557780f92b403b19c19
commit-date: 2021-03-09
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 12.0.0

Error output

thread 'rustc' panicked at 'attribute takes lit', compiler/rustc_middle/src/ty/context.rs:1095:38
note: run with `RUST_BACKTRACE=1` environment variable to display a 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 (3a5d45f68 2021-03-09) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type staticlib

query stack during panic:
#0 [unsafety_check_result] unsafety-checking `UNINIT`
#1 [mir_const] processing MIR for `UNINIT`
end of query stack
Backtrace

thread 'rustc' panicked at 'attribute takes lit', compiler/rustc_middle/src/ty/context.rs:1095:38
stack backtrace:
   0: rust_begin_unwind
             at /rustc/3a5d45f68cadc8fff4fbb557780f92b403b19c19/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/3a5d45f68cadc8fff4fbb557780f92b403b19c19/library/core/src/panicking.rs:92:14
   2: core::option::expect_failed
             at /rustc/3a5d45f68cadc8fff4fbb557780f92b403b19c19/library/core/src/option.rs:1293:5
   3: rustc_middle::ty::context::TyCtxt::layout_scalar_valid_range::{{closure}}
   4: rustc_middle::ty::context::TyCtxt::layout_scalar_valid_range
   5: <rustc_mir::transform::check_unsafety::UnsafetyChecker as rustc_middle::mir::visit::Visitor>::visit_rvalue
   6: rustc_mir::transform::check_unsafety::unsafety_check_result
   7: core::ops::function::FnOnce::call_once
   8: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
   9: rustc_data_structures::stack::ensure_sufficient_stack
  10: rustc_query_system::query::plumbing::force_query_with_job
  11: rustc_query_system::query::plumbing::get_query_impl
  12: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  13: rustc_mir::transform::mir_const
  14: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  15: rustc_data_structures::stack::ensure_sufficient_stack
  16: rustc_query_system::query::plumbing::force_query_with_job
  17: rustc_query_system::query::plumbing::get_query_impl
  18: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const
  19: rustc_mir::transform::mir_const_qualif
  20: core::ops::function::FnOnce::call_once
  21: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  22: rustc_data_structures::stack::ensure_sufficient_stack
  23: rustc_query_system::query::plumbing::force_query_with_job
  24: rustc_query_system::query::plumbing::get_query_impl
  25: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const_qualif
  26: rustc_mir::transform::mir_promoted
  27: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  28: rustc_data_structures::stack::ensure_sufficient_stack
  29: rustc_query_system::query::plumbing::force_query_with_job
  30: rustc_query_system::query::plumbing::get_query_impl
  31: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_promoted
  32: rustc_mir::borrow_check::mir_borrowck
  33: core::ops::function::FnOnce::call_once
  34: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  35: rustc_data_structures::stack::ensure_sufficient_stack
  36: rustc_query_system::query::plumbing::force_query_with_job
  37: rustc_query_system::query::plumbing::get_query_impl
  38: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  39: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  40: rustc_interface::passes::analysis
  41: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  42: rustc_data_structures::stack::ensure_sufficient_stack
  43: rustc_query_system::query::plumbing::force_query_with_job
  44: rustc_query_system::query::plumbing::get_query_impl
  45: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  46: rustc_interface::passes::QueryContext::enter
  47: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  48: rustc_span::with_source_map
  49: rustc_interface::interface::create_compiler_and_run
  50: rustc_span::with_session_globals
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 (3a5d45f68 2021-03-09) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type staticlib

query stack during panic:
#0 [unsafety_check_result] unsafety-checking `UNINIT`
#1 [mir_const] processing MIR for `UNINIT`
#2 [mir_const_qualif] const checking `UNINIT`
#3 [mir_promoted] processing `UNINIT`
#4 [mir_borrowck] borrow-checking `UNINIT`
#5 [analysis] running analysis passes on this crate
end of query stack

@chengniansun chengniansun 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 Mar 10, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 10, 2021

This isn't really a bug, it's just that it has bad diagnostics because it uses rustc_layout_scalar_valid_range_start, which is a perma-unstable attribute. I would recommend against reporting bugs that need rustc_* attributes unless they cause unsoundness.

@jyn514 jyn514 added A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself A-diagnostics Area: Messages for errors, warnings, and lints and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Mar 10, 2021
@jyn514
Copy link
Member

jyn514 commented Mar 10, 2021

MCVE:

#![feature(rustc_attrs)]
#[rustc_layout_scalar_valid_range_start(A)]
struct T {}
const C: T = T {};

@jyn514 jyn514 changed the title ICE: thread 'rustc' panicked at 'attribute takes lit', compiler/rustc_middle/src/ty/context.rs:1095:38 ICE on invalid rustc_layout_scalar_valid_range_start attribute Mar 10, 2021
@jyn514 jyn514 added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ and removed C-bug Category: This is a bug. labels Mar 10, 2021
@chengniansun
Copy link
Author

@jyn514

Should I exclude all test programs that have a line starting with #[rustc_?

Thanks.

@jyn514
Copy link
Member

jyn514 commented Mar 10, 2021

I don't personally feel comfortable setting a policy that we'll never fix ICEs with rustc_ attributes, but they are definitely less likely to be bugs than other ICEs.

a line starting with #[rustc_

Note that this isn't sufficient to catch programs that have an attribute, you can have arbitrary macros that play with conditional compilation, like cfg_if. Catching #[rustc_ and #[cfg_attr(xxx, rustc_ will probably hit the common cases, though (you may want to also include inner attributes).

fanninpm added a commit to fanninpm/glacier that referenced this issue Mar 12, 2021
May not be that important, due to the use of a perma-unstable attribute.

Issue: rust-lang/rust#82981
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 12, 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.
@bors bors closed this as completed in b8622f2 Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contributor-roadblock Area: Makes things more difficult for new contributors to rust itself A-diagnostics Area: Messages for errors, warnings, and lints glacier ICE tracked in rust-lang/glacier. 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