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: compiler/rustc_middle/src/mir/mod.rs:2306:49: could not find allocation for alloc1 #78655

Closed
chengniansun opened this issue Nov 2, 2020 · 6 comments · Fixed by #78742
Closed
Assignees
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chengniansun
Copy link

chengniansun commented Nov 2, 2020

Code

const FOO: *const u32 = {
    let x;
    &x
};
fn main() {
    let FOO = FOO;
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (4f7612ac1 2020-10-31)
binary: rustc
commit-hash: 4f7612ac1499258025077f1fd05d2f429f9accfb
commit-date: 2020-10-31
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly

Error output

error[E0381]: borrow of possibly-uninitialized variable: `x`
 --> reduced_mutant.rs:3:5
  |
3 |     &x
  |     ^^ use of possibly-uninitialized `x`

error: encountered dangling pointer in final constant
 --> reduced_mutant.rs:1:1
  |
1 | / const FOO: *const u32 = {
2 | |     let x;
3 | |     &x
4 | | };
  | |__^

error[E0005]: refutable pattern in local binding: `_` not covered
 --> reduced_mutant.rs:6:9
  |
1 | / const FOO: *const u32 = {
2 | |     let x;
3 | |     &x
4 | | };
  | |__- constant defined here
5 |   fn main() {
6 |       let FOO = FOO;
  |           ^^^
  |           |
  |           interpreted as a constant pattern, not a new variable
  |           help: introduce a variable instead: `foo_var`
  |
  = note: the matched value is of type `*const u32`

error: internal compiler error: compiler/rustc_middle/src/mir/mod.rs:2306:49: could not find allocation for alloc1

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:942:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.49.0-nightly (4f7612ac1 2020-10-31) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [mir_borrowck] borrow-checking `main`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0005, E0381.
For more information about an error, try `rustc --explain E0005`.
Backtrace

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:942:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::bug_fmt
   8: rustc_middle::mir::Constant::check_static_ptr
   9: <rustc_mir::borrow_check::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_constant
  10: rustc_middle::mir::visit::Visitor::super_rvalue
  11: <rustc_mir::borrow_check::type_check::TypeVerifier as rustc_middle::mir::visit::Visitor>::visit_body
  12: rustc_mir::borrow_check::type_check::type_check
  13: rustc_mir::borrow_check::nll::compute_regions
  14: rustc_mir::borrow_check::do_mir_borrowck
  15: rustc_infer::infer::InferCtxtBuilder::enter
  16: rustc_mir::borrow_check::mir_borrowck
  17: core::ops::function::FnOnce::call_once
  18: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  19: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  20: rustc_data_structures::stack::ensure_sufficient_stack
  21: rustc_query_system::query::plumbing::get_query_impl
  22: rustc_query_system::query::plumbing::ensure_query_impl
  23: rustc_interface::passes::analysis
  24: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  25: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  26: rustc_data_structures::stack::ensure_sufficient_stack
  27: rustc_query_system::query::plumbing::get_query_impl
  28: rustc_interface::passes::QueryContext::enter
  29: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  30: rustc_span::with_source_map
  31: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

NOTE: The bug is found by our work-in-progress compiler testing tool Kira, and the test program is reduced/minimized by Perses

@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 Nov 2, 2020
@JohnTitor
Copy link
Member

This is ICE since 1.45.0, I think #71508 is the cause. This @RalfJung's comment seems related: #71508 (comment)

@JohnTitor JohnTitor added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Nov 2, 2020
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 2, 2020
@jonas-schievink jonas-schievink added the A-const-eval Area: constant evaluation (mir interpretation) label Nov 2, 2020
@RalfJung
Copy link
Member

RalfJung commented Nov 2, 2020

The intention was that "error: encountered dangling pointer in final constant" would stop compilation... but as usual when using a constant as a pattern like this code does, compilation doesn't actually stop, so bogus things end up hitting other parts of the compiler. :/ FWIW, this regression can only possible affect code that should not compile (but it should error cleanly, not ICE).

Cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Nov 2, 2020

This specific case could become delay_span_bug by invoking get_global_alloc instead of global_alloc. But that's just fixing symptoms as noted by @RalfJung

I think the correct fix would be to make sure that intern_const_alloc_recursive bubbles up an ErrorReported to make sure we don't get that constant but either just get an error or potentially a ConstKind::Error

@oli-obk oli-obk added E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Nov 2, 2020
@RalfJung
Copy link
Member

RalfJung commented Nov 2, 2020

Found the issue for the underlying problem (or at least, something closely related): #76064

@JohnTitor
Copy link
Member

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@JohnTitor JohnTitor added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Nov 2, 2020
@vn-ki
Copy link
Contributor

vn-ki commented Nov 3, 2020

@rustbot claim

m-ou-se added a commit to m-ou-se/rust that referenced this issue Nov 5, 2020
make intern_const_alloc_recursive return error

fix rust-lang#78655

r? `@oli-obk`
m-ou-se added a commit to m-ou-se/rust that referenced this issue Nov 5, 2020
make intern_const_alloc_recursive return error

fix rust-lang#78655

r? ``@oli-obk``
@bors bors closed this as completed in bd7229d Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) C-bug Category: This is a bug. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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.

7 participants