Skip to content

Referencing result of const-fn with expression argument causes ICE with optimization. #38985

Closed
@kennytm

Description

@kennytm

Test case:

#![feature(const_fn)]

pub const fn x(y: u64) -> u64 {
    y
}

fn main() {
    &(x(1 + 1));
}

When compile with RUST_BACKTRACE=1 rustc -O foo.rs, causes this error:

error: internal compiler error: /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustc_trans/mir/constant.rs:374: _2 not initialized
 --> foo.rs:8:6
  |
8 |     &(x(1 + 1));
  |      ^^^^^^^^^^

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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/librustc_errors/lib.rs:382
stack backtrace:
   1:        0x10d60000c - std::sys::imp::backtrace::tracing::imp::write::h36dcd6719b30e145
   2:        0x10d60c76e - std::panicking::default_hook::{{closure}}::hce0d7336eef94718
   3:        0x10d60c313 - std::panicking::default_hook::hd7b4c7a7e16abb43
   4:        0x10d60cc27 - std::panicking::rust_panic_with_hook::h33761bada49f3713
   5:        0x10bc8bdeb - std::panicking::begin_panic::h5e5716dfd2a87c31
   6:        0x10bca8e63 - rustc::session::opt_span_bug_fmt::{{closure}}::h958c683d6fdc31a8
   7:        0x10bca8c89 - rustc::session::span_bug_fmt::h3d230e35039b33b9
   8:        0x10bd5cfc6 - rustc_trans::mir::constant::MirConstContext::const_lvalue::h823568f2ee453853
   9:        0x10bd5d362 - rustc_trans::mir::constant::MirConstContext::const_operand::h73ccf10b598e5ece
  10:        0x10bd5b768 - rustc_trans::mir::constant::MirConstContext::trans::hfa4114b189d14855
  11:        0x10bd61dc5 - rustc_trans::mir::constant::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_constant::h8e44b1e781d76a41
  12:        0x10bd657fc - rustc_trans::mir::operand::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_operand::hfec2b1d846c0f6f9
  13:        0x10bd6885a - rustc_trans::mir::rvalue::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_rvalue_operand::h80f403cf4a280127
  14:        0x10bd53328 - rustc_trans::mir::block::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_block::h35b047b88b63dbd6
  15:        0x10bd50d81 - rustc_trans::mir::trans_mir::h3388a992a25319d1
  16:        0x10bd73667 - rustc_trans::trans_item::TransItem::define::hd3afc898263ab359
  17:        0x10bcf1c23 - rustc_trans::base::trans_crate::h8e2134128cf43214
  18:        0x10adfcceb - rustc_driver::driver::phase_4_translate_to_llvm::hdb9e4a6b9452d28e
  19:        0x10adcb935 - rustc_driver::driver::compile_input::{{closure}}::ha69264f895357be2
  20:        0x10adf079f - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h2eaba017e87ae33c
  21:        0x10adda210 - rustc_driver::driver::phase_3_run_analysis_passes::h1c4ba3b3a21c77e7
  22:        0x10adc9aaa - rustc_driver::driver::compile_input::h32ceef72bc3e1387
  23:        0x10ae1187b - rustc_driver::run_compiler::h98c0b71fc02a61c6
  24:        0x10ad219b8 - std::panicking::try::do_call::h974ffa41f7e629f8
  25:        0x10d60f83a - __rust_maybe_catch_panic
  26:        0x10ad4b3c3 - <F as alloc::boxed::FnBox<A>>::call_box::he8ec96cbec76aa19
  27:        0x10d60b894 - std::sys::imp::thread::Thread::new::thread_start::he1b44499d44cc4a4
  28:     0x7fffbe345aaa - _pthread_body
  29:     0x7fffbe3459f6 - _pthread_start
$ rustc -vV
rustc 1.16.0-nightly (47c8d9fdc 2017-01-08)
binary: rustc
commit-hash: 47c8d9fdcf2e6502cf4ca7d7f059fdc1a2810afa
commit-date: 2017-01-08
host: x86_64-apple-darwin
release: 1.16.0-nightly
LLVM version: 3.9

Metadata

Metadata

Assignees

Labels

regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions