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

Template type param as bitfield leads to panic #1140

Closed
fitzgen opened this issue Nov 2, 2017 · 0 comments
Closed

Template type param as bitfield leads to panic #1140

fitzgen opened this issue Nov 2, 2017 · 0 comments

Comments

@fitzgen
Copy link
Member

fitzgen commented Nov 2, 2017

Input C/C++ Header

template <class T>
class TemplatizedBitfield {
    T t : 6;
};

Bindgen Invocation

$ bindgen input.hpp

Actual Results

thread 'main' panicked at 'Bitfield without layout? Gah!', /checkout/src/libcore/option.rs:839:4
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:69
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:58
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:397
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:538
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:522
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:498
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:71
   9: core::option::expect_failed
             at /checkout/src/libcore/option.rs:839
  10: <core::option::Option<T>>::expect
             at /checkout/src/libcore/option.rs:302
  11: bindgen::ir::comp::bitfields_to_allocation_units
             at ./src/ir/comp.rs:573
  12: bindgen::ir::comp::raw_fields_to_fields_and_bitfield_units
             at ./src/ir/comp.rs:501
  13: bindgen::ir::comp::CompFields::compute_bitfield_units
             at ./src/ir/comp.rs:698
  14: bindgen::ir::comp::CompInfo::compute_bitfield_units
             at ./src/ir/comp.rs:1476
  15: bindgen::ir::context::BindgenContext::compute_bitfield_units::{{closure}}
             at ./src/ir/context.rs:996
  16: bindgen::ir::context::BindgenContext::with_loaned_item
             at ./src/ir/context.rs:979
  17: bindgen::ir::context::BindgenContext::compute_bitfield_units
             at ./src/ir/context.rs:995
  18: bindgen::ir::context::BindgenContext::gen
             at ./src/ir/context.rs:1170
  19: bindgen::codegen::codegen
             at ./src/codegen/mod.rs:3358
  20: bindgen::Bindings::generate
             at ./src/lib.rs:1635
  21: bindgen::Builder::generate
             at ./src/lib.rs:1097
  22: bindgen::main::{{closure}}
             at ./src/main.rs:55
  23: std::panicking::try::do_call
             at /checkout/src/libstd/panicking.rs:480
  24: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:99
  25: std::panicking::try
             at /checkout/src/libstd/panicking.rs:459
  26: std::panic::catch_unwind
             at /checkout/src/libstd/panic.rs:361
  27: bindgen::main
             at ./src/main.rs:54
  28: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:99
  29: std::rt::lang_start
             at /checkout/src/libstd/panicking.rs:459
             at /checkout/src/libstd/panic.rs:361
             at /checkout/src/libstd/rt.rs:59
  30: main
  31: __libc_start_main
  32: _start

Expected Results

No panic. Perhaps the templatized struct is opaque, or we don't emit bitfield accessors for it.

fitzgen added a commit to fitzgen/rust-bindgen that referenced this issue Nov 2, 2017
Instead of panicking when we see a bitfield that does not have a layout, return
an error up the stack. If we get an error when allocating bitfields into units,
then make the whole struct opaque.

Fixes rust-lang#1140
fitzgen added a commit to fitzgen/rust-bindgen that referenced this issue Nov 3, 2017
Instead of panicking when we see a bitfield that does not have a layout, return
an error up the stack. If we get an error when allocating bitfields into units,
then make the whole struct opaque.

Fixes rust-lang#1140
bors-servo pushed a commit that referenced this issue Nov 3, 2017
Make bitfield unit allocation fallible

Instead of panicking when we see a bitfield that does not have a layout, return an error up the stack. If we get an error when allocating bitfields into units, then make the whole struct opaque.

Fixes #1140

r? @pepyakin or @emilio
bors-servo pushed a commit that referenced this issue Nov 3, 2017
Make bitfield unit allocation fallible

Instead of panicking when we see a bitfield that does not have a layout, return an error up the stack. If we get an error when allocating bitfields into units, then make the whole struct opaque.

Fixes #1140

r? @pepyakin or @emilio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant