diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-09-13 13:50:25 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2022-09-13 13:50:25 -0700 |
| commit | 0a4cfb81bcca0ca514758049f8d7d99224537f93 (patch) | |
| tree | 1acc4e8c41a4c0f2a1c80f4864f23a5b16a374eb /src/type.zig | |
| parent | f9859c102d7d54ce109ee7afdbd59251c233e92c (diff) | |
| parent | c25ce5bba0d00283ad4de9077dba5a8d5255b619 (diff) | |
| download | zig-0a4cfb81bcca0ca514758049f8d7d99224537f93.tar.gz zig-0a4cfb81bcca0ca514758049f8d7d99224537f93.zip | |
Merge remote-tracking branch 'origin/master' into llvm15
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 5de0611667..3e2e395d07 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, } |
