-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codegen: Explicitly align unions if needed.
Also adds a test header I missed from the previous PR. Fixes #1393
- Loading branch information
Showing
4 changed files
with
75 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
|
||
#[repr(C)] | ||
#[repr(align(16))] | ||
#[derive(Copy, Clone)] | ||
pub union Bar { | ||
pub foo: ::std::os::raw::c_uchar, | ||
_bindgen_union_align: u128, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_Bar() { | ||
assert_eq!( | ||
::std::mem::size_of::<Bar>(), | ||
16usize, | ||
concat!("Size of: ", stringify!(Bar)) | ||
); | ||
assert_eq!( | ||
::std::mem::align_of::<Bar>(), | ||
16usize, | ||
concat!("Alignment of ", stringify!(Bar)) | ||
); | ||
assert_eq!( | ||
unsafe { &(*(::std::ptr::null::<Bar>())).foo as *const _ as usize }, | ||
0usize, | ||
concat!("Offset of field: ", stringify!(Bar), "::", stringify!(foo)) | ||
); | ||
} | ||
impl Default for Bar { | ||
fn default() -> Self { | ||
unsafe { ::std::mem::zeroed() } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// bindgen-flags: --rust-target 1.26 | ||
|
||
struct foo { | ||
long double bar; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// bindgen-flags: --rust-target 1.26 | ||
|
||
union Bar { | ||
unsigned char foo; | ||
} __attribute__ ((__aligned__ (16))); |