From d49aa3c57cd05b5cb603734bf78fa15c8280beb5 Mon Sep 17 00:00:00 2001 From: peter klausler Date: Wed, 29 May 2019 16:00:31 -0700 Subject: [PATCH] [flang] Final fixes before review Original-commit: flang-compiler/f18@efe5c1b8ec60f7c3d2a083da12924bc4523e6f72 Reviewed-on: https://github.com/flang-compiler/f18/pull/472 Tree-same-pre-rewrite: false --- flang/lib/evaluate/fold.cc | 8 +++++++- flang/lib/evaluate/integer.h | 16 +--------------- flang/lib/evaluate/intrinsics.cc | 4 ++-- flang/lib/evaluate/type.cc | 2 +- flang/lib/semantics/expression.cc | 4 ++-- flang/test/semantics/modfile26.f90 | 7 ++++++- 6 files changed, 19 insertions(+), 22 deletions(-) diff --git a/flang/lib/evaluate/fold.cc b/flang/lib/evaluate/fold.cc index a99583ba2980..a263e52f9f44 100644 --- a/flang/lib/evaluate/fold.cc +++ b/flang/lib/evaluate/fold.cc @@ -525,7 +525,13 @@ Expr> FoldOperation(FoldingContext &context, } else if (name == "radix") { return Expr{2}; } else if (name == "range") { - if (const auto *cx{UnwrapExpr>(args[0])}) { + if (const auto *cx{UnwrapExpr>(args[0])}) { + return Expr{std::visit( + [](const auto &kx) { + return Scalar>::RANGE; + }, + cx->u)}; + } else if (const auto *cx{UnwrapExpr>(args[0])}) { return Expr{std::visit( [](const auto &kx) { return Scalar>::RANGE; diff --git a/flang/lib/evaluate/integer.h b/flang/lib/evaluate/integer.h index d8b9b81db1bd..18db5731b6a3 100644 --- a/flang/lib/evaluate/integer.h +++ b/flang/lib/evaluate/integer.h @@ -350,24 +350,10 @@ public: static constexpr Integer BIT_SIZE() { return {bits}; } static constexpr Integer HUGE() { return MASKR(bits - 1); } - static constexpr int Precision{// in the sense of SELECTED_INT_KIND + static constexpr int RANGE{// in the sense of SELECTED_INT_KIND // This magic value is LOG10(2.)*1E12. static_cast(((bits - 1) * 301029995664) / 1000000000000)}; - // Returns the number of full decimal digits that can be represented. - static constexpr int RANGE() { - if (bits < 4) { - return 0; - } - Integer x{HUGE()}, ten{10}; - int digits{0}; - while (x.CompareUnsigned(ten) != Ordering::Less) { - ++digits; - x = x.DivideUnsigned(ten).quotient; - } - return digits; - } - constexpr bool IsZero() const { for (int j{0}; j < parts; ++j) { if (part_[j] != 0) { diff --git a/flang/lib/evaluate/intrinsics.cc b/flang/lib/evaluate/intrinsics.cc index 9bb95f24d00b..fc4dce7afc52 100644 --- a/flang/lib/evaluate/intrinsics.cc +++ b/flang/lib/evaluate/intrinsics.cc @@ -510,8 +510,8 @@ static const IntrinsicInterface genericIntrinsicFunction[]{ SameNumeric, Rank::dimReduced}, {"precision", {{"x", AnyFloating, Rank::anyOrAssumedRank}}, DefaultInt}, {"present", {{"a", Anything, Rank::anyOrAssumedRank}}, DefaultLogical}, - {"radix", {{"x", AnyFloating, Rank::anyOrAssumedRank}}, DefaultInt}, - {"range", {{"x", AnyFloating, Rank::anyOrAssumedRank}}, DefaultInt}, + {"radix", {{"x", AnyNumeric, Rank::anyOrAssumedRank}}, DefaultInt}, + {"range", {{"x", AnyNumeric, Rank::anyOrAssumedRank}}, DefaultInt}, {"rank", {{"a", Anything, Rank::anyOrAssumedRank}}, DefaultInt}, {"real", {{"a", AnyNumeric, Rank::elementalOrBOZ}, DefaultingKIND}, KINDReal}, diff --git a/flang/lib/evaluate/type.cc b/flang/lib/evaluate/type.cc index fdb765ae794b..ca40cfbc1b63 100644 --- a/flang/lib/evaluate/type.cc +++ b/flang/lib/evaluate/type.cc @@ -227,7 +227,7 @@ public: using Result = std::optional; using Types = IntegerTypes; template Result Test() const { - if (Scalar::Precision >= precision_) { + if (Scalar::RANGE >= precision_) { return T::kind; } else { return std::nullopt; diff --git a/flang/lib/semantics/expression.cc b/flang/lib/semantics/expression.cc index 480c62784171..90bfd7099d19 100644 --- a/flang/lib/semantics/expression.cc +++ b/flang/lib/semantics/expression.cc @@ -30,8 +30,8 @@ #include #include -#define DUMP_ON_FAILURE 1 // pmk -// #define CRASH_ON_FAILURE +// #define DUMP_ON_FAILURE 1 +// #define CRASH_ON_FAILURE 1 #if DUMP_ON_FAILURE #include "../parser/dump-parse-tree.h" #include diff --git a/flang/test/semantics/modfile26.f90 b/flang/test/semantics/modfile26.f90 index 23998a55f40b..9ea80020c71d 100644 --- a/flang/test/semantics/modfile26.f90 +++ b/flang/test/semantics/modfile26.f90 @@ -19,7 +19,10 @@ module m1 ! INTEGER(KIND=2) handles 3 <= P < 5 ! INTEGER(KIND=4) handles 5 <= P < 10 ! INTEGER(KIND=8) handles 10 <= P < 19 - ! INTEGER(KIND=16) handles 19 <= P < 38 + ! INTEGER(KIND=16) handles 19 <= P < 39 + integer, parameter :: iranges(:) = & + [range(0_1), range(0_2), range(0_4), range(0_8), range(0_16)] + logical, parameter :: ircheck = all([2, 4, 9, 18, 38] == iranges) integer, parameter :: intpvals(:) = [0, 2, 3, 4, 5, 9, 10, 18, 19, 38, 39] integer, parameter :: intpkinds(:) = & [(selected_int_kind(intpvals(j)),j=1,size(intpvals))] @@ -64,6 +67,8 @@ module m1 end module m1 !Expect: m1.mod !module m1 +!integer(4),parameter::iranges(1_8:)=[Integer(4)::2_4,4_4,9_4,18_4,38_4] +!logical(4),parameter::ircheck=.true._4 !integer(4),parameter::intpvals(1_8:)=[Integer(4)::0_4,2_4,3_4,4_4,5_4,9_4,10_4,18_4,19_4,38_4,39_4] !integer(4),parameter::intpkinds(1_8:)=[Integer(4)::1_4,1_4,2_4,2_4,4_4,4_4,8_4,8_4,16_4,16_4,-1_4] !logical(4),parameter::ipcheck=.true._4