aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-07-13 13:14:37 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-07-13 13:14:37 -0700
commit92bc3cbe27792be0300fb5f104c011a11f3cf40f (patch)
tree8d9e7f2df29a824d104cfa01d2eb832d456554aa /src/type.zig
parent35e70111248f795fbdcefd5ae0d6fc494d1b0683 (diff)
downloadzig-92bc3cbe27792be0300fb5f104c011a11f3cf40f.tar.gz
zig-92bc3cbe27792be0300fb5f104c011a11f3cf40f.zip
stage2: fix comptime bitcast involving f80
* Sema: implement comptime bitcast of f80 with integer-like types bitwise rather than taking a round trip through memory layout. * Type: introduce `isAbiInt`. * Value: comptime memory write of f80 writes 0 bytes for padding instead of leaving the memory uninitialized. * Value: floatReadFromMemory has a more general implementation, checking the endianness rather than checking for specific architectures. This fixes behavior test failures occurring on MIPS.
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index 765f1da18c..0744a50579 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -4439,6 +4439,16 @@ pub const Type = extern union {
};
}
+ /// Returns true for integers, enums, error sets, and packed structs.
+ /// If this function returns true, then intInfo() can be called on the type.
+ pub fn isAbiInt(ty: Type) bool {
+ return switch (ty.zigTypeTag()) {
+ .Int, .Enum, .ErrorSet => true,
+ .Struct => ty.containerLayout() == .Packed,
+ else => false,
+ };
+ }
+
/// Asserts the type is an integer, enum, error set, or vector of one of them.
pub fn intInfo(self: Type, target: Target) struct { signedness: std.builtin.Signedness, bits: u16 } {
var ty = self;