diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-09-11 21:48:52 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-09-12 18:13:24 -0700 |
| commit | 188902a710a64b08762d7731aab81cb695322184 (patch) | |
| tree | 177ba4a0edb07fe1751a749f8cc30d7f533e29f6 /src/type.zig | |
| parent | f16855b9d70c747423ee81f27d619694856d365b (diff) | |
| download | zig-188902a710a64b08762d7731aab81cb695322184.tar.gz zig-188902a710a64b08762d7731aab81cb695322184.zip | |
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.
Diffstat (limited to 'src/type.zig')
| -rw-r--r-- | src/type.zig | 25 |
1 files changed, 18 insertions, 7 deletions
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, } |
