-
Notifications
You must be signed in to change notification settings - Fork 717
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid divide-by-zero when checking if a field will merge with bitfields
- Loading branch information
Showing
3 changed files
with
72 additions
and
2 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
45 changes: 45 additions & 0 deletions
45
tests/expectations/tests/divide-by-zero-in-struct-layout.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,45 @@ | ||
/* 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 WithBitfield { | ||
pub _bitfield_1: [u8; 0usize], | ||
pub __bindgen_padding_0: u32, | ||
pub a: ::std::os::raw::c_uint, | ||
} | ||
impl WithBitfield { | ||
#[inline] | ||
pub fn new_bitfield_1() -> u8 { | ||
0 | ||
} | ||
} | ||
#[repr(C, packed)] | ||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct WithBitfieldAndAttrPacked { | ||
pub _bitfield_1: [u8; 0usize], | ||
pub a: ::std::os::raw::c_uint, | ||
pub __bindgen_padding_0: u8, | ||
} | ||
impl WithBitfieldAndAttrPacked { | ||
#[inline] | ||
pub fn new_bitfield_1() -> u8 { | ||
0 | ||
} | ||
} | ||
#[repr(C, packed)] | ||
#[derive(Debug, Default, Copy, Clone)] | ||
pub struct WithBitfieldAndPacked { | ||
pub _bitfield_1: [u8; 0usize], | ||
pub a: ::std::os::raw::c_uint, | ||
pub __bindgen_padding_0: u8, | ||
} | ||
impl WithBitfieldAndPacked { | ||
#[inline] | ||
pub fn new_bitfield_1() -> u8 { | ||
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,22 @@ | ||
// bindgen-flags: --no-layout-tests | ||
// | ||
// Unfortunately, we aren't translating the second and third structs correctly | ||
// yet. But we definitely shouldn't divide-by-zero when we see it... | ||
// | ||
// Once we fix #981 we should remove the `--no-layout-tests`. | ||
|
||
struct WithBitfield { | ||
unsigned : 7; | ||
unsigned a; | ||
}; | ||
|
||
struct WithBitfieldAndAttrPacked { | ||
unsigned : 7; | ||
unsigned a; | ||
} __attribute__((packed)); | ||
|
||
#pragma pack(1) | ||
struct WithBitfieldAndPacked { | ||
unsigned : 7; | ||
unsigned a; | ||
}; |