authorgravatar for sinon@vortan.devDavid Rubin <sinon@vortan.dev> 2026-06-09 18:14:08-07:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-18 16:42:32+02:00
log6f4499c9dc069e8a6d6b6113fc918407f9d577cd
tree479a0502bc558a6a20abdf24cccf71acd0396979
parent2db133b53f80268e4e36ea43a58340bc7853bb61

Sema: copy alignment for try pointer expression


2 files changed, 16 insertions(+), 9 deletions(-)

src/Sema.zig+4-9
......@@ -17590,15 +17590,10 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1759017590 const is_cold = sema.branch_hint == .cold;
1759117591
1759217592 const operand_ty = sema.typeOf(operand);
17593 const ptr_info = operand_ty.ptrInfo(zcu);
17594 const res_ty = try pt.ptrType(.{
17595 .child = err_union_ty.errorUnionPayload(zcu).toIntern(),
17596 .flags = .{
17597 .is_const = ptr_info.flags.is_const,
17598 .is_volatile = ptr_info.flags.is_volatile,
17599 .is_allowzero = ptr_info.flags.is_allowzero,
17600 .address_space = ptr_info.flags.address_space,
17601 },
17593 const res_ty = try pt.ptrType(info: {
17594 var new = operand_ty.ptrInfo(zcu);
17595 new.child = err_union_ty.errorUnionPayload(zcu).toIntern();
17596 break :info new;
1760217597 });
1760317598 const res_ty_ref = Air.internedToRef(res_ty.toIntern());
1760417599 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.TryPtr).@"struct".field_names.len +
test/behavior/try.zig+12
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
3const assert = std.debug.assert;
34const expect = std.testing.expect;
45
56test "try on error union" {
......@@ -197,3 +198,14 @@ test "try ptr propagation mutate" {
197198 try S.doTheTest();
198199 try comptime S.doTheTest();
199200}
201
202test "try pointer expression alignment" {
203 const S = struct {
204 fn doTheTest(p: *align(1) (anyerror!u32)) !void {
205 comptime assert(@TypeOf(&(try p.*)) == *align(1) u32);
206 try expect((try p.*) == 10);
207 }
208 };
209 var x: anyerror!u32 = 10;
210 try S.doTheTest(&x);
211}