authorgravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-06-24 13:37:39-04:00
committergravatar for kcbanner@gmail.comCasey Banner <kcbanner@gmail.com> 2023-06-24 13:49:24-04:00
logbaa2b62e88c5438c95ab439b12d3bafa55fd21a0
tree1e16229de7fe903666cf0f76c294d36c39594cc9
parenta5e15eced0e9cb00871966ede74eed9b3a07183c

cbe: fix crash caused by calling `mod.intValue` on `type_inferred_error_set`


2 files changed, 18 insertions(+), 2 deletions(-)

src/codegen/c.zig+1-2
......@@ -5654,14 +5654,13 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
56545654 const operand = try f.resolveInst(ty_op.operand);
56555655 const error_union_ty = f.typeOf(ty_op.operand).childType(mod);
56565656
5657 const error_ty = error_union_ty.errorUnionSet(mod);
56585657 const payload_ty = error_union_ty.errorUnionPayload(mod);
56595658
56605659 // First, set the non-error value.
56615660 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
56625661 try f.writeCValueDeref(writer, operand);
56635662 try writer.writeAll(" = ");
5664 try f.object.dg.renderValue(writer, error_ty, try mod.intValue(error_ty, 0), .Other);
5663 try f.object.dg.renderValue(writer, Type.err_int, try mod.intValue(Type.err_int, 0), .Other);
56655664 try writer.writeAll(";\n ");
56665665
56675666 return operand;
test/behavior/error.zig+17
......@@ -921,3 +921,20 @@ test "optional error set return type" {
921921 try expect(null == S.foo(true));
922922 try expect(E.A == S.foo(false).?);
923923}
924
925test "returning an error union containing a type with no runtime bits" {
926 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
927 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
928 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
929
930 const ZeroByteType = struct {
931 foo: void,
932
933 pub fn init() !@This() {
934 return .{ .foo = {} };
935 }
936 };
937
938 var zero_byte: ZeroByteType = undefined;
939 (&zero_byte).* = try ZeroByteType.init();
940}