| ... | @@ -518,8 +518,13 @@ const Parser = struct { | ... | @@ -518,8 +518,13 @@ const Parser = struct { |
| 518 | .@"enum" => return self.parseEnumLiteral(T, node), | 518 | .@"enum" => return self.parseEnumLiteral(T, node), |
| 519 | .pointer => |pointer| switch (pointer.size) { | 519 | .pointer => |pointer| switch (pointer.size) { |
| 520 | .one => { | 520 | .one => { |
| 521 | const result = try self.gpa.create(pointer.child); | 521 | const slice = try self.gpa.alignedAlloc( |
| 522 | errdefer self.gpa.destroy(result); | 522 | pointer.child, |
| | 523 | if (pointer.attrs.@"align") |a| .fromByteUnits(a) else null, |
| | 524 | 1, |
| | 525 | ); |
| | 526 | errdefer self.gpa.free(slice); |
| | 527 | const result = &slice[0]; |
| 523 | result.* = try self.parseExprInner(pointer.child, node); | 528 | result.* = try self.parseExprInner(pointer.child, node); |
| 524 | return result; | 529 | return result; |
| 525 | }, | 530 | }, |
| ... | @@ -3568,3 +3573,25 @@ test "std.zon errors without diagnostics" { | ... | @@ -3568,3 +3573,25 @@ test "std.zon errors without diagnostics" { |
| 3568 | try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".a", null, .{})); | 3573 | try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".a", null, .{})); |
| 3569 | try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".{ .b = 8 }", null, .{})); | 3574 | try std.testing.expectError(error.ParseZon, fromSliceAlloc(Union, gpa, ".{ .b = 8 }", null, .{})); |
| 3570 | } | 3575 | } |
| | 3576 | |
| | 3577 | test "std.zon aligned pointers" { |
| | 3578 | const gpa = std.testing.allocator; |
| | 3579 | |
| | 3580 | const n: u8 align(8) = 10; |
| | 3581 | const Foo = struct { |
| | 3582 | inner: *align(8) const u8, |
| | 3583 | }; |
| | 3584 | |
| | 3585 | const expected: Foo = .{ |
| | 3586 | .inner = &n, |
| | 3587 | }; |
| | 3588 | const found = try fromSliceAlloc( |
| | 3589 | Foo, |
| | 3590 | gpa, |
| | 3591 | ".{ .inner = 10 }", |
| | 3592 | null, |
| | 3593 | .{}, |
| | 3594 | ); |
| | 3595 | defer free(gpa, found); |
| | 3596 | try std.testing.expectEqualDeep(expected.inner, found.inner); |
| | 3597 | } |