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: translating unsupported cast: fn() -> u64 (cast_pointer) -> f32 (cast_float) #15355

Closed
gmorenz opened this issue Jul 2, 2014 · 4 comments
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@gmorenz
Copy link

gmorenz commented Jul 2, 2014

Code:

fn f() -> u64 {
    0
}

fn main() {
    let n = f as f32;
}

Error with backtrace:

src/main.rs:6:9: 6:10 warning: unused variable: `n`, #[warn(unused_variable)] on by default
src/main.rs:6     let n = f as f32;
                      ^
error: internal compiler error: translating unsupported cast: fn() -> u64 (cast_pointer) -> f32 (cast_float)
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/diagnostic.rs:163

stack backtrace:
   1:     0x7f6e5389ced0 - rt::backtrace::imp::write::h3e02102493c7a1b79Hp::v0.11.0.pre
   2:     0x7f6e538a3a00 - failure::on_fail::h73803e3fd7728138o3p::v0.11.0.pre
   3:     0x7f6e55a06ef0 - unwind::begin_unwind_inner::h66e3981eb8555b96cZd::v0.11.0.pre
   4:     0x7f6e54e4a4e0 - unwind::begin_unwind::h14114372353668361027::v0.11.0.pre
   5:     0x7f6e54e4ae80 - diagnostic::Handler::bug::h163e51ddd1a017c2Dgc::v0.11.0.pre
   6:     0x7f6e562f9520 - driver::session::Session::bug::h09f59f7b6f35750fdsr::v0.11.0.pre
   7:     0x7f6e5637cbf0 - middle::trans::expr::trans_imm_cast::h261d15fd2f6453feLQh::v0.11.0.pre
   8:     0x7f6e5636e380 - middle::trans::expr::trans_unadjusted::h37391b28c8fd0d0b60f::v0.11.0.pre
   9:     0x7f6e5632a310 - middle::trans::expr::trans_into::hdc05c03d27b262d4JDf::v0.11.0.pre
  10:     0x7f6e56434000 - middle::trans::_match::store_local::closure.85655
  11:     0x7f6e56433cf0 - middle::trans::_match::mk_binding_alloca::h16257314354832004452::v0.11.0.pre
  12:     0x7f6e563eaa70 - middle::trans::_match::store_local::h71f3ff230e537ab6JEu::v0.11.0.pre
  13:     0x7f6e563297e0 - middle::trans::base::init_local::he8478d5bef2cef9cOZp::v0.11.0.pre
  14:     0x7f6e56328d40 - middle::trans::controlflow::trans_stmt::h77aa44239cd8a9d8Mdc::v0.11.0.pre
  15:     0x7f6e5632a940 - middle::trans::controlflow::trans_block::hf4faa65f79a4fae52ic::v0.11.0.pre
  16:     0x7f6e563f0850 - middle::trans::base::trans_closure::hbab3416264edbe7aauq::v0.11.0.pre
  17:     0x7f6e562fa790 - middle::trans::base::trans_fn::hd7d1d11484c269ccbCq::v0.11.0.pre
  18:     0x7f6e562f3230 - middle::trans::base::trans_item::h40a4f8eccf6f8e7eCSq::v0.11.0.pre
  19:     0x7f6e564011b0 - middle::trans::base::trans_crate::h470bfcf3cac093e1JMr::v0.11.0.pre
  20:     0x7f6e56c06570 - driver::driver::phase_4_translate_to_llvm::h2fa30f4b120cdb579Aq::v0.11.0.pre
  21:     0x7f6e56bfd2b0 - driver::driver::compile_input::h1d313b682f9ead2bDeq::v0.11.0.pre
  22:     0x7f6e56cca0c0 - driver::run_compiler::hcc8540f7b478ad28b0s::v0.11.0.pre
  23:     0x7f6e56cc9fd0 - driver::main_args::closure.117522
  24:     0x7f6e56cdf0f0 - task::TaskBuilder<S>::try_future::closure.118663
  25:     0x7f6e56cded10 - task::TaskBuilder<S>::spawn_internal::closure.118640
  26:     0x7f6e55d5c590 - task::spawn_opts::closure.7462
  27:     0x7f6e55a5f290 - rust_try
  28:     0x7f6e55a03500 - unwind::try::h800fde6f36f3558bBNd::v0.11.0.pre
  29:     0x7f6e55a031e0 - task::Task::run::hf743f122a6385418XYc::v0.11.0.pre
  30:     0x7f6e55d5c350 - task::spawn_opts::closure.7408
  31:     0x7f6e55a05da0 - thread::thread_start::hd9510588dd47efddvld::v0.11.0.pre
  32:     0x7f6e53311060 - start_thread
  33:     0x7f6e556cd489 - __clone
  34:                0x0 - <unknown>
@huonw huonw added the I-ICE label Jul 2, 2014
@steveklabnik
Copy link
Member

Triage: same ICE

@ghost
Copy link

ghost commented Mar 4, 2015

This is now rejected:

test.rs:4:13: 4:21 error: illegal cast; cast through an integer first: `fn() -> u64 {f}` as `f64`
test.rs:4     let n = f as f64;

However:

fn f() -> u64 { 0 }

fn main() {
    let n = f as u64 as f64;
}

now segfaults at compile-time:

(lldb) run ./test.rs
Process 52461 launched: '/usr/local/bin/rustc' (x86_64)
test.rs:4:9: 4:10 warning: unused variable: `n`, #[warn(unused_variables)] on by default
test.rs:4     let n = f as u64 as f64;
                  ^
Process 52461 stopped
* thread #2: tid = 0x126ff8, 0x00000001024efc59 librustc_llvm-4e7c5e5c.dylib`llvm::TypeFinder::run(llvm::Module const&, bool) + 73, name = 'rustc', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
    frame #0: 0x00000001024efc59 librustc_llvm-4e7c5e5c.dylib`llvm::TypeFinder::run(llvm::Module const&, bool) + 73
librustc_llvm-4e7c5e5c.dylib`llvm::TypeFinder::run(llvm::Module const&, bool) + 73:
-> 0x1024efc59:  movq   0x8(%rbx), %rsi
   0x1024efc5d:  testq  %rsi, %rsi
   0x1024efc60:  je     0x1024f0070               ; llvm::TypeFinder::run(llvm::Module const&, bool) + 1120
   0x1024efc66:  movzbl 0x8(%rsi), %eax
(lldb) bt
* thread #2: tid = 0x126ff8, 0x00000001024efc59 librustc_llvm-4e7c5e5c.dylib`llvm::TypeFinder::run(llvm::Module const&, bool) + 73, name = 'rustc', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
  * frame #0: 0x00000001024efc59 librustc_llvm-4e7c5e5c.dylib`llvm::TypeFinder::run(llvm::Module const&, bool) + 73
    frame #1: 0x00000001023b4192 librustc_llvm-4e7c5e5c.dylib`llvm::TypePrinting::incorporateTypes(llvm::Module const&) + 34
    frame #2: 0x00000001023c430c librustc_llvm-4e7c5e5c.dylib`llvm::Value::printAsOperand(llvm::raw_ostream&, bool, llvm::Module const*) const + 364
    frame #3: 0x0000000101d42bfa librustc_llvm-4e7c5e5c.dylib`llvm::AsmPrinter::lowerConstant(llvm::Constant const*) + 1610
    frame #4: 0x0000000101d45842 librustc_llvm-4e7c5e5c.dylib`emitGlobalConstantImpl(llvm::Constant const*, llvm::AsmPrinter&) + 2498
    frame #5: 0x0000000101d3dfcb librustc_llvm-4e7c5e5c.dylib`llvm::AsmPrinter::EmitGlobalVariable(llvm::GlobalVariable const*) + 1899
    frame #6: 0x0000000101d418f0 librustc_llvm-4e7c5e5c.dylib`llvm::AsmPrinter::doFinalization(llvm::Module&) + 80
    frame #7: 0x00000001024cd523 librustc_llvm-4e7c5e5c.dylib`llvm::FPPassManager::doFinalization(llvm::Module&) + 83
    frame #8: 0x00000001024cdafd librustc_llvm-4e7c5e5c.dylib`llvm::legacy::PassManagerImpl::run(llvm::Module&) + 1421
    frame #9: 0x00000001013b68c7 librustc_llvm-4e7c5e5c.dylib`LLVMRustWriteOutputFile(Target=<unavailable>, PMR=0x0000000103f05e70, M=0x0000000103f05e70, path=<unavailable>, FileType=CGFT_ObjectFile) + 503 at PassWrapper.cpp:211
    frame #10: 0x00000001005a34ff librustc_trans-4e7c5e5c.dylib`back::write::write_output_file::hdb56d5084c63bc86v6b + 223
    frame #11: 0x00000001005a601f librustc_trans-4e7c5e5c.dylib`back::write::optimize_and_codegen::closure.38410 + 1327
    frame #12: 0x00000001005b0cb9 librustc_trans-4e7c5e5c.dylib`back::write::execute_work_item::hd8db7afca5e1ebc8nZc + 6345
    frame #13: 0x00000001005a7af4 librustc_trans-4e7c5e5c.dylib`back::write::run_passes::hd2f044ab61edb7b9cFc + 6468
    frame #14: 0x0000000100029e1a librustc_driver-4e7c5e5c.dylib`driver::phase_5_run_llvm_passes::hb3416b462f92d001dOa + 362
    frame #15: 0x00000001000055db librustc_driver-4e7c5e5c.dylib`driver::compile_input::heef3a8983ecc9746Iba + 5339
    frame #16: 0x00000001000d644f librustc_driver-4e7c5e5c.dylib`run_compiler::h09dbb9820b7ec68bF5b + 4159
    frame #17: 0x00000001000d3808 librustc_driver-4e7c5e5c.dylib`thunk::F.Invoke$LT$A$C$$u20$R$GT$::invoke::h10490261994158956019 + 600
    frame #18: 0x00000001000d2350 librustc_driver-4e7c5e5c.dylib`rt::unwind::try::try_fn::h10082179094849837244 + 192
    frame #19: 0x0000000103a67089 libstd-4e7c5e5c.dylib`rust_try_inner + 9
    frame #20: 0x0000000103a67076 libstd-4e7c5e5c.dylib`rust_try + 6
    frame #21: 0x00000001000d2b89 librustc_driver-4e7c5e5c.dylib`thunk::F.Invoke$LT$A$C$$u20$R$GT$::invoke::h16026492124957986721 + 1433
    frame #22: 0x00000001039d06f3 libstd-4e7c5e5c.dylib`sys::thread::thread_start::hb52a23d4ffceb69312E + 179
    frame #23: 0x00007fff865272fc libsystem_pthread.dylib`_pthread_body + 131
    frame #24: 0x00007fff86527279 libsystem_pthread.dylib`_pthread_start + 176

@ghost
Copy link

ghost commented Mar 4, 2015

FWIW, the error message is also misleading: it should suggest casting through usize.

@ghost ghost added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Mar 4, 2015
@steveklabnik
Copy link
Member

This is now fixed. It suggests casting through usize, then actually compiles and runs just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

3 participants