From 6afcaf4a08b6fb1cce0cdb2393fc1d4cd041509c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 21 Nov 2021 19:39:32 -0700 Subject: stage2: fix the build for 32-bit architectures * Introduce a mechanism into Sema for emitting a compile error when an integer is too big and we need it to fit into a usize. * Add `@intCast` where necessary * link/MachO: fix an unnecessary allocation when all that was happening was appending zeroes to an ArrayList. * Add `error.Overflow` as a possible error to some codepaths, allowing usage of `math.intCast`. closes #9710 --- src/codegen.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/codegen.zig') diff --git a/src/codegen.zig b/src/codegen.zig index 0f13b43c36..3a74342adf 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -37,6 +37,7 @@ pub const Result = union(enum) { pub const GenerateSymbolError = error{ OutOfMemory, + Overflow, /// A Decl that this symbol depends on had a semantic analysis failure. AnalysisFail, }; @@ -289,7 +290,8 @@ pub fn generateSymbol( const field_vals = typed_value.val.castTag(.@"struct").?.data; _ = field_vals; // TODO write the fields for real const target = bin_file.options.target; - try code.writer().writeByteNTimes(0xaa, typed_value.ty.abiSize(target)); + const abi_size = try math.cast(usize, typed_value.ty.abiSize(target)); + try code.writer().writeByteNTimes(0xaa, abi_size); return Result{ .appended = {} }; }, else => |t| { -- cgit v1.2.3