-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unnamed bit-fields should not affect alignment
According to the x86[-64] ABI spec: "Unnamed bit-fields’ types do not affect the alignment of a structure or union". This makes sense: such bit-fields are only used for padding, and we can't perform an un-aligned read of something we can't read because we can't even name it. Fixes #1076
- Loading branch information
Showing
4 changed files
with
54 additions
and
10 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
31 changes: 31 additions & 0 deletions
31
tests/expectations/tests/issue-1076-unnamed-bitfield-alignment.rs
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,31 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
|
||
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] | ||
|
||
|
||
#[repr(C)] | ||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct S1 { | ||
pub _bitfield_1: [u8; 2usize], | ||
pub __bindgen_padding_0: u8, | ||
} | ||
#[test] | ||
fn bindgen_test_layout_S1() { | ||
assert_eq!( | ||
::std::mem::size_of::<S1>(), | ||
3usize, | ||
concat!("Size of: ", stringify!(S1)) | ||
); | ||
assert_eq!( | ||
::std::mem::align_of::<S1>(), | ||
1usize, | ||
concat!("Alignment of ", stringify!(S1)) | ||
); | ||
} | ||
impl S1 { | ||
#[inline] | ||
pub fn new_bitfield_1() -> u16 { | ||
0 | ||
} | ||
} |
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,4 @@ | ||
struct S1 { | ||
signed : 15; | ||
unsigned : 6 | ||
}; |