| author | |
| committer | |
| log | d5446652fa22db2e771be9af6ab755e8b199b5c9 |
| tree | af6f8e48ab10b887a16f684fcacfd8b9e8dc33cf |
| parent | e6686ae00d8d4b4b104037f3afa6b0b603c7d708 |
2 files changed, 15 insertions(+), 6 deletions(-)
src/Sema.zig+4-6| ... | ... | @@ -7956,12 +7956,10 @@ fn analyzeOptionalPayloadPtr( |
| 7956 | 7956 | } |
| 7957 | 7957 | |
| 7958 | 7958 | const child_type = opt_type.optionalChild(zcu); |
| 7959 | const child_pointer = try pt.ptrType(.{ | |
| 7960 | .child = child_type.toIntern(), | |
| 7961 | .flags = .{ | |
| 7962 | .is_const = optional_ptr_ty.isConstPtr(zcu), | |
| 7963 | .address_space = optional_ptr_ty.ptrAddressSpace(zcu), | |
| 7964 | }, | |
| 7959 | const child_pointer = try pt.ptrType(info: { | |
| 7960 | var new = optional_ptr_ty.ptrInfo(zcu); | |
| 7961 | new.child = child_type.toIntern(); | |
| 7962 | break :info new; | |
| 7965 | 7963 | }); |
| 7966 | 7964 | |
| 7967 | 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 | 665 | assert(S.void.?.* == void); |
| 666 | 666 | } |
| 667 | 667 | } |
| 668 | ||
| 669 | test "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 | } |