summaryrefslogtreecommitdiff
path: root/flang/lib/Evaluate/fold-real.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'flang/lib/Evaluate/fold-real.cpp')
-rw-r--r--flang/lib/Evaluate/fold-real.cpp129
1 files changed, 43 insertions, 86 deletions
diff --git a/flang/lib/Evaluate/fold-real.cpp b/flang/lib/Evaluate/fold-real.cpp
index 6fb5249c8a5e..225e3402fd1a 100644
--- a/flang/lib/Evaluate/fold-real.cpp
+++ b/flang/lib/Evaluate/fold-real.cpp
@@ -35,9 +35,8 @@ static Expr<T> FoldTransformationalBessel(
}
return Expr<T>{Constant<T>{
std::move(results), ConstantSubscripts{std::max(n2 - n1 + 1, 0)}}};
- } else if (context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingFailure)) {
- context.messages().Say(common::UsageWarning::FoldingFailure,
+ } else {
+ context.Warn(common::UsageWarning::FoldingFailure,
"%s(integer(kind=4), real(kind=%d)) cannot be folded on host"_warn_en_US,
name, T::kind);
}
@@ -131,10 +130,8 @@ static Expr<Type<TypeCategory::Real, KIND>> FoldNorm2(FoldingContext &context,
context.targetCharacteristics().roundingMode()};
Constant<T> result{DoReduction<T>(arrayAndMask->array, arrayAndMask->mask,
dim, identity, norm2Accumulator)};
- if (norm2Accumulator.overflow() &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingException)) {
- context.messages().Say(common::UsageWarning::FoldingException,
+ if (norm2Accumulator.overflow()) {
+ context.Warn(common::UsageWarning::FoldingException,
"NORM2() of REAL(%d) data overflowed"_warn_en_US, KIND);
}
return Expr<T>{std::move(result)};
@@ -165,9 +162,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
if (auto callable{GetHostRuntimeWrapper<T, T>(name)}) {
return FoldElementalIntrinsic<T, T>(
context, std::move(funcRef), *callable);
- } else if (context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingFailure)) {
- context.messages().Say(common::UsageWarning::FoldingFailure,
+ } else {
+ context.Warn(common::UsageWarning::FoldingFailure,
"%s(real(kind=%d)) cannot be folded on host"_warn_en_US, name, KIND);
}
} else if (name == "amax0" || name == "amin0" || name == "amin1" ||
@@ -179,9 +175,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
if (auto callable{GetHostRuntimeWrapper<T, T, T>(localName)}) {
return FoldElementalIntrinsic<T, T, T>(
context, std::move(funcRef), *callable);
- } else if (context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingFailure)) {
- context.messages().Say(common::UsageWarning::FoldingFailure,
+ } else {
+ context.Warn(common::UsageWarning::FoldingFailure,
"%s(real(kind=%d), real(kind%d)) cannot be folded on host"_warn_en_US,
name, KIND, KIND);
}
@@ -191,9 +186,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
if (auto callable{GetHostRuntimeWrapper<T, Int4, T>(name)}) {
return FoldElementalIntrinsic<T, Int4, T>(
context, std::move(funcRef), *callable);
- } else if (context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingFailure)) {
- context.messages().Say(common::UsageWarning::FoldingFailure,
+ } else {
+ context.Warn(common::UsageWarning::FoldingFailure,
"%s(integer(kind=4), real(kind=%d)) cannot be folded on host"_warn_en_US,
name, KIND);
}
@@ -210,10 +204,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
ScalarFunc<T, ComplexT>([&name, &context](
const Scalar<ComplexT> &z) -> Scalar<T> {
ValueWithRealFlags<Scalar<T>> y{z.ABS()};
- if (y.flags.test(RealFlag::Overflow) &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingException)) {
- context.messages().Say(common::UsageWarning::FoldingException,
+ if (y.flags.test(RealFlag::Overflow)) {
+ context.Warn(common::UsageWarning::FoldingException,
"complex ABS intrinsic folding overflow"_warn_en_US, name);
}
return y.value;
@@ -234,10 +226,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
ScalarFunc<T, T>(
[&name, &context, mode](const Scalar<T> &x) -> Scalar<T> {
ValueWithRealFlags<Scalar<T>> y{x.ToWholeNumber(mode)};
- if (y.flags.test(RealFlag::Overflow) &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingException)) {
- context.messages().Say(common::UsageWarning::FoldingException,
+ if (y.flags.test(RealFlag::Overflow)) {
+ context.Warn(common::UsageWarning::FoldingException,
"%s intrinsic folding overflow"_warn_en_US, name);
}
return y.value;
@@ -247,10 +237,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
ScalarFunc<T, T, T>([&context](const Scalar<T> &x,
const Scalar<T> &y) -> Scalar<T> {
ValueWithRealFlags<Scalar<T>> result{x.DIM(y)};
- if (result.flags.test(RealFlag::Overflow) &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingException)) {
- context.messages().Say(common::UsageWarning::FoldingException,
+ if (result.flags.test(RealFlag::Overflow)) {
+ context.Warn(common::UsageWarning::FoldingException,
"DIM intrinsic folding overflow"_warn_en_US);
}
return result.value;
@@ -282,10 +270,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
ScalarFunc<T, T, T>(
[&](const Scalar<T> &x, const Scalar<T> &y) -> Scalar<T> {
ValueWithRealFlags<Scalar<T>> result{x.HYPOT(y)};
- if (result.flags.test(RealFlag::Overflow) &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingException)) {
- context.messages().Say(common::UsageWarning::FoldingException,
+ if (result.flags.test(RealFlag::Overflow)) {
+ context.Warn(common::UsageWarning::FoldingException,
"HYPOT intrinsic folding overflow"_warn_en_US);
}
return result.value;
@@ -307,11 +293,9 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
bool badPConst{false};
if (auto *pExpr{UnwrapExpr<Expr<T>>(args[1])}) {
*pExpr = Fold(context, std::move(*pExpr));
- if (auto pConst{GetScalarConstantValue<T>(*pExpr)}; pConst &&
- pConst->IsZero() &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingAvoidsRuntimeCrash)) {
- context.messages().Say(common::UsageWarning::FoldingAvoidsRuntimeCrash,
+ if (auto pConst{GetScalarConstantValue<T>(*pExpr)};
+ pConst && pConst->IsZero()) {
+ context.Warn(common::UsageWarning::FoldingAvoidsRuntimeCrash,
"MOD: P argument is zero"_warn_en_US);
badPConst = true;
}
@@ -320,11 +304,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
ScalarFunc<T, T, T>([&context, badPConst](const Scalar<T> &x,
const Scalar<T> &y) -> Scalar<T> {
auto result{x.MOD(y)};
- if (!badPConst && result.flags.test(RealFlag::DivideByZero) &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingAvoidsRuntimeCrash)) {
- context.messages().Say(
- common::UsageWarning::FoldingAvoidsRuntimeCrash,
+ if (!badPConst && result.flags.test(RealFlag::DivideByZero)) {
+ context.Warn(common::UsageWarning::FoldingAvoidsRuntimeCrash,
"second argument to MOD must not be zero"_warn_en_US);
}
return result.value;
@@ -334,11 +315,9 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
bool badPConst{false};
if (auto *pExpr{UnwrapExpr<Expr<T>>(args[1])}) {
*pExpr = Fold(context, std::move(*pExpr));
- if (auto pConst{GetScalarConstantValue<T>(*pExpr)}; pConst &&
- pConst->IsZero() &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingAvoidsRuntimeCrash)) {
- context.messages().Say(common::UsageWarning::FoldingAvoidsRuntimeCrash,
+ if (auto pConst{GetScalarConstantValue<T>(*pExpr)};
+ pConst && pConst->IsZero()) {
+ context.Warn(common::UsageWarning::FoldingAvoidsRuntimeCrash,
"MODULO: P argument is zero"_warn_en_US);
badPConst = true;
}
@@ -347,11 +326,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
ScalarFunc<T, T, T>([&context, badPConst](const Scalar<T> &x,
const Scalar<T> &y) -> Scalar<T> {
auto result{x.MODULO(y)};
- if (!badPConst && result.flags.test(RealFlag::DivideByZero) &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingAvoidsRuntimeCrash)) {
- context.messages().Say(
- common::UsageWarning::FoldingAvoidsRuntimeCrash,
+ if (!badPConst && result.flags.test(RealFlag::DivideByZero)) {
+ context.Warn(common::UsageWarning::FoldingAvoidsRuntimeCrash,
"second argument to MODULO must not be zero"_warn_en_US);
}
return result.value;
@@ -363,11 +339,9 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
[&](const auto &sVal) {
using TS = ResultType<decltype(sVal)>;
bool badSConst{false};
- if (auto sConst{GetScalarConstantValue<TS>(sVal)}; sConst &&
- (sConst->IsZero() || sConst->IsNotANumber()) &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingValueChecks)) {
- context.messages().Say(common::UsageWarning::FoldingValueChecks,
+ if (auto sConst{GetScalarConstantValue<TS>(sVal)};
+ sConst && (sConst->IsZero() || sConst->IsNotANumber())) {
+ context.Warn(common::UsageWarning::FoldingValueChecks,
"NEAREST: S argument is %s"_warn_en_US,
sConst->IsZero() ? "zero" : "NaN");
badSConst = true;
@@ -375,22 +349,15 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
return FoldElementalIntrinsic<T, T, TS>(context, std::move(funcRef),
ScalarFunc<T, T, TS>([&](const Scalar<T> &x,
const Scalar<TS> &s) -> Scalar<T> {
- if (!badSConst && (s.IsZero() || s.IsNotANumber()) &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingValueChecks)) {
- context.messages().Say(
- common::UsageWarning::FoldingValueChecks,
+ if (!badSConst && (s.IsZero() || s.IsNotANumber())) {
+ context.Warn(common::UsageWarning::FoldingValueChecks,
"NEAREST: S argument is %s"_warn_en_US,
s.IsZero() ? "zero" : "NaN");
}
auto result{x.NEAREST(!s.IsNegative())};
- if (context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingException)) {
- if (result.flags.test(RealFlag::InvalidArgument)) {
- context.messages().Say(
- common::UsageWarning::FoldingException,
- "NEAREST intrinsic folding: bad argument"_warn_en_US);
- }
+ if (result.flags.test(RealFlag::InvalidArgument)) {
+ context.Warn(common::UsageWarning::FoldingException,
+ "NEAREST intrinsic folding: bad argument"_warn_en_US);
}
return result.value;
}));
@@ -427,11 +394,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
template
#endif
SCALE<Scalar<TBY>>(y)};
- if (result.flags.test(RealFlag::Overflow) &&
- context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingException)) {
- context.messages().Say(
- common::UsageWarning::FoldingException,
+ if (result.flags.test(RealFlag::Overflow)) {
+ context.Warn(common::UsageWarning::FoldingException,
"SCALE/IEEE_SCALB intrinsic folding overflow"_warn_en_US);
}
return result.value;
@@ -481,12 +445,8 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
auto yBig{Scalar<LargestReal>::Convert(y).value};
switch (xBig.Compare(yBig)) {
case Relation::Unordered:
- if (context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingValueChecks)) {
- context.messages().Say(
- common::UsageWarning::FoldingValueChecks,
- "IEEE_NEXT_AFTER intrinsic folding: arguments are unordered"_warn_en_US);
- }
+ context.Warn(common::UsageWarning::FoldingValueChecks,
+ "IEEE_NEXT_AFTER intrinsic folding: arguments are unordered"_warn_en_US);
return x.NotANumber();
case Relation::Equal:
break;
@@ -507,12 +467,9 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
return FoldElementalIntrinsic<T, T>(context, std::move(funcRef),
ScalarFunc<T, T>([&](const Scalar<T> &x) -> Scalar<T> {
auto result{x.NEAREST(upward)};
- if (context.languageFeatures().ShouldWarn(
- common::UsageWarning::FoldingException)) {
- if (result.flags.test(RealFlag::InvalidArgument)) {
- context.messages().Say(common::UsageWarning::FoldingException,
- "%s intrinsic folding: argument is NaN"_warn_en_US, iName);
- }
+ if (result.flags.test(RealFlag::InvalidArgument)) {
+ context.Warn(common::UsageWarning::FoldingException,
+ "%s intrinsic folding: argument is NaN"_warn_en_US, iName);
}
return result.value;
}));