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 when referencing () from an array #43205

Closed
goffrie opened this issue Jul 13, 2017 · 2 comments
Closed

ICE when referencing () from an array #43205

goffrie opened this issue Jul 13, 2017 · 2 comments
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

@goffrie
Copy link
Contributor

goffrie commented Jul 13, 2017

This code:

fn main() {
    println!("{:?}", &[()][0]);
}

gives this ICE:

error: internal compiler error: /checkout/src/librustc_trans/mir/lvalue.rs:301: using operand local _10 as lvalue

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.20.0-nightly (f85579d4a 2017-07-12) running on x86_64-unknown-linux-gnu

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:489:8

playground

Doesn't happen if you use e.g. 1 instead of (), or use (&[()]) instead of [()].

@Mark-Simulacrum Mark-Simulacrum added 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 19, 2017
@Mark-Simulacrum
Copy link
Member

Minimized to:

fn main() {
    &&[()][1];
}
error: internal compiler error: src/librustc_trans/mir/lvalue.rs:301: using operand local _2 as lvalue

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.20.0-dev (cdd8dc67b 2017-07-18) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:489:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:71
             at src/libstd/sys_common/backtrace.rs:60
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:380
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:390
   4: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:611
   5: std::panicking::begin_panic_new
             at /home/mark/BuildDisk/rust/src/libstd/panicking.rs:553
   6: rustc_errors::Handler::bug
             at src/librustc_errors/lib.rs:489
   7: <std::thread::local::LocalKey<T>>::try_with
             at src/librustc/session/mod.rs:859
             at src/librustc/ty/context.rs:985
             at src/librustc/ty/context.rs:974
             at /home/mark/BuildDisk/rust/src/libstd/thread/local.rs:429
   8: <std::thread::local::LocalKey<T>>::with
             at /home/mark/BuildDisk/rust/src/libstd/thread/local.rs:343
   9: rustc::ty::context::tls::with
             at src/librustc/ty/context.rs:970
  10: rustc::ty::context::tls::with_opt
             at src/librustc/ty/context.rs:985
  11: rustc::session::opt_span_bug_fmt
             at src/librustc/session/mod.rs:855
  12: rustc::session::bug_fmt
             at src/librustc/session/mod.rs:839
  13: rustc_trans::mir::lvalue::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_lvalue
             at src/librustc_trans/mir/lvalue.rs:301
  14: rustc_trans::mir::rvalue::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_rvalue_operand
             at src/librustc_trans/mir/rvalue.rs:354
  15: rustc_trans::mir::statement::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_statement
             at src/librustc_trans/mir/statement.rs:38
  16: rustc_trans::mir::block::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_block
             at src/librustc_trans/mir/block.rs:49
  17: rustc_trans::mir::trans_mir
             at src/librustc_trans/mir/mod.rs:324
  18: rustc_trans::base::trans_instance
             at src/librustc_trans/base.rs:607
  19: rustc_trans::trans_item::TransItem::define
             at src/librustc_trans/trans_item.rs:90
  20: rustc_trans::base::trans_crate::module_translation
             at src/librustc_trans/base.rs:1190
  21: rustc::dep_graph::graph::DepGraph::with_task
             at /home/mark/BuildDisk/rust/src/librustc/dep_graph/graph.rs:125
  22: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once
             at src/librustc_trans/base.rs:1124
             at /home/mark/BuildDisk/rust/src/libcore/ops/function.rs:191
  23: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::spec_extend
             at /home/mark/BuildDisk/rust/src/libcore/option.rs:398
             at /home/mark/BuildDisk/rust/src/libcore/iter/mod.rs:1073
             at /home/mark/BuildDisk/rust/src/liballoc/vec.rs:1825
  24: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
             at /home/mark/BuildDisk/rust/src/liballoc/vec.rs:1808
  25: rustc_trans::base::trans_crate
             at /home/mark/BuildDisk/rust/src/liballoc/vec.rs:1695
             at /home/mark/BuildDisk/rust/src/libcore/iter/iterator.rs:1303
             at src/librustc_trans/base.rs:1119
  26: rustc::util::common::time
             at src/librustc_driver/driver.rs:1069
             at /home/mark/BuildDisk/rust/src/librustc/util/common.rs:48
  27: rustc_driver::driver::phase_4_translate_to_llvm
             at src/librustc_driver/driver.rs:1067
  28: rustc_driver::driver::compile_input::{{closure}}
             at src/librustc_driver/driver.rs:211
  29: <std::thread::local::LocalKey<T>>::try_with
             at src/librustc_driver/driver.rs:1049
             at /home/mark/BuildDisk/rust/src/librustc/ty/context.rs:958
             at /home/mark/BuildDisk/rust/src/libstd/thread/local.rs:429
  30: <std::thread::local::LocalKey<T>>::with
             at /home/mark/BuildDisk/rust/src/libstd/thread/local.rs:343
  31: rustc::ty::context::tls::enter
             at /home/mark/BuildDisk/rust/src/librustc/ty/context.rs:955
  32: <std::thread::local::LocalKey<T>>::try_with
             at /home/mark/BuildDisk/rust/src/librustc/ty/context.rs:942
             at /home/mark/BuildDisk/rust/src/libstd/thread/local.rs:429
  33: <std::thread::local::LocalKey<T>>::with
             at /home/mark/BuildDisk/rust/src/libstd/thread/local.rs:343
  34: rustc::ty::context::tls::enter_global
             at /home/mark/BuildDisk/rust/src/librustc/ty/context.rs:939
  35: rustc::ty::context::TyCtxt::create_and_enter
             at /home/mark/BuildDisk/rust/src/librustc/ty/context.rs:720
  36: rustc_driver::driver::phase_3_run_analysis_passes
             at src/librustc_driver/driver.rs:962
  37: rustc_driver::driver::compile_input
             at src/librustc_driver/driver.rs:177
  38: rustc_driver::run_compiler
             at src/librustc_driver/lib.rs:218

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
taleks added a commit to taleks/rust that referenced this issue Aug 23, 2017
- fixes evaluation of array length for zero-sized type referenced by
  rvalue operand.
- adds test to verify fix.

Cause of the issue.

Zero-sized aggregates are handled as operands, not lvalues. Therefore while
visiting Assign statement by LocalAnalyser, mark_as_lvalue() is not called for
related Local. This behaviour is controlled by rvalue_creates_operand() method.
As result it causes error later, when rvalue operand is evaluated in
trans_rvalue_operand() while handling Rvalue::Len case. Array length evaluation
invokes trans_lvalue() which expects referenced Local to be value, not operand.

How it is fixed.

In certain cases result of Rvalue::Len can be evaluated without calling
trans_lvalue(). Method evaluate_array_len() is introduced to handle length
evaluation for zero-sized types referenced by Locals.
bors added a commit that referenced this issue Aug 27, 2017
Fixes issue #43205: ICE in Rvalue::Len evaluation.

- fixes evaluation of array length for zero-sized type referenced by rvalue operand.
- adds test to verify fix.

*Cause of the issue*.

Zero-sized aggregates are handled as operands, not lvalues. Therefore while visiting `Assign` statement by `LocalAnalyser`, `mark_as_lvalue()` is not called for related `Local`. This behaviour is controlled by `rvalue_creates_operand()` method.

As result it causes error later, when rvalue operand is evaluated in `trans_rvalue_operand()` while handling `Rvalue::Len` case. Array length evaluation invokes `trans_lvalue()` which expects referenced `Local` to be value, not operand.

*How it is fixed*.

In certain cases result of `Rvalue::Len` can be evaluated without calling
`trans_lvalue()`. Method `evaluate_array_len()` is introduced to handle length
evaluation for zero-sized types referenced by Locals.

*Some concerns*.

- `trans_lvalue()` has two other entry points in `rvalue.rs`: it is invoked while handling `Rvalue::Ref` and `Rvalue::Discriminant`. There is a chance those may produce the same issue, but I've failed to write a specific test that leads to this.
- `evaluate_array_len()` performs the same check (matches lvalue and `Local`), which is performed again in `trans_lvalue()`. Without changing `trans_lvalue()` signature to make it aware that caller deals with rvalue, it seems there is no cheap solution to avoid this check.
@goffrie
Copy link
Contributor Author

goffrie commented Aug 29, 2017

Fixed in #44060.

@goffrie goffrie closed this as completed Aug 29, 2017
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

No branches or pull requests

2 participants