Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
- Fixed a panic when generating bindings for Objective-C methods that declare C-style parameters (#3488).
- Fixed a panic when an Objective-C method returns `Class`. The `Class` type is now generated as `*mut objc::runtime::Class` instead of an interface named after the enclosing declaration (#3484).
- Fixed a stack overflow when generating bindings for nested alias template instantiations such as `U<U<int>>` (#3478).
- Empty structs with `__attribute__((aligned(N)))` now get `#[repr(align(N))]`, so their alignment and the layout of structs containing them are correct (#3549).

## Security

Expand Down
56 changes: 56 additions & 0 deletions bindgen-tests/tests/expectations/tests/empty-struct-aligned-cpp.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions bindgen-tests/tests/expectations/tests/empty-struct-aligned.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions bindgen-tests/tests/headers/empty-struct-aligned-cpp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
struct empty_aligned {
} __attribute__((aligned(64)));

struct contains_empty_aligned {
int before;
empty_aligned empty;
long long after;
};
8 changes: 8 additions & 0 deletions bindgen-tests/tests/headers/empty-struct-aligned.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
struct empty_aligned {
} __attribute__((aligned(64)));

struct contains_empty_aligned {
int before;
struct empty_aligned empty;
long long after;
};
10 changes: 10 additions & 0 deletions bindgen/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,16 @@ impl CodeGenerator for CompInfo {
}
}
}
} else if !is_union && zero_sized && !forward_decl {
// An empty struct can still be over-aligned, e.g. with
// `__attribute__((aligned(N)))`.
if let Some(layout) = layout {
if layout.align > 1 &&
struct_layout.requires_explicit_align(layout)
{
explicit_align = Some(layout.align);
}
}
} else if is_union && !forward_decl {
if let Some(layout) = layout {
// TODO(emilio): It'd be nice to unify this with the struct path above somehow.
Expand Down
Loading