From: peter klausler Date: Fri, 23 Aug 2019 18:14:48 +0000 (-0700) Subject: [flang] Make it easier to enable minimal FP output by default for module files (but... X-Git-Tag: llvmorg-12-init~9537^2~702 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9717cc43b82b68cb20cdee8a69741788ce46d493;p=platform%2Fupstream%2Fllvm.git [flang] Make it easier to enable minimal FP output by default for module files (but do not enable it) Original-commit: flang-compiler/f18@f6b640319b33008375ca719a88fd0580bcf90bba Reviewed-on: https://github.com/flang-compiler/f18/pull/671 --- diff --git a/flang/lib/evaluate/real.cc b/flang/lib/evaluate/real.cc index fafe94d..0853c6c 100644 --- a/flang/lib/evaluate/real.cc +++ b/flang/lib/evaluate/real.cc @@ -459,7 +459,8 @@ std::string Real::DumpHexadecimal() const { } template -std::ostream &Real::AsFortran(std::ostream &o, int kind) const { +std::ostream &Real::AsFortran( + std::ostream &o, int kind, bool minimal) const { if (IsNotANumber()) { o << "(0._" << kind << "/0.)"; } else if (IsInfinite()) { @@ -476,8 +477,11 @@ std::ostream &Real::AsFortran(std::ostream &o, int kind) const { using B = decimal::BinaryFloatingPointNumber

; const auto *value{reinterpret_cast(this)}; char buffer[24000]; // accommodate real*16 - auto result{decimal::ConvertToDecimal

(buffer, sizeof buffer, - static_cast(0), + decimal::DecimalConversionFlags flags{}; // default: exact representation + if (minimal) { + flags = decimal::Minimize; + } + auto result{decimal::ConvertToDecimal

(buffer, sizeof buffer, flags, static_cast(sizeof buffer), decimal::RoundNearest, *value)}; const char *p{result.str}; if (DEREF(p) == '-' || *p == '+') { diff --git a/flang/lib/evaluate/real.h b/flang/lib/evaluate/real.h index edaee19..abb844b 100644 --- a/flang/lib/evaluate/real.h +++ b/flang/lib/evaluate/real.h @@ -362,7 +362,7 @@ public: // Emits a character representation for an equivalent Fortran constant // or parenthesized constant expression that produces this value. - std::ostream &AsFortran(std::ostream &, int kind) const; + std::ostream &AsFortran(std::ostream &, int kind, bool minimal = false) const; private: using Significand = Integer; // no implicit bit diff --git a/flang/test/evaluate/real.cc b/flang/test/evaluate/real.cc index 2a8ab67..882e2cb 100644 --- a/flang/test/evaluate/real.cc +++ b/flang/test/evaluate/real.cc @@ -164,7 +164,7 @@ template void basicTests(int rm, Rounding rounding) { MATCH(x, ivf.value.ToUInt64())(ldesc); if (rounding.mode == RoundingMode::TiesToEven) { // to match stold() std::stringstream ss; - vr.value.AsFortran(ss, kind); + vr.value.AsFortran(ss, kind, false /*exact*/); std::string decimal{ss.str()}; const char *p{decimal.data()}; MATCH(x, static_cast(std::stold(decimal))) @@ -411,7 +411,7 @@ void subsetTests(int pass, Rounding rounding, std::uint32_t opds) { static constexpr int kind{REAL::bits / 8}; std::stringstream ss, css; - x.AsFortran(ss, kind); + x.AsFortran(ss, kind, false /*exact*/); std::string s{ss.str()}; if (IsNaN(rj)) { css << "(0._" << kind << "/0.)";