authorgravatar for sinon@vortan.devDavid Rubin <sinon@vortan.dev> 2026-06-09 17:45:19-07:00
committergravatar for alichraghi@noreply.codeberg.orgAli Cheraghi <alichraghi@noreply.codeberg.org> 2026-06-18 22:42:42+02:00
logd5446652fa22db2e771be9af6ab755e8b199b5c9
treeaf6f8e48ab10b887a16f684fcacfd8b9e8dc33cf
parente6686ae00d8d4b4b104037f3afa6b0b603c7d708

Sema: correctly copy pointer attributes for optional pointer payload


2 files changed, 15 insertions(+), 6 deletions(-)

src/Sema.zig+4-6
...@@ -7956,12 +7956,10 @@ fn analyzeOptionalPayloadPtr(...@@ -7956,12 +7956,10 @@ fn analyzeOptionalPayloadPtr(
7956 }7956 }
79577957
7958 const child_type = opt_type.optionalChild(zcu);7958 const child_type = opt_type.optionalChild(zcu);
7959 const child_pointer = try pt.ptrType(.{7959 const child_pointer = try pt.ptrType(info: {
7960 .child = child_type.toIntern(),7960 var new = optional_ptr_ty.ptrInfo(zcu);
7961 .flags = .{7961 new.child = child_type.toIntern();
7962 .is_const = optional_ptr_ty.isConstPtr(zcu),7962 break :info new;
7963 .address_space = optional_ptr_ty.ptrAddressSpace(zcu),
7964 },
7965 });7963 });
79667964
7967 if (try sema.resolveDefinedValue(block, src, optional_ptr)) |ptr_val| {7965 if (try sema.resolveDefinedValue(block, src, optional_ptr)) |ptr_val| {
test/behavior/optional.zig+11
...@@ -665,3 +665,14 @@ test "global comptime only optional" {...@@ -665,3 +665,14 @@ test "global comptime only optional" {
665 assert(S.void.?.* == void);665 assert(S.void.?.* == void);
666 }666 }
667}667}
668
669test "optional ptr payload alignment" {
670 const S = struct {
671 fn doTheTest(p: *align(1) ?u32) !void {
672 comptime assert(@TypeOf(&p.*.?) == *align(1) u32);
673 try expect(p.*.? == 10);
674 }
675 };
676 var x: ?u32 = 10;
677 try S.doTheTest(&x);
678}