From 4ab7b459dfea45d1dbdfe301eeb840eaa796a4e7 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 6 May 2019 21:48:10 +0200 Subject: [PATCH] Avoid endless recursion in __extendhfsf2 On some platforms the conversion ended up creating a dangerous recursive loop that ate all the stack. The conversion to f16 is also pointless since we're operating on the raw bits anyway. --- std/special/compiler_rt/extendXfYf2.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/std/special/compiler_rt/extendXfYf2.zig b/std/special/compiler_rt/extendXfYf2.zig index 099e27b74a..953072b9e3 100644 --- a/std/special/compiler_rt/extendXfYf2.zig +++ b/std/special/compiler_rt/extendXfYf2.zig @@ -3,20 +3,20 @@ const builtin = @import("builtin"); const is_test = builtin.is_test; pub extern fn __extenddftf2(a: f64) f128 { - return extendXfYf2(f128, f64, a); + return extendXfYf2(f128, f64, @bitCast(u64, a)); } pub extern fn __extendsftf2(a: f32) f128 { - return extendXfYf2(f128, f32, a); + return extendXfYf2(f128, f32, @bitCast(u32, a)); } pub extern fn __extendhfsf2(a: u16) f32 { - return extendXfYf2(f32, f16, @bitCast(f16, a)); + return extendXfYf2(f32, f16, a); } const CHAR_BIT = 8; -inline fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t { +inline fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @typeInfo(src_t).Float.bits)) dst_t { const src_rep_t = @IntType(false, @typeInfo(src_t).Float.bits); const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits); const srcSigBits = std.math.floatMantissaBits(src_t);