From 6fde2fcd519cacdc44871fc1035b05afee072f44 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 8 May 2022 13:05:16 -0700 Subject: allow in-memory coercion of differently-named floats with same bits For example, this allows passing a `*c_longdouble` where a `*f80` is expected, provided that `c_longdouble` maps to `f80` for this target. --- src/Sema.zig | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/Sema.zig') diff --git a/src/Sema.zig b/src/Sema.zig index 76edfbf2cd..2e7e5c9293 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -18673,6 +18673,15 @@ fn coerceInMemoryAllowed( } } + // Differently-named floats with the same number of bits. + if (dest_ty.zigTypeTag() == .Float and src_ty.zigTypeTag() == .Float) { + const dest_bits = dest_ty.floatBits(target); + const src_bits = src_ty.floatBits(target); + if (dest_bits == src_bits) { + return .ok; + } + } + // Pointers / Pointer-like Optionals var dest_buf: Type.Payload.ElemType = undefined; var src_buf: Type.Payload.ElemType = undefined; -- cgit v1.2.3