Sema: require reified packed struct fields to have zero alignment

This commit is contained in:
Julian 2022-10-03 05:05:12 -05:00 committed by GitHub
parent 2eb0909206
commit 32d755beb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -17682,6 +17682,10 @@ fn reifyStruct(
}
const abi_align = @intCast(u29, (try alignment_val.getUnsignedIntAdvanced(target, sema.kit(block, src))).?);
if (layout == .Packed and abi_align != 0) {
return sema.fail(block, src, "alignment in a packed struct field must be set to 0", .{});
}
const field_name = try name_val.toAllocatedBytes(
Type.initTag(.const_slice_u8),
new_decl_arena_allocator,

View File

@ -0,0 +1,11 @@
export fn entry() void {
_ = @Type(.{ .Struct = .{ .layout = .Packed, .fields = &.{
.{ .name = "one", .field_type = u4, .default_value = null, .is_comptime = false, .alignment = 2 },
}, .decls = &.{}, .is_tuple = false } });
}
// error
// backend=stage2
// target=native
//
// :2:9: error: alignment in a packed struct field must be set to 0