motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 7a4dad7e87bd5561bbe62f5d38fda1b968f9d529 (tree)
parent 2d00f17d155b46e8effb47c363e051f50b866d47
Author: LemonBoy <thatlemon@gmail.com>
Date:   Thu, 15 Apr 2021 18:17:31 +0200

stage1: More precise serialization of f16 values

Taking a detour trough a f64 is dangerous as the softfloat library
doesn't like converting sNaN values.

The error went unnoticed as an exception is raised by the library but
the stage1 compiler doesn't give a damn.

Diffstat:
Msrc/stage1/codegen.cpp | 5++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp @@ -7436,7 +7436,10 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n case ZigTypeIdFloat: switch (type_entry->data.floating.bit_count) { case 16: - return LLVMConstReal(get_llvm_type(g, type_entry), zig_f16_to_double(const_val->data.x_f16)); + { + LLVMValueRef as_int = LLVMConstInt(LLVMInt16Type(), const_val->data.x_f16.v, false); + return LLVMConstBitCast(as_int, get_llvm_type(g, type_entry)); + } case 32: return LLVMConstReal(get_llvm_type(g, type_entry), const_val->data.x_f32); case 64: