codegen: Write padding bytes for unions

Previously we did not write any missing padding bytes after the smallest
field (either tag or payload, depending on alignment). This resulted in
writing too few bytes and not matching the full abisize of the union.
This commit is contained in:
Luuk de Gram 2023-05-30 21:55:44 +02:00
parent 7e10cf4fbe
commit ebfd3450d9
No known key found for this signature in database
GPG Key ID: A8CFE58E4DC7D664
2 changed files with 6 additions and 2 deletions

View File

@ -1726,8 +1726,8 @@ fn isByRef(ty: Type, target: std.Target) bool {
.Array,
.Frame,
.Union,
=> {
=> return ty.hasRuntimeBitsIgnoreComptime(),
.Union => {
if (ty.castTag(.@"union")) |union_ty| {
if (union_ty.data.layout == .Packed) {
return ty.abiSize(target) > 8;

View File

@ -611,6 +611,10 @@ pub fn generateSymbol(
}
}
if (layout.padding > 0) {
try code.writer().writeByteNTimes(0, layout.padding);
}
return Result.ok;
},
.Optional => {