diff options
| author | Luuk de Gram <luuk@degram.dev> | 2023-05-30 21:55:44 +0200 |
|---|---|---|
| committer | Luuk de Gram <luuk@degram.dev> | 2023-05-31 18:04:33 +0200 |
| commit | ebfd3450d9a3338726e1ed8b08a5751b06604cd5 (patch) | |
| tree | a74bf6ee7003cb7dbba333866619829c85c58659 | |
| parent | 7e10cf4fbe2a8a379564941be9953ce157d483cc (diff) | |
| download | zig-ebfd3450d9a3338726e1ed8b08a5751b06604cd5.tar.gz zig-ebfd3450d9a3338726e1ed8b08a5751b06604cd5.zip | |
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.
| -rw-r--r-- | src/arch/wasm/CodeGen.zig | 4 | ||||
| -rw-r--r-- | src/codegen.zig | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index 2072ff1506..d4be9bf139 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/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; diff --git a/src/codegen.zig b/src/codegen.zig index 692c55e380..adce183833 100644 --- a/src/codegen.zig +++ b/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 => { |
