diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2022-08-10 19:13:29 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-10 19:13:29 -0400 |
| commit | e0178890ba5ad76fdf5ba955f479ccf6f05a3d49 (patch) | |
| tree | 97388d19f25afa268f68862225a3a1a478feb3f6 /src/Module.zig | |
| parent | 45c444ff18b43d30a7277e346174ba6eca4a6193 (diff) | |
| parent | 0d32b73078aa4579187f7d5c67343a6036eed277 (diff) | |
| download | zig-e0178890ba5ad76fdf5ba955f479ccf6f05a3d49.tar.gz zig-e0178890ba5ad76fdf5ba955f479ccf6f05a3d49.zip | |
Merge pull request #12379 from ifreund/packed-struct-explicit-backing-int
stage2: Implement explicit backing integers for packed structs
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/Module.zig b/src/Module.zig index 8b195eff2d..7e877a2f4a 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -895,6 +895,11 @@ pub const Struct = struct { zir_index: Zir.Inst.Index, layout: std.builtin.Type.ContainerLayout, + /// If the layout is not packed, this is the noreturn type. + /// If the layout is packed, this is the backing integer type of the packed struct. + /// Whether zig chooses this type or the user specifies it, it is stored here. + /// This will be set to the noreturn type until status is `have_layout`. + backing_int_ty: Type = Type.initTag(.noreturn), status: enum { none, field_types_wip, @@ -1025,7 +1030,7 @@ pub const Struct = struct { pub fn packedFieldBitOffset(s: Struct, target: Target, index: usize) u16 { assert(s.layout == .Packed); - assert(s.haveFieldTypes()); + assert(s.haveLayout()); var bit_sum: u64 = 0; for (s.fields.values()) |field, i| { if (i == index) { @@ -1033,19 +1038,7 @@ pub const Struct = struct { } bit_sum += field.ty.bitSize(target); } - return @intCast(u16, bit_sum); - } - - pub fn packedIntegerBits(s: Struct, target: Target) u16 { - return s.packedFieldBitOffset(target, s.fields.count()); - } - - pub fn packedIntegerType(s: Struct, target: Target, buf: *Type.Payload.Bits) Type { - buf.* = .{ - .base = .{ .tag = .int_unsigned }, - .data = s.packedIntegerBits(target), - }; - return Type.initPayload(&buf.base); + unreachable; // index out of bounds } }; |
