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

Wrong layout for union with bitfields #1056

Closed
pepyakin opened this issue Oct 3, 2017 · 3 comments
Closed

Wrong layout for union with bitfields #1056

pepyakin opened this issue Oct 3, 2017 · 3 comments

Comments

@pepyakin
Copy link
Contributor

pepyakin commented Oct 3, 2017

See original issue #1034

Input C/C++ Header

Generated by C-Smith and reduced by creduce:

union U4 {
  unsigned : 1
};

Bindgen Invocation

$ bindgen input.h --with-derive-partialeq --with-derive-eq

Actual Results

running 1 test
test bindgen_test_layout_U4 ... FAILED

failures:

---- bindgen_test_layout_U4 stdout ----
	thread 'bindgen_test_layout_U4' panicked at 'assertion failed: `(left == right)`
  left: `2`,
 right: `1`: Size of: U4', /var/folders/cd/c9707gm91qj22fkb99clygfm0000gn/T/bindings.rs.XXXXXX.E24MhMan:58:4

failures:
    bindgen_test_layout_U4

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

Expected Results

No layout test failures.

@pepyakin
Copy link
Contributor Author

pepyakin commented Oct 3, 2017

Seems like we have a different problem in the size case.

Let's consider this header:

union U4 {
  unsigned : 1
};

in generated bindings assert test is failing

assert_eq!(
    ::std::mem::size_of::<U4>(),
    1usize,
    concat!("Size of: ", stringify!(U4))
);

and it makes sense if we look at U4 definition:

#[repr(C)]
#[derive(Copy)]
pub struct U4 {
    pub _bitfield_1: u8,
    pub bindgen_union_field: u8,
}

there are 2 disjoint fields, and this is clearly wrong.

I suppose in this case we shouldn't generate _bitfield_1 but should refer bindgen_union_field in bitfield's accessors.

@emilio
Copy link
Contributor

emilio commented Oct 3, 2017

This is a dupe of #744, I believe.

@pepyakin
Copy link
Contributor Author

pepyakin commented Oct 3, 2017

Agree, closing.

@pepyakin pepyakin closed this as completed Oct 3, 2017
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

2 participants