authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-19 15:24:22+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-19 20:21:48+02:00
log89f6ff177178dba4e66680227a02de7b4068123c
tree8363dfe4f78e21c681b3c59b504813bbf3734dd8
parente02749224357a33cffcaf9970d14c199adc3d892

stage2: correct use of .unwrap_err_union_* in LLVM and C backend


2 files changed, 21 insertions(+), 15 deletions(-)

src/codegen/c.zig+15-11
......@@ -3090,17 +3090,18 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
30903090 const operand = try f.resolveInst(ty_op.operand);
30913091 const operand_ty = f.air.typeOf(ty_op.operand);
30923092
3093 const payload_ty = operand_ty.errorUnionPayload();
3094 if (!payload_ty.hasRuntimeBits()) {
3095 if (operand_ty.zigTypeTag() == .Pointer) {
3096 const local = try f.allocLocal(inst_ty, .Const);
3097 try writer.writeAll(" = *");
3098 try f.writeCValue(writer, operand);
3099 try writer.writeAll(";\n");
3100 return local;
3101 } else {
3093 if (operand_ty.zigTypeTag() == .Pointer) {
3094 if (!operand_ty.childType().errorUnionPayload().hasRuntimeBits()) {
31023095 return operand;
31033096 }
3097 const local = try f.allocLocal(inst_ty, .Const);
3098 try writer.writeAll(" = *");
3099 try f.writeCValue(writer, operand);
3100 try writer.writeAll(";\n");
3101 return local;
3102 }
3103 if (!operand_ty.errorUnionPayload().hasRuntimeBits()) {
3104 return operand;
31043105 }
31053106
31063107 const local = try f.allocLocal(inst_ty, .Const);
......@@ -3123,8 +3124,11 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, maybe_addrof: []cons
31233124 const operand = try f.resolveInst(ty_op.operand);
31243125 const operand_ty = f.air.typeOf(ty_op.operand);
31253126
3126 const payload_ty = operand_ty.errorUnionPayload();
3127 if (!payload_ty.hasRuntimeBits()) {
3127 const error_union_ty = if (operand_ty.zigTypeTag() == .Pointer)
3128 operand_ty.childType()
3129 else
3130 operand_ty;
3131 if (!error_union_ty.errorUnionPayload().hasRuntimeBits()) {
31283132 return CValue.none;
31293133 }
31303134
src/codegen/llvm.zig+6-4
......@@ -3165,8 +3165,9 @@ pub const FuncGen = struct {
31653165
31663166 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
31673167 const operand = try self.resolveInst(ty_op.operand);
3168 const err_union_ty = self.air.typeOf(ty_op.operand);
3169 const payload_ty = err_union_ty.errorUnionPayload();
3168 const result_ty = self.air.getRefType(ty_op.ty);
3169 const payload_ty = if (operand_is_ptr) result_ty.childType() else result_ty;
3170
31703171 if (!payload_ty.hasRuntimeBits()) return null;
31713172 if (operand_is_ptr or isByRef(payload_ty)) {
31723173 return self.builder.buildStructGEP(operand, 1, "");
......@@ -3185,14 +3186,15 @@ pub const FuncGen = struct {
31853186 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
31863187 const operand = try self.resolveInst(ty_op.operand);
31873188 const operand_ty = self.air.typeOf(ty_op.operand);
3189 const err_set_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
31883190
3189 const payload_ty = operand_ty.errorUnionPayload();
3191 const payload_ty = err_set_ty.errorUnionPayload();
31903192 if (!payload_ty.hasRuntimeBits()) {
31913193 if (!operand_is_ptr) return operand;
31923194 return self.builder.buildLoad(operand, "");
31933195 }
31943196
3195 if (operand_is_ptr or isByRef(payload_ty)) {
3197 if (operand_is_ptr or isByRef(err_set_ty)) {
31963198 const err_field_ptr = self.builder.buildStructGEP(operand, 0, "");
31973199 return self.builder.buildLoad(err_field_ptr, "");
31983200 }