rust-lang / rust-lang/rust-bindgen

Emit wrong layout with inheriting from zero-sized type parameters

Open
#586 7 comments 0 reactions 1 assignee View on GitHub

@fitzgen is already working on this.

Since Mar 15, 2017.

bug I-bogus-codegen I-failing-layout-test
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
namespace JS {
namespace detail {
class a {};
template <class b> class CallArgsBase : b {
  int *c;
  unsigned d;
};
}
}
class B : JS::detail::CallArgsBase<JS::detail::a> {};
Bindgen Invokation
$ bindgen input.hpp --enable-cxx-namespaces -- -std=c++14
Actual Results

Compiles into this:

/* automatically generated by rust-bindgen */

#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
    #[allow(unused_imports)]
    use self::super::root;
    pub mod JS {
        #[allow(unused_imports)]
        use self::super::super::root;
        pub mod detail {
            #[allow(unused_imports)]
            use self::super::super::super::root;
            #[repr(C)]
            #[derive(Debug, Copy)]
            pub struct a {
                pub _address: u8,
            }
            #[test]
            fn bindgen_test_layout_a() {
                assert_eq!(::std::mem::size_of::<a>() , 1usize , concat ! (
                           "Size of: " , stringify ! ( a ) ));
                assert_eq! (::std::mem::align_of::<a>() , 1usize , concat ! (
                            "Alignment of " , stringify ! ( a ) ));
            }
            impl Clone for a {
                fn clone(&self) -> Self { *self }
            }
            #[repr(C)]
            #[derive(Debug, Copy, Clone)]
            pub struct CallArgsBase<b> {
                pub _base: b,
                pub c: *mut ::std::os::raw::c_int,
                pub d: ::std::os::raw::c_uint,
            }
        }
    }
    #[test]
    fn __bindgen_test_layout_CallArgsBase_instantiation_16() {
        assert_eq!(::std::mem::size_of::<root::JS::detail::CallArgsBase<root::JS::detail::a>>()
                   , 16usize , concat ! (
                   "Size of template specialization: " , stringify ! (
                   root::JS::detail::CallArgsBase<root::JS::detail::a> ) ));
        assert_eq!(::std::mem::align_of::<root::JS::detail::CallArgsBase<root::JS::detail::a>>()
                   , 8usize , concat ! (
                   "Alignment of template specialization: " , stringify ! (
                   root::JS::detail::CallArgsBase<root::JS::detail::a> ) ));
    }
}

And results in this layout test failure:

running 2 tests
test root::JS::detail::bindgen_test_layout_a ... ok
test root::__bindgen_test_layout_CallArgsBase_instantiation_16 ... FAILED

failures:

---- root::__bindgen_test_layout_CallArgsBase_instantiation_16 stdout ----
	thread 'root::__bindgen_test_layout_CallArgsBase_instantiation_16' panicked at 'assertion failed: `(left == right)` (left: `24`, right: `16`): Size of template specialization: root :: JS :: detail :: CallArgsBase < root :: JS :: detail :: a >', ./js.rs:41
note: Run with `RUST_BACKTRACE=1` for a backtrace.


failures:
    root::__bindgen_test_layout_CallArgsBase_instantiation_16

test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured
Expected Results

Maybe opaque blobs, but never any layout test failures.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.