From 188902a710a64b08762d7731aab81cb695322184 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 11 Sep 2022 21:48:52 -0700 Subject: Sema: introduce Type.ptrAlignmentAdvanced I'm not sure why the other commits in this branch caused this fix to be necessary. Also, there seems to be more fixes necessary before tests will pass. --- src/type.zig | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'src/type.zig') diff --git a/src/type.zig b/src/type.zig index ec7e155d4e..c72cf2be84 100644 --- a/src/type.zig +++ b/src/type.zig @@ -2715,8 +2715,12 @@ pub const Type = extern union { } /// Returns 0 if the pointer is naturally aligned and the element type is 0-bit. - pub fn ptrAlignment(self: Type, target: Target) u32 { - switch (self.tag()) { + pub fn ptrAlignment(ty: Type, target: Target) u32 { + return ptrAlignmentAdvanced(ty, target, null) catch unreachable; + } + + pub fn ptrAlignmentAdvanced(ty: Type, target: Target, sema_kit: ?Module.WipAnalysis) !u32 { + switch (ty.tag()) { .single_const_pointer, .single_mut_pointer, .many_const_pointer, @@ -2728,8 +2732,12 @@ pub const Type = extern union { .optional_single_const_pointer, .optional_single_mut_pointer, => { - const child_type = self.cast(Payload.ElemType).?.data; - return child_type.abiAlignment(target); + const child_type = ty.cast(Payload.ElemType).?.data; + if (sema_kit) |sk| { + const res = try child_type.abiAlignmentAdvanced(target, .{ .sema_kit = sk }); + return res.scalar; + } + return (child_type.abiAlignmentAdvanced(target, .eager) catch unreachable).scalar; }, .manyptr_u8, @@ -2740,14 +2748,17 @@ pub const Type = extern union { => return 1, .pointer => { - const ptr_info = self.castTag(.pointer).?.data; + const ptr_info = ty.castTag(.pointer).?.data; if (ptr_info.@"align" != 0) { return ptr_info.@"align"; + } else if (sema_kit) |sk| { + const res = try ptr_info.pointee_type.abiAlignmentAdvanced(target, .{ .sema_kit = sk }); + return res.scalar; } else { - return ptr_info.pointee_type.abiAlignment(target); + return (ptr_info.pointee_type.abiAlignmentAdvanced(target, .eager) catch unreachable).scalar; } }, - .optional => return self.castTag(.optional).?.data.ptrAlignment(target), + .optional => return ty.castTag(.optional).?.data.ptrAlignmentAdvanced(target, sema_kit), else => unreachable, } -- cgit v1.2.3