Skip to content

Commit 041ee54

Browse files
author
bors-servo
authored
Auto merge of #495 - flier:fix-493, r=emilio
check layout align before padding bytes Fix issue #493 again :S Still finding way to reproduce it
2 parents ddfa1e0 + e08072a commit 041ee54

File tree

3 files changed

+203
-1
lines changed

3 files changed

+203
-1
lines changed

src/codegen/struct_layout.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,12 @@ impl<'a, 'ctx> StructLayoutTracker<'a, 'ctx> {
8989
Some(offset) if offset / 8 > self.latest_offset => {
9090
(offset / 8 - self.latest_offset, true)
9191
}
92-
_ => {
92+
_ if field_layout.align != 0 => {
9393
(self.padding_bytes(field_layout), (self.latest_offset % field_layout.align) != 0)
9494
}
95+
_ => {
96+
(0, false)
97+
}
9598
};
9699

97100
self.latest_offset += padding_bytes;

tests/expectations/tests/issue-493.rs

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
pub struct __BindgenUnionField<T>(::std::marker::PhantomData<T>);
9+
impl <T> __BindgenUnionField<T> {
10+
#[inline]
11+
pub fn new() -> Self { __BindgenUnionField(::std::marker::PhantomData) }
12+
#[inline]
13+
pub unsafe fn as_ref(&self) -> &T { ::std::mem::transmute(self) }
14+
#[inline]
15+
pub unsafe fn as_mut(&mut self) -> &mut T { ::std::mem::transmute(self) }
16+
}
17+
impl <T> ::std::default::Default for __BindgenUnionField<T> {
18+
#[inline]
19+
fn default() -> Self { Self::new() }
20+
}
21+
impl <T> ::std::clone::Clone for __BindgenUnionField<T> {
22+
#[inline]
23+
fn clone(&self) -> Self { Self::new() }
24+
}
25+
impl <T> ::std::marker::Copy for __BindgenUnionField<T> { }
26+
impl <T> ::std::fmt::Debug for __BindgenUnionField<T> {
27+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
28+
fmt.write_str("__BindgenUnionField")
29+
}
30+
}
31+
#[repr(C)]
32+
#[derive(Debug, Copy, Clone)]
33+
pub struct basic_string<_CharT, _Traits, _Allocator> {
34+
pub _address: u8,
35+
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
36+
pub _phantom_1: ::std::marker::PhantomData<_Traits>,
37+
pub _phantom_2: ::std::marker::PhantomData<_Allocator>,
38+
}
39+
pub type basic_string_size_type = ::std::os::raw::c_ulonglong;
40+
pub type basic_string_value_type = ::std::os::raw::c_char;
41+
pub type basic_string_pointer = *mut basic_string_value_type;
42+
#[repr(C)]
43+
#[derive(Debug, Copy, Clone)]
44+
pub struct basic_string___long<_CharT, _Traits, _Allocator> {
45+
pub __cap_: basic_string_size_type,
46+
pub __size_: basic_string_size_type,
47+
pub __data_: basic_string_pointer,
48+
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
49+
pub _phantom_1: ::std::marker::PhantomData<_Traits>,
50+
pub _phantom_2: ::std::marker::PhantomData<_Allocator>,
51+
}
52+
impl <_CharT, _Traits, _Allocator> Default for
53+
basic_string___long<_CharT, _Traits, _Allocator> {
54+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
55+
}
56+
pub const basic_string___min_cap: basic_string__bindgen_ty_1 =
57+
basic_string__bindgen_ty_1::__min_cap;
58+
#[repr(i32)]
59+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
60+
pub enum basic_string__bindgen_ty_1 { __min_cap = 0, }
61+
#[repr(C)]
62+
#[derive(Debug, Copy, Clone)]
63+
pub struct basic_string___short<_CharT, _Traits, _Allocator> {
64+
pub __bindgen_anon_1: basic_string___short__bindgen_ty_1<_CharT, _Traits,
65+
_Allocator>,
66+
pub __data_: *mut basic_string_value_type,
67+
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
68+
pub _phantom_1: ::std::marker::PhantomData<_Traits>,
69+
pub _phantom_2: ::std::marker::PhantomData<_Allocator>,
70+
}
71+
#[repr(C)]
72+
#[derive(Debug, Default, Copy, Clone)]
73+
pub struct basic_string___short__bindgen_ty_1<_CharT, _Traits, _Allocator> {
74+
pub __size_: __BindgenUnionField<::std::os::raw::c_uchar>,
75+
pub __lx: __BindgenUnionField<basic_string_value_type>,
76+
pub bindgen_union_field: u8,
77+
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
78+
pub _phantom_1: ::std::marker::PhantomData<_Traits>,
79+
pub _phantom_2: ::std::marker::PhantomData<_Allocator>,
80+
}
81+
impl <_CharT, _Traits, _Allocator> Default for
82+
basic_string___short<_CharT, _Traits, _Allocator> {
83+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
84+
}
85+
#[repr(C)]
86+
#[derive(Copy, Clone)]
87+
pub struct basic_string___ulx<_CharT, _Traits, _Allocator> {
88+
pub __lx: __BindgenUnionField<basic_string___long<_CharT, _Traits,
89+
_Allocator>>,
90+
pub __lxx: __BindgenUnionField<basic_string___short<_CharT, _Traits,
91+
_Allocator>>,
92+
pub bindgen_union_field: [u8; 0usize],
93+
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
94+
pub _phantom_1: ::std::marker::PhantomData<_Traits>,
95+
pub _phantom_2: ::std::marker::PhantomData<_Allocator>,
96+
}
97+
impl <_CharT, _Traits, _Allocator> Default for
98+
basic_string___ulx<_CharT, _Traits, _Allocator> {
99+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
100+
}
101+
pub const basic_string___n_words: basic_string__bindgen_ty_2 =
102+
basic_string__bindgen_ty_2::__n_words;
103+
#[repr(i32)]
104+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
105+
pub enum basic_string__bindgen_ty_2 { __n_words = 0, }
106+
#[repr(C)]
107+
#[derive(Debug, Copy, Clone)]
108+
pub struct basic_string___raw<_CharT, _Traits, _Allocator> {
109+
pub __words: *mut basic_string_size_type,
110+
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
111+
pub _phantom_1: ::std::marker::PhantomData<_Traits>,
112+
pub _phantom_2: ::std::marker::PhantomData<_Allocator>,
113+
}
114+
impl <_CharT, _Traits, _Allocator> Default for
115+
basic_string___raw<_CharT, _Traits, _Allocator> {
116+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
117+
}
118+
#[repr(C)]
119+
#[derive(Copy, Clone)]
120+
pub struct basic_string___rep<_CharT, _Traits, _Allocator> {
121+
pub __bindgen_anon_1: basic_string___rep__bindgen_ty_1<_CharT, _Traits,
122+
_Allocator>,
123+
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
124+
pub _phantom_1: ::std::marker::PhantomData<_Traits>,
125+
pub _phantom_2: ::std::marker::PhantomData<_Allocator>,
126+
}
127+
#[repr(C)]
128+
#[derive(Copy, Clone)]
129+
pub struct basic_string___rep__bindgen_ty_1<_CharT, _Traits, _Allocator> {
130+
pub __l: __BindgenUnionField<basic_string___long<_CharT, _Traits,
131+
_Allocator>>,
132+
pub __s: __BindgenUnionField<basic_string___short<_CharT, _Traits,
133+
_Allocator>>,
134+
pub __r: __BindgenUnionField<basic_string___raw<_CharT, _Traits,
135+
_Allocator>>,
136+
pub bindgen_union_field: [u8; 0usize],
137+
pub _phantom_0: ::std::marker::PhantomData<_CharT>,
138+
pub _phantom_1: ::std::marker::PhantomData<_Traits>,
139+
pub _phantom_2: ::std::marker::PhantomData<_Allocator>,
140+
}
141+
impl <_CharT, _Traits, _Allocator> Default for
142+
basic_string___rep__bindgen_ty_1<_CharT, _Traits, _Allocator> {
143+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
144+
}
145+
impl <_CharT, _Traits, _Allocator> Default for
146+
basic_string___rep<_CharT, _Traits, _Allocator> {
147+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
148+
}
149+
impl <_CharT, _Traits, _Allocator> Default for
150+
basic_string<_CharT, _Traits, _Allocator> {
151+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
152+
}

tests/headers/issue-493.hpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
template<class _CharT, class _Traits, class _Allocator>
2+
class basic_string
3+
{
4+
public:
5+
typedef unsigned long long size_type;
6+
typedef char value_type;
7+
typedef value_type * pointer;
8+
9+
struct __long
10+
{
11+
size_type __cap_;
12+
size_type __size_;
13+
pointer __data_;
14+
};
15+
16+
enum {__min_cap = (sizeof(__long) - 1)/sizeof(value_type) > 2 ?
17+
(sizeof(__long) - 1)/sizeof(value_type) : 2};
18+
19+
struct __short
20+
{
21+
union
22+
{
23+
unsigned char __size_;
24+
value_type __lx;
25+
};
26+
value_type __data_[__min_cap];
27+
};
28+
29+
union __ulx{__long __lx; __short __lxx;};
30+
31+
enum {__n_words = sizeof(__ulx) / sizeof(size_type)};
32+
33+
struct __raw
34+
{
35+
size_type __words[__n_words];
36+
};
37+
38+
struct __rep
39+
{
40+
union
41+
{
42+
__long __l;
43+
__short __s;
44+
__raw __r;
45+
};
46+
};
47+
};

0 commit comments

Comments
 (0)