Skip to content

translate-c: fix applying struct alignment to first field #23863

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions src/translate_c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -977,8 +977,8 @@ fn transRecordDecl(c: *Context, scope: *Scope, record_decl: *const clang.RecordD
else => |e| return e,
};

const alignment = if (flexible_field != null and field_decl.getFieldIndex() == 0)
@as(c_uint, @intCast(record_alignment))
const alignment: ?c_uint = if (flexible_field == null and field_decl.getFieldIndex() == 0)
@intCast(record_alignment)
else
ClangAlignment.forField(c, field_decl, record_def).zigAlignment();

Expand Down
12 changes: 12 additions & 0 deletions test/cases/translate_c/aligned_struct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
struct __attribute__((aligned(16))) foo {
int bar;
int baz;
};

// translate-c
// c_frontend=aro,clang
//
// pub const struct_foo = extern struct {
// bar: c_int align(16) = @import("std").mem.zeroes(c_int),
// baz: c_int = @import("std").mem.zeroes(c_int),
// };
Loading