zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 6f4499c9dc069e8a6d6b6113fc918407f9d577cd (tree)
parent 2db133b53f80268e4e36ea43a58340bc7853bb61
Author: David Rubin <sinon@vortan.dev>
Date:   Tue,  9 Jun 2026 18:14:08 -0700

Sema: copy alignment for try pointer expression

Diffstat:
Msrc/Sema.zig | 13++++---------
Mtest/behavior/try.zig | 12++++++++++++
2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -17590,15 +17590,10 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr const is_cold = sema.branch_hint == .cold; const operand_ty = sema.typeOf(operand); - const ptr_info = operand_ty.ptrInfo(zcu); - const res_ty = try pt.ptrType(.{ - .child = err_union_ty.errorUnionPayload(zcu).toIntern(), - .flags = .{ - .is_const = ptr_info.flags.is_const, - .is_volatile = ptr_info.flags.is_volatile, - .is_allowzero = ptr_info.flags.is_allowzero, - .address_space = ptr_info.flags.address_space, - }, + const res_ty = try pt.ptrType(info: { + var new = operand_ty.ptrInfo(zcu); + new.child = err_union_ty.errorUnionPayload(zcu).toIntern(); + break :info new; }); const res_ty_ref = Air.internedToRef(res_ty.toIntern()); try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.TryPtr).@"struct".field_names.len + diff --git a/test/behavior/try.zig b/test/behavior/try.zig @@ -1,5 +1,6 @@ const std = @import("std"); const builtin = @import("builtin"); +const assert = std.debug.assert; const expect = std.testing.expect; test "try on error union" { @@ -197,3 +198,14 @@ test "try ptr propagation mutate" { try S.doTheTest(); try comptime S.doTheTest(); } + +test "try pointer expression alignment" { + const S = struct { + fn doTheTest(p: *align(1) (anyerror!u32)) !void { + comptime assert(@TypeOf(&(try p.*)) == *align(1) u32); + try expect((try p.*) == 10); + } + }; + var x: anyerror!u32 = 10; + try S.doTheTest(&x); +}