aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-11-27 19:00:47 +0200
committerVeikka Tuominen <git@vexu.eu>2022-11-30 15:14:33 +0200
commit1a1a5702abd61bb670b26bfa4a02d0ff7a6cc84b (patch)
tree343a8272eb4946ae5501e56b45e0337f650fd561 /src/codegen
parent4def9c4a9b384a5980086825bcb849a88438912b (diff)
downloadzig-1a1a5702abd61bb670b26bfa4a02d0ff7a6cc84b.tar.gz
zig-1a1a5702abd61bb670b26bfa4a02d0ff7a6cc84b.zip
cbe: correctly handle pointers to zero bit error union payloads
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/c.zig13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 97b37309b2..6a7ef2c007 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -4580,7 +4580,18 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
const operand_is_ptr = operand_ty.zigTypeTag() == .Pointer;
const error_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
- if (!error_union_ty.errorUnionPayload().hasRuntimeBits()) return CValue.none;
+ if (!error_union_ty.errorUnionPayload().hasRuntimeBits()) {
+ if (!is_ptr) return CValue.none;
+
+ const local = try f.allocLocal(inst_ty, .Const);
+ const w = f.object.writer();
+ try w.writeAll(" = (");
+ try f.renderTypecast(w, inst_ty);
+ try w.writeByte(')');
+ try f.writeCValue(w, operand, .Initializer);
+ try w.writeAll(";\n");
+ return local;
+ }
const writer = f.object.writer();
const local = try f.allocLocal(inst_ty, .Const);