Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't emit #[repr(align(0))], and reduced test case #1593

Merged
merged 5 commits into from Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ir/comp.rs
Expand Up @@ -1072,6 +1072,12 @@ impl CompInfo {
return None;
}

// By definition, we don't have the right layout information here if
// we're a forward declaration.
if self.is_forward_declaration() {
return None;
}

let mut max_size = 0;
let mut max_align = 0;
for field in self.fields() {
Expand Down
@@ -1,6 +1,11 @@
/* automatically generated by rust-bindgen */

#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Debug, Default, Copy)]
Expand Down Expand Up @@ -73,7 +78,7 @@ extern "C" {
pub fn baz_struct(f: *mut Foo);
}
#[repr(C)]
#[derive(Copy)]
#[derive(Debug, Copy)]
pub struct Union {
_unused: [u8; 0],
}
Expand Down
19 changes: 19 additions & 0 deletions tests/expectations/tests/forward_declared_opaque.rs
@@ -0,0 +1,19 @@
/* automatically generated by rust-bindgen */

#![allow(
dead_code,
non_snake_case,
non_camel_case_types,
non_upper_case_globals
)]

#[repr(C)]
#[derive(Copy, Clone)]
pub struct a {
_unused: [u8; 0],
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct b {
_unused: [u8; 0],
}
4 changes: 4 additions & 0 deletions tests/headers/forward_declared_opaque.h
@@ -0,0 +1,4 @@
// bindgen-flags: --opaque-type "*"

union a;
struct b;