Commit ebfd3450d9

Luuk de Gram <luuk@degram.dev>
2023-05-30 21:55:44
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.
1 parent 7e10cf4
Changed files (2)
src/arch/wasm/CodeGen.zig
@@ -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;
src/codegen.zig
@@ -611,6 +611,10 @@ pub fn generateSymbol(
                 }
             }
 
+            if (layout.padding > 0) {
+                try code.writer().writeByteNTimes(0, layout.padding);
+            }
+
             return Result.ok;
         },
         .Optional => {