forked from OSchip/llvm-project
[flang] Final fixes before review
Original-commit: flang-compiler/f18@efe5c1b8ec Reviewed-on: https://github.com/flang-compiler/f18/pull/472 Tree-same-pre-rewrite: false
This commit is contained in:
parent
f4b1209f4b
commit
d49aa3c57c
|
@ -525,7 +525,13 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldOperation(FoldingContext &context,
|
|||
} else if (name == "radix") {
|
||||
return Expr<T>{2};
|
||||
} else if (name == "range") {
|
||||
if (const auto *cx{UnwrapExpr<Expr<SomeReal>>(args[0])}) {
|
||||
if (const auto *cx{UnwrapExpr<Expr<SomeInteger>>(args[0])}) {
|
||||
return Expr<T>{std::visit(
|
||||
[](const auto &kx) {
|
||||
return Scalar<ResultType<decltype(kx)>>::RANGE;
|
||||
},
|
||||
cx->u)};
|
||||
} else if (const auto *cx{UnwrapExpr<Expr<SomeReal>>(args[0])}) {
|
||||
return Expr<T>{std::visit(
|
||||
[](const auto &kx) {
|
||||
return Scalar<ResultType<decltype(kx)>>::RANGE;
|
||||
|
|
|
@ -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<int>(((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) {
|
||||
|
|
|
@ -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},
|
||||
|
|
|
@ -227,7 +227,7 @@ public:
|
|||
using Result = std::optional<int>;
|
||||
using Types = IntegerTypes;
|
||||
template<typename T> Result Test() const {
|
||||
if (Scalar<T>::Precision >= precision_) {
|
||||
if (Scalar<T>::RANGE >= precision_) {
|
||||
return T::kind;
|
||||
} else {
|
||||
return std::nullopt;
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
#include <optional>
|
||||
#include <set>
|
||||
|
||||
#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 <iostream>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue