aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordweiller <4678790+dweiller@users.noreply.github.com>2025-04-09 14:25:37 +1000
committerMatthew Lugg <mlugg@mlugg.co.uk>2025-04-28 16:48:45 +0100
commit365ed0ed68b6f6c39b3b8f5373fbba25fe09a518 (patch)
tree48a6cb2d7b9f0a7eba8f85acac7e4f0dc6b8b1b4 /src
parent1f6336794b519d827eb2da583e238e95c6f7e0e5 (diff)
downloadzig-365ed0ed68b6f6c39b3b8f5373fbba25fe09a518.tar.gz
zig-365ed0ed68b6f6c39b3b8f5373fbba25fe09a518.zip
sema: do checked cast when resolving aggregate size
Diffstat (limited to 'src')
-rw-r--r--src/Sema.zig20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index ef26d5a9dd..9e7427b4fa 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -34985,7 +34985,15 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
offsets[i] = @intCast(aligns[i].forward(offset));
offset = offsets[i] + sizes[i];
}
- struct_type.setLayoutResolved(ip, @intCast(big_align.forward(offset)), big_align);
+ const size = std.math.cast(u32, big_align.forward(offset)) orelse {
+ const msg = try sema.errMsg(
+ ty.srcLoc(zcu),
+ "struct layout requires size {d}, this compiler implementation supports up to {d}",
+ .{ big_align.forward(offset), std.math.maxInt(u32) },
+ );
+ return sema.failWithOwnedErrorMsg(null, msg);
+ };
+ struct_type.setLayoutResolved(ip, size, big_align);
_ = try ty.comptimeOnlySema(pt);
}
@@ -35260,7 +35268,15 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
break :layout .{ size, max_align.max(tag_align), padding };
} else .{ max_align.forward(max_size), max_align, 0 };
- union_type.setHaveLayout(ip, @intCast(size), padding, alignment);
+ const casted_size = std.math.cast(u32, size) orelse {
+ const msg = try sema.errMsg(
+ ty.srcLoc(pt.zcu),
+ "union layout requires size {d}, this compiler implementation supports up to {d}",
+ .{ size, std.math.maxInt(u32) },
+ );
+ return sema.failWithOwnedErrorMsg(null, msg);
+ };
+ union_type.setHaveLayout(ip, casted_size, padding, alignment);
if (union_type.flagsUnordered(ip).assumed_runtime_bits and !(try ty.hasRuntimeBitsSema(pt))) {
const msg = try sema.errMsg(