From 92bc3cbe27792be0300fb5f104c011a11f3cf40f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 13 Jul 2022 13:14:37 -0700 Subject: 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. --- src/type.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/type.zig') 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; -- cgit v1.2.3