Skip to content

Template type param as bitfield leads to panic #1140

Closed
@fitzgen

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions