diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-02-19 15:24:22 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-02-19 20:21:48 +0200 |
| commit | 89f6ff177178dba4e66680227a02de7b4068123c (patch) | |
| tree | 8363dfe4f78e21c681b3c59b504813bbf3734dd8 /src/codegen/c.zig | |
| parent | e02749224357a33cffcaf9970d14c199adc3d892 (diff) | |
| download | zig-89f6ff177178dba4e66680227a02de7b4068123c.tar.gz zig-89f6ff177178dba4e66680227a02de7b4068123c.zip | |
stage2: correct use of .unwrap_err_union_* in LLVM and C backend
Diffstat (limited to 'src/codegen/c.zig')
| -rw-r--r-- | src/codegen/c.zig | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 776cec6457..f6e2d467a7 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -3090,17 +3090,18 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue { const operand = try f.resolveInst(ty_op.operand); const operand_ty = f.air.typeOf(ty_op.operand); - const payload_ty = operand_ty.errorUnionPayload(); - if (!payload_ty.hasRuntimeBits()) { - if (operand_ty.zigTypeTag() == .Pointer) { - const local = try f.allocLocal(inst_ty, .Const); - try writer.writeAll(" = *"); - try f.writeCValue(writer, operand); - try writer.writeAll(";\n"); - return local; - } else { + if (operand_ty.zigTypeTag() == .Pointer) { + if (!operand_ty.childType().errorUnionPayload().hasRuntimeBits()) { return operand; } + const local = try f.allocLocal(inst_ty, .Const); + try writer.writeAll(" = *"); + try f.writeCValue(writer, operand); + try writer.writeAll(";\n"); + return local; + } + if (!operand_ty.errorUnionPayload().hasRuntimeBits()) { + return operand; } const local = try f.allocLocal(inst_ty, .Const); @@ -3123,8 +3124,11 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, maybe_addrof: []cons const operand = try f.resolveInst(ty_op.operand); const operand_ty = f.air.typeOf(ty_op.operand); - const payload_ty = operand_ty.errorUnionPayload(); - if (!payload_ty.hasRuntimeBits()) { + const error_union_ty = if (operand_ty.zigTypeTag() == .Pointer) + operand_ty.childType() + else + operand_ty; + if (!error_union_ty.errorUnionPayload().hasRuntimeBits()) { return CValue.none; } |
