| author | |
| committer | |
| log | 6f4499c9dc069e8a6d6b6113fc918407f9d577cd |
| tree | 479a0502bc558a6a20abdf24cccf71acd0396979 |
| parent | 2db133b53f80268e4e36ea43a58340bc7853bb61 |
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 |
| 17590 | 17590 | const is_cold = sema.branch_hint == .cold; |
| 17591 | 17591 | |
| 17592 | 17592 | 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; | |
| 17602 | 17597 | }); |
| 17603 | 17598 | const res_ty_ref = Air.internedToRef(res_ty.toIntern()); |
| 17604 | 17599 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.TryPtr).@"struct".field_names.len + |
test/behavior/try.zig+12| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | 1 | const std = @import("std"); |
| 2 | 2 | const builtin = @import("builtin"); |
| 3 | const assert = std.debug.assert; | |
| 3 | 4 | const expect = std.testing.expect; |
| 4 | 5 | |
| 5 | 6 | test "try on error union" { |
| ... | ... | @@ -197,3 +198,14 @@ test "try ptr propagation mutate" { |
| 197 | 198 | try S.doTheTest(); |
| 198 | 199 | try comptime S.doTheTest(); |
| 199 | 200 | } |
| 201 | ||
| 202 | test "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 | } |