Skip to content

Commit 281b62e

Browse files
pmarksemilio
authored andcommitted
Fix layout computation for union forward declarations (#1593)
1 parent f354836 commit 281b62e

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

src/ir/comp.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,12 @@ impl CompInfo {
10721072
return None;
10731073
}
10741074

1075+
// By definition, we don't have the right layout information here if
1076+
// we're a forward declaration.
1077+
if self.is_forward_declaration() {
1078+
return None;
1079+
}
1080+
10751081
let mut max_size = 0;
10761082
let mut max_align = 0;
10771083
for field in self.fields() {

tests/expectations/tests/forward_declared_complex_types_1_0.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/* automatically generated by rust-bindgen */
22

3-
#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
3+
#![allow(
4+
dead_code,
5+
non_snake_case,
6+
non_camel_case_types,
7+
non_upper_case_globals
8+
)]
49

510
#[repr(C)]
611
#[derive(Debug, Default, Copy)]
@@ -73,7 +78,7 @@ extern "C" {
7378
pub fn baz_struct(f: *mut Foo);
7479
}
7580
#[repr(C)]
76-
#[derive(Copy)]
81+
#[derive(Debug, Copy)]
7782
pub struct Union {
7883
_unused: [u8; 0],
7984
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
#![allow(
4+
dead_code,
5+
non_snake_case,
6+
non_camel_case_types,
7+
non_upper_case_globals
8+
)]
9+
10+
#[repr(C)]
11+
#[derive(Copy, Clone)]
12+
pub struct a {
13+
_unused: [u8; 0],
14+
}
15+
#[repr(C)]
16+
#[derive(Debug, Default, Copy, Clone)]
17+
pub struct b {
18+
_unused: [u8; 0],
19+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// bindgen-flags: --opaque-type "*"
2+
3+
union a;
4+
struct b;

0 commit comments

Comments
 (0)