aboutsummaryrefslogtreecommitdiff
path: root/src/Type.zig
diff options
context:
space:
mode:
authormlugg <mlugg@mlugg.co.uk>2025-04-28 00:28:55 +0100
committerMatthew Lugg <mlugg@mlugg.co.uk>2025-05-03 20:10:26 +0100
commitf83fe2714bd4441610156e1a6017d07409ad6093 (patch)
treeace9b73ebcc5dec94488312d8078f62822849a08 /src/Type.zig
parentae1b444d6a651c6a6c6f09c15565d7b37759e488 (diff)
downloadzig-f83fe2714bd4441610156e1a6017d07409ad6093.tar.gz
zig-f83fe2714bd4441610156e1a6017d07409ad6093.zip
compiler: fix comptime memory store bugs
* When storing a zero-bit type, we should short-circuit almost immediately. Zero-bit stores do not need to do any work. * The bit size computation for arrays is incorrect; the `abiSize` will already be appropriately aligned, but the logic to do so here incorrectly assumes that zero-bit types have an alignment of 0. They don't; their alignment is 1. Resolves: #21202 Resolves: #21508 Resolves: #23307
Diffstat (limited to 'src/Type.zig')
-rw-r--r--src/Type.zig5
1 files changed, 1 insertions, 4 deletions
diff --git a/src/Type.zig b/src/Type.zig
index a789edefe1..f3e33abbec 100644
--- a/src/Type.zig
+++ b/src/Type.zig
@@ -1637,10 +1637,7 @@ pub fn bitSizeInner(
const len = array_type.lenIncludingSentinel();
if (len == 0) return 0;
const elem_ty = Type.fromInterned(array_type.child);
- const elem_size = @max(
- (try elem_ty.abiAlignmentInner(strat_lazy, zcu, tid)).scalar.toByteUnits() orelse 0,
- (try elem_ty.abiSizeInner(strat_lazy, zcu, tid)).scalar,
- );
+ const elem_size = (try elem_ty.abiSizeInner(strat_lazy, zcu, tid)).scalar;
if (elem_size == 0) return 0;
const elem_bit_size = try elem_ty.bitSizeInner(strat, zcu, tid);
return (len - 1) * 8 * elem_size + elem_bit_size;