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

rustc panic with divide by zero #50761

Closed
bpa opened this issue May 15, 2018 · 1 comment · Fixed by #50819
Closed

rustc panic with divide by zero #50761

bpa opened this issue May 15, 2018 · 1 comment · Fixed by #50819
Assignees
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High 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

@bpa
Copy link

bpa commented May 15, 2018

thread 'rustc' panicked at 'attempt to divide by zero', librustc_trans/abi.rs:430:26

Stripped down version of code to reproduce

mod a {
    pub trait A {}
}

mod b {
    pub struct Builder {}

    pub fn new() -> Builder {
        Builder {}
    }

    impl Builder {
        pub fn with_a(&mut self, _a: fn() -> ::a::A) {}
    }
}

pub use self::b::new;

Meta rustc --version --verbose:

rustc 1.26.0 (a77568041 2018-05-07)
binary: rustc
commit-hash: a7756804103447ea4e68a71ccf071e7ad8f7a03e
commit-date: 2018-05-07
host: x86_64-unknown-linux-gnu
release: 1.26.0
LLVM version: 6.0

stack backtrace:

   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:207
   3: std::panicking::default_hook
             at libstd/panicking.rs:223
   4: core::ops::function::Fn::call
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:403
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:349
   7: rust_begin_unwind
             at libstd/panicking.rs:325
   8: core::panicking::panic_fmt
             at libcore/panicking.rs:72
   9: core::panicking::panic
             at libcore/panicking.rs:51
  10: rustc_trans::abi::CastTarget::llvm_type
  11: rustc_trans::abi::FnType::llvm_type
  12: <rustc::ty::layout::TyLayout<'tcx> as rustc_trans::type_of::LayoutLlvmExt<'tcx>>::llvm_type
  13: rustc_trans::abi::FnType::llvm_type
  14: rustc_trans::declare::declare_fn
  15: rustc_trans::trans_item::predefine_fn
  16: rustc_trans::trans_item::MonoItemExt::predefine
  17: rustc_trans::base::compile_codegen_unit
  18: rustc::dep_graph::graph::DepGraph::with_task_impl
  19: rustc_errors::Handler::track_diagnostics
  20: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  21: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::force
  22: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::try_get
  23: rustc::ty::maps::TyCtxtAt::compile_codegen_unit
  24: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::compile_codegen_unit
  25: rustc_trans::base::trans_crate
  26: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
  27: rustc::util::common::time
  28: rustc_driver::driver::phase_4_translate_to_llvm
  29: rustc_driver::driver::compile_input::{{closure}}
  30: <std::thread::local::LocalKey<T>>::with
  31: <std::thread::local::LocalKey<T>>::with
  32: rustc::ty::context::TyCtxt::create_and_enter
  33: rustc_driver::driver::compile_input
  34: rustc_driver::run_compiler_impl
  35: syntax::with_globals
@sfackler sfackler added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label May 15, 2018
@oli-obk oli-obk added 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. labels May 15, 2018
@nikomatsakis nikomatsakis added the P-high High priority label May 17, 2018
@nikomatsakis
Copy link
Contributor

Pending fix in #50819. Assigned to the current reviewer ( @michaelwoerister ).

kennytm added a commit to kennytm/rust that referenced this issue May 19, 2018
Fix potential divide by zero

This should fix rust-lang#50761

I had trouble reproducing with the provided code, but looking at the stack trace would indicate that this code is the likely cause. I made a number of assumptions here, because I don't have enough context on how the register size is set:

1. I assumed `rest.unit.size.bytes()` can be 0, and it's ok if it's set to 0 before this function is called
2. I assumed that if `rest.unit.size.bytes()` is 0, that we want `rest_count` to also be 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High 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.

5 participants