From 151597cc0dcfcad384218a2b92cae4b23b11ebe6 Mon Sep 17 00:00:00 2001 From: Pavel Verigo Date: Sun, 18 Oct 2026 18:29:34 +0200 Subject: [PATCH] x86_64: fix repr of ?error --- src/codegen/x86_64/CodeGen.zig | 20 +++++++++----------- test/behavior/optional.zig | 1 + 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/codegen/x86_64/CodeGen.zig b/src/codegen/x86_64/CodeGen.zig index 4f9b9ef0b0a2c6d3df51f642256e83b7cdda8a24..c6bf1686697b9f910ab279f41a20dcb0c02a2e74 100644 --- a/src/codegen/x86_64/CodeGen.zig +++ b/src/codegen/x86_64/CodeGen.zig @@ -181803,17 +181803,15 @@ fn intInfo(cg: *CodeGen, ty: Type) ?std.lang.Type.Int { .one, .many, .c => .{ .signedness = .unsigned, .bits = cg.target.ptrBitWidth() }, .slice => null, }, - .opt_type => |opt_child| return if (!Type.fromInterned(opt_child).hasRuntimeBits(zcu)) - .{ .signedness = .unsigned, .bits = 1 } - else switch (ip.indexToKey(opt_child)) { - .ptr_type => |ptr_type| switch (ptr_type.flags.size) { - .one, .many => switch (ptr_type.flags.is_allowzero) { - false => .{ .signedness = .unsigned, .bits = cg.target.ptrBitWidth() }, - true => null, - }, - .slice, .c => null, - }, - else => null, + .opt_type => |opt_child| { + if (!Type.fromInterned(opt_child).hasRuntimeBits(zcu)) { + return .{ .signedness = .unsigned, .bits = 1 }; + } + if (Type.fromInterned(ty_index).optionalReprIsPayload(zcu)) { + ty_index = opt_child; + continue; + } + return null; }, .error_union_type => |error_union_type| return if (!Type.fromInterned(error_union_type.payload_type) .hasRuntimeBits(zcu)) .{ .signedness = .unsigned, .bits = zcu.errorSetBits() } else null, diff --git a/test/behavior/optional.zig b/test/behavior/optional.zig index f8e36204603a2eb991c13eaa4fd3e4c8e0406018..f19877ab5c151db2d3d82532bb59c75c961a5e56 100644 --- a/test/behavior/optional.zig +++ b/test/behavior/optional.zig @@ -59,6 +59,7 @@ fn testNullPtrsEql() !void { } test "optional error equality" { + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; if (builtin.zig_backend == .stage2_riscv64) return error.SkipZigTest; -- 2.54.0