mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
sema: pass sema through if available for the array_type case in bitSizeAdvanced
This commit is contained in:
parent
63e5476450
commit
3fc6a2f113
2 changed files with 12 additions and 1 deletions
|
|
@ -1519,7 +1519,10 @@ pub const Type = struct {
|
||||||
const len = array_type.len + @intFromBool(array_type.sentinel != .none);
|
const len = array_type.len + @intFromBool(array_type.sentinel != .none);
|
||||||
if (len == 0) return 0;
|
if (len == 0) return 0;
|
||||||
const elem_ty = array_type.child.toType();
|
const elem_ty = array_type.child.toType();
|
||||||
const elem_size = @max(elem_ty.abiAlignment(mod).toByteUnits(0), elem_ty.abiSize(mod));
|
const elem_size = @max(
|
||||||
|
(try elem_ty.abiAlignmentAdvanced(mod, strat)).scalar.toByteUnits(0),
|
||||||
|
(try elem_ty.abiSizeAdvanced(mod, strat)).scalar,
|
||||||
|
);
|
||||||
if (elem_size == 0) return 0;
|
if (elem_size == 0) return 0;
|
||||||
const elem_bit_size = try bitSizeAdvanced(elem_ty, mod, opt_sema);
|
const elem_bit_size = try bitSizeAdvanced(elem_ty, mod, opt_sema);
|
||||||
return (len - 1) * 8 * elem_size + elem_bit_size;
|
return (len - 1) * 8 * elem_size + elem_bit_size;
|
||||||
|
|
|
||||||
|
|
@ -300,3 +300,11 @@ test "@offsetOf zero-bit field" {
|
||||||
};
|
};
|
||||||
try expect(@offsetOf(S, "b") == @offsetOf(S, "c"));
|
try expect(@offsetOf(S, "b") == @offsetOf(S, "c"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "@bitSizeOf on array of structs" {
|
||||||
|
const S = struct {
|
||||||
|
foo: u64,
|
||||||
|
};
|
||||||
|
|
||||||
|
try expectEqual(128, @bitSizeOf([2]S));
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue