Skip to content

Commit 0b417dd

Browse files
committed
align cast result of flexible array member function
Closes #211
1 parent e09293a commit 0b417dd

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/Translator.zig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3980,7 +3980,8 @@ fn createFlexibleMemberFn(
39803980

39813981
// return @ptrCast(&self.*.<field_name>);
39823982
const address_of = try ZigTag.address_of.create(t.arena, field_access);
3983-
const casted = try ZigTag.ptr_cast.create(t.arena, address_of);
3983+
const aligned = try ZigTag.align_cast.create(t.arena, address_of);
3984+
const casted = try ZigTag.ptr_cast.create(t.arena, aligned);
39843985
const return_stmt = try ZigTag.@"return".create(t.arena, casted);
39853986
const body = try ZigTag.block_single.create(t.arena, return_stmt);
39863987

test/cases/translate/struct_with_flexible_array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ struct bar { int x; int y[0]; };
77
// x: c_int = 0,
88
// _y: [0]c_int = @import("std").mem.zeroes([0]c_int),
99
// pub fn y(self: anytype) __helpers.FlexibleArrayType(@TypeOf(self), @typeInfo(@TypeOf(self.*._y)).array.child) {
10-
// return @ptrCast(&self.*._y);
10+
// return @ptrCast(@alignCast(&self.*._y));
1111
// }
1212
// };
1313
// pub const struct_bar = extern struct {
1414
// x: c_int = 0,
1515
// _y: [0]c_int = @import("std").mem.zeroes([0]c_int),
1616
// pub fn y(self: anytype) __helpers.FlexibleArrayType(@TypeOf(self), @typeInfo(@TypeOf(self.*._y)).array.child) {
17-
// return @ptrCast(&self.*._y);
17+
// return @ptrCast(@alignCast(&self.*._y));
1818
// }
1919
// };

0 commit comments

Comments
 (0)