From cdf792b016475eef68c5b2805141d6977e8f542f Mon Sep 17 00:00:00 2001 From: Nuno Lopes Date: Wed, 29 Nov 2023 01:45:32 +0000 Subject: [PATCH] fix #980: UB executed with uitofp --- ir/type.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ir/type.cpp b/ir/type.cpp index 860bc3418..1ded46b26 100644 --- a/ir/type.cpp +++ b/ir/type.cpp @@ -446,24 +446,24 @@ expr FloatType::fromFloat(State &s, const expr &fp, const Type &from_type0, // 2) input NaN // 3) quieted input NaN - const FloatType &from_type = *from_type0.getAsFloatType(); + const FloatType *from_type = from_type0.getAsFloatType(); auto add_maybe_quiet = [&](const expr &e) { // account for fpext/fptruc - expr fraction = e.trunc(min(from_type.fractionBits(), fraction_bits)); + expr fraction = e.trunc(min(from_type->fractionBits(), fraction_bits)); if (fraction.bits() < fraction_bits) fraction = fraction.concat_zeros(fraction_bits - fraction.bits()); assert(!fraction.isValid() || fraction.bits() == fraction_bits); expr truncated_is_nan = true; - if (from_type.fractionBits() > fraction_bits) + if (from_type->fractionBits() > fraction_bits) truncated_is_nan = fraction != 0; expr qnan = fraction.extract(fraction_bits - 1, fraction_bits - 1); expr quieted = var.extract(0, 0); qnan = expr::mkIf(truncated_is_nan, qnan | quieted, expr::mkUInt(1, 1)); exprs.add(qnan.concat(fraction.trunc(fraction_bits - 1)), - from_type.getFloat(e).isNaN()); + from_type->getFloat(e).isNaN()); }; if (nary >= 1) { add_maybe_quiet(a);