authorgravatar for 58199799+mov-rax@users.noreply.github.comJulian <58199799+mov-rax@users.noreply.github.com> 2022-10-03 05:05:12-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-10-03 13:05:12+03:00
log32d755beb8d83a666100ca9455df51b93caff1fc
treef17274c9e85736b61dd3cb6cfcb5f2cd446caada
parent2eb09092065715642e93d9cfd54196840a314bc0
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Sema: require reified packed struct fields to have zero alignment


2 files changed, 15 insertions(+), 0 deletions(-)

src/Sema.zig+4
......@@ -17682,6 +17682,10 @@ fn reifyStruct(
1768217682 }
1768317683 const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?);
1768417684
17685 if (layout == .Packed and abi_align != 0) {
17686 return sema.fail(block, src, "alignment in a packed struct field must be set to 0", .{});
17687 }
17688
1768517689 const field_name = try name_val.toAllocatedBytes(
1768617690 Type.initTag(.const_slice_u8),
1768717691 new_decl_arena_allocator,
test/cases/compile_errors/packed_struct_field_alignment_unavailable_for_reify_type.zig created+11
......@@ -0,0 +1,11 @@
1export fn entry() void {
2 _ = @Type(.{ .Struct = .{ .layout = .Packed, .fields = &.{
3 .{ .name = "one", .field_type = u4, .default_value = null, .is_comptime = false, .alignment = 2 },
4 }, .decls = &.{}, .is_tuple = false } });
5}
6
7// error
8// backend=stage2
9// target=native
10//
11// :2:9: error: alignment in a packed struct field must be set to 0