| author | |
| committer | |
| log | 89f6ff177178dba4e66680227a02de7b4068123c |
| tree | 8363dfe4f78e21c681b3c59b504813bbf3734dd8 |
| parent | e02749224357a33cffcaf9970d14c199adc3d892 |
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 { |
| 3090 | 3090 | const operand = try f.resolveInst(ty_op.operand); |
| 3091 | 3091 | const operand_ty = f.air.typeOf(ty_op.operand); |
| 3092 | 3092 | |
| 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()) { | |
| 3102 | 3095 | return operand; |
| 3103 | 3096 | } |
| 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; | |
| 3104 | 3105 | } |
| 3105 | 3106 | |
| 3106 | 3107 | const local = try f.allocLocal(inst_ty, .Const); |
| ... | ... | @@ -3123,8 +3124,11 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, maybe_addrof: []cons |
| 3123 | 3124 | const operand = try f.resolveInst(ty_op.operand); |
| 3124 | 3125 | const operand_ty = f.air.typeOf(ty_op.operand); |
| 3125 | 3126 | |
| 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()) { | |
| 3128 | 3132 | return CValue.none; |
| 3129 | 3133 | } |
| 3130 | 3134 |
src/codegen/llvm.zig+6-4| ... | ... | @@ -3165,8 +3165,9 @@ pub const FuncGen = struct { |
| 3165 | 3165 | |
| 3166 | 3166 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 3167 | 3167 | 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 | ||
| 3170 | 3171 | if (!payload_ty.hasRuntimeBits()) return null; |
| 3171 | 3172 | if (operand_is_ptr or isByRef(payload_ty)) { |
| 3172 | 3173 | return self.builder.buildStructGEP(operand, 1, ""); |
| ... | ... | @@ -3185,14 +3186,15 @@ pub const FuncGen = struct { |
| 3185 | 3186 | const ty_op = self.air.instructions.items(.data)[inst].ty_op; |
| 3186 | 3187 | const operand = try self.resolveInst(ty_op.operand); |
| 3187 | 3188 | const operand_ty = self.air.typeOf(ty_op.operand); |
| 3189 | const err_set_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty; | |
| 3188 | 3190 | |
| 3189 | const payload_ty = operand_ty.errorUnionPayload(); | |
| 3191 | const payload_ty = err_set_ty.errorUnionPayload(); | |
| 3190 | 3192 | if (!payload_ty.hasRuntimeBits()) { |
| 3191 | 3193 | if (!operand_is_ptr) return operand; |
| 3192 | 3194 | return self.builder.buildLoad(operand, ""); |
| 3193 | 3195 | } |
| 3194 | 3196 | |
| 3195 | if (operand_is_ptr or isByRef(payload_ty)) { | |
| 3197 | if (operand_is_ptr or isByRef(err_set_ty)) { | |
| 3196 | 3198 | const err_field_ptr = self.builder.buildStructGEP(operand, 0, ""); |
| 3197 | 3199 | return self.builder.buildLoad(err_field_ptr, ""); |
| 3198 | 3200 | } |