stage2: bitsize of packed struct should trigger backing int ty check

Closes #13398
This commit is contained in:
Veikka Tuominen 2022-11-04 18:47:52 +02:00
parent 51b1083d66
commit f92e7bed7b
2 changed files with 18 additions and 7 deletions

View File

@ -3574,15 +3574,13 @@ pub const Type = extern union {
.u128, .i128, .f128 => return 128,
.@"struct" => {
if (sema_kit) |sk| _ = try sk.sema.resolveTypeFields(sk.block, sk.src, ty);
if (ty.containerLayout() != .Packed) {
const struct_obj = ty.castTag(.@"struct").?.data;
if (struct_obj.layout != .Packed) {
return (try ty.abiSizeAdvanced(target, if (sema_kit) |sk| .{ .sema_kit = sk } else .eager)).scalar * 8;
}
var total: u64 = 0;
for (ty.structFields().values()) |field| {
total += try bitSizeAdvanced(field.ty, target, sema_kit);
}
return total;
if (sema_kit) |sk| _ = try sk.sema.resolveTypeLayout(sk.block, sk.src, ty);
assert(struct_obj.haveLayout());
return try struct_obj.backing_int_ty.bitSizeAdvanced(target, sema_kit);
},
.tuple, .anon_struct => {

View File

@ -0,0 +1,13 @@
const Foo = packed struct(u32) {
x: u1,
};
fn bar(_: Foo) callconv(.C) void {}
pub export fn entry() void {
bar(.{ .x = 0 });
}
// error
// backend=stage2
// target=native
//
// :1:27: error: backing integer type 'u32' has bit size 32 but the struct fields have a total bit size of 1