motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit a5ea22d0693cf767fa47c9947399651ed3c35aaf (tree)
parent bb3532e775bb17fff1630103d4d29a650b7ad5c3
Author: William Sengir <william@sengir.com>
Date:   Sat, 23 Apr 2022 02:54:52 -0700

LLVM: correctly pad result tuple of `airOverflow`

Diffstat:
Msrc/codegen/llvm.zig | 12+++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig @@ -5605,14 +5605,24 @@ pub const FuncGen = struct { const lhs_ty = self.air.typeOf(extra.lhs); const scalar_ty = lhs_ty.scalarType(); + const dest_ty = self.air.typeOfIndex(inst); const intrinsic_name = if (scalar_ty.isSignedInt()) signed_intrinsic else unsigned_intrinsic; const llvm_lhs_ty = try self.dg.llvmType(lhs_ty); + const llvm_dest_ty = try self.dg.llvmType(dest_ty); + + const tg = self.dg.module.getTarget(); const llvm_fn = self.getIntrinsic(intrinsic_name, &.{llvm_lhs_ty}); const result_struct = self.builder.buildCall(llvm_fn, &[_]*const llvm.Value{ lhs, rhs }, 2, .Fast, .Auto, ""); - return result_struct; + + const result = self.builder.buildExtractValue(result_struct, 0, ""); + const overflow_bit = self.builder.buildExtractValue(result_struct, 1, ""); + + var ty_buf: Type.Payload.Pointer = undefined; + const partial = self.builder.buildInsertValue(llvm_dest_ty.getUndef(), result, llvmFieldIndex(dest_ty, 0, tg, &ty_buf).?, ""); + return self.builder.buildInsertValue(partial, overflow_bit, llvmFieldIndex(dest_ty, 1, tg, &ty_buf).?, ""); } fn buildElementwiseCall(