Skip to content

Commit 469a428

Browse files
committed
ir: consider all nested definitions inside structs to be inner types.
Fixes rust-lang#643
1 parent 5b74655 commit 469a428

File tree

3 files changed

+129
-10
lines changed

3 files changed

+129
-10
lines changed

src/ir/comp.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -588,21 +588,19 @@ impl CompInfo {
588588
CXCursor_ClassTemplate |
589589
CXCursor_ClassDecl => {
590590
// We can find non-semantic children here, clang uses a
591-
// StructDecl to note incomplete structs that hasn't been
592-
// forward-declared before, see:
591+
// StructDecl to note incomplete structs that haven't been
592+
// forward-declared before, see [1].
593593
//
594594
// Also, clang seems to scope struct definitions inside
595-
// unions to the whole translation unit. Since those are
596-
// anonymous, let's just assume that if the cursor we've
597-
// found is a definition it's a valid inner type.
595+
// unions, and other named struct definitions inside other
596+
// structs to the whole translation unit.
598597
//
599-
// Note that doing this could be always ok, but let's just
600-
// keep the union check for now.
598+
// Let's just assume that if the cursor we've found is a
599+
// definition, it's a valid inner type.
601600
//
602-
// https://github.com/servo/rust-bindgen/issues/482
601+
// [1]: https://github.com/servo/rust-bindgen/issues/482
603602
let is_inner_struct = cur.semantic_parent() == cursor ||
604-
(kind == CompKind::Union &&
605-
cur.is_definition());
603+
cur.is_definition();
606604
if !is_inner_struct {
607605
return CXChildVisit_Continue;
608606
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Default)]
9+
pub struct __IncompleteArrayField<T>(::std::marker::PhantomData<T>);
10+
impl <T> __IncompleteArrayField<T> {
11+
#[inline]
12+
pub fn new() -> Self {
13+
__IncompleteArrayField(::std::marker::PhantomData)
14+
}
15+
#[inline]
16+
pub unsafe fn as_ptr(&self) -> *const T { ::std::mem::transmute(self) }
17+
#[inline]
18+
pub unsafe fn as_mut_ptr(&mut self) -> *mut T {
19+
::std::mem::transmute(self)
20+
}
21+
#[inline]
22+
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
23+
::std::slice::from_raw_parts(self.as_ptr(), len)
24+
}
25+
#[inline]
26+
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
27+
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
28+
}
29+
}
30+
impl <T> ::std::fmt::Debug for __IncompleteArrayField<T> {
31+
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
32+
fmt.write_str("__IncompleteArrayField")
33+
}
34+
}
35+
impl <T> ::std::clone::Clone for __IncompleteArrayField<T> {
36+
#[inline]
37+
fn clone(&self) -> Self { Self::new() }
38+
}
39+
impl <T> ::std::marker::Copy for __IncompleteArrayField<T> { }
40+
#[repr(C)]
41+
#[derive(Debug, Copy)]
42+
pub struct rte_ring {
43+
pub memzone: *mut rte_memzone,
44+
pub prod: rte_ring_prod,
45+
pub cons: rte_ring_cons,
46+
pub ring: __IncompleteArrayField<*mut ::std::os::raw::c_void>,
47+
}
48+
#[repr(C)]
49+
#[derive(Debug, Default, Copy)]
50+
pub struct rte_ring_prod {
51+
pub watermark: ::std::os::raw::c_uint,
52+
}
53+
#[test]
54+
fn bindgen_test_layout_rte_ring_prod() {
55+
assert_eq!(::std::mem::size_of::<rte_ring_prod>() , 4usize , concat ! (
56+
"Size of: " , stringify ! ( rte_ring_prod ) ));
57+
assert_eq! (::std::mem::align_of::<rte_ring_prod>() , 4usize , concat ! (
58+
"Alignment of " , stringify ! ( rte_ring_prod ) ));
59+
assert_eq! (unsafe {
60+
& ( * ( 0 as * const rte_ring_prod ) ) . watermark as * const
61+
_ as usize } , 0usize , concat ! (
62+
"Alignment of field: " , stringify ! ( rte_ring_prod ) , "::"
63+
, stringify ! ( watermark ) ));
64+
}
65+
impl Clone for rte_ring_prod {
66+
fn clone(&self) -> Self { *self }
67+
}
68+
#[repr(C)]
69+
#[derive(Debug, Default, Copy)]
70+
pub struct rte_ring_cons {
71+
pub sc_dequeue: ::std::os::raw::c_uint,
72+
}
73+
#[test]
74+
fn bindgen_test_layout_rte_ring_cons() {
75+
assert_eq!(::std::mem::size_of::<rte_ring_cons>() , 4usize , concat ! (
76+
"Size of: " , stringify ! ( rte_ring_cons ) ));
77+
assert_eq! (::std::mem::align_of::<rte_ring_cons>() , 4usize , concat ! (
78+
"Alignment of " , stringify ! ( rte_ring_cons ) ));
79+
assert_eq! (unsafe {
80+
& ( * ( 0 as * const rte_ring_cons ) ) . sc_dequeue as * const
81+
_ as usize } , 0usize , concat ! (
82+
"Alignment of field: " , stringify ! ( rte_ring_cons ) , "::"
83+
, stringify ! ( sc_dequeue ) ));
84+
}
85+
impl Clone for rte_ring_cons {
86+
fn clone(&self) -> Self { *self }
87+
}
88+
#[test]
89+
fn bindgen_test_layout_rte_ring() {
90+
assert_eq!(::std::mem::size_of::<rte_ring>() , 16usize , concat ! (
91+
"Size of: " , stringify ! ( rte_ring ) ));
92+
assert_eq! (::std::mem::align_of::<rte_ring>() , 8usize , concat ! (
93+
"Alignment of " , stringify ! ( rte_ring ) ));
94+
}
95+
impl Clone for rte_ring {
96+
fn clone(&self) -> Self { *self }
97+
}
98+
impl Default for rte_ring {
99+
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
100+
}
101+
#[repr(C)]
102+
#[derive(Debug, Default, Copy)]
103+
pub struct rte_memzone {
104+
pub _address: u8,
105+
}
106+
impl Clone for rte_memzone {
107+
fn clone(&self) -> Self { *self }
108+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
struct rte_ring {
2+
struct rte_memzone *memzone;
3+
4+
struct prod {
5+
unsigned watermark;
6+
} prod;
7+
8+
struct cons {
9+
unsigned sc_dequeue;
10+
} cons;
11+
12+
void *ring[];
13+
};

0 commit comments

Comments
 (0)