cbe: correctly handle pointers to zero bit error union payloads

This commit is contained in:
Veikka Tuominen 2022-11-27 19:00:47 +02:00
parent 4def9c4a9b
commit 1a1a5702ab
2 changed files with 12 additions and 2 deletions

View File

@ -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);

View File

@ -342,7 +342,6 @@ test "optional pointer to zero bit optional payload" {
}
test "optional pointer to zero bit error union payload" {
if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO