Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions bindgen-tests/tests/expectations/tests/issue-3406.rs

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

19 changes: 19 additions & 0 deletions bindgen-tests/tests/headers/issue-3406.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,26 @@ struct __attribute__((aligned(16))) Inner {
char byte;
};

typedef int AlignedInt __attribute__((aligned(16)));
typedef AlignedInt NestedAlignedInt;

struct Outer {
int before;
struct Inner inner;
};

struct Outer2 {
int before;
AlignedInt one;
AlignedInt two;
};

struct Outer3 {
int before;
AlignedInt inner;
};

struct Outer4 {
int before;
NestedAlignedInt inner;
};
9 changes: 9 additions & 0 deletions bindgen/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ impl Type {

/// What is the layout of this type?
pub(crate) fn layout(&self, ctx: &BindgenContext) -> Option<Layout> {
if let TypeKind::Alias(inner) | TypeKind::ResolvedTypeRef(inner) =
self.kind
{
// HACK(emilio): Rust can't represent over-aligned typedefs, so prefer the inner type's
// layout if available, to get struct layout correct at least...
if let Some(l) = ctx.resolve_type(inner).layout(ctx) {
return Some(l);
}
}
self.layout.or_else(|| {
match self.kind {
TypeKind::Comp(ref ci) => ci.layout(ctx),
Expand Down
Loading