[flang] Real->Integer conversion folding

Original-commit: flang-compiler/f18@5ad6505e78
Reviewed-on: https://github.com/flang-compiler/f18/pull/144
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2018-07-20 13:52:52 -07:00
parent 61c45394c0
commit 943b50289b
2 changed files with 24 additions and 3 deletions

View File

@ -241,6 +241,29 @@ auto IntegerExpr<KIND>::ConvertInteger::FoldScalar(FoldingContext &context,
c.u);
}
template<int KIND>
auto IntegerExpr<KIND>::ConvertReal::FoldScalar(FoldingContext &context,
const CategoryScalar<Category::Real> &c) -> std::optional<Scalar> {
return std::visit(
[&](auto &x) -> std::optional<Scalar> {
auto converted{x.template ToInteger<Scalar>()};
if (context.messages != nullptr) {
if (converted.flags.test(RealFlag::Overflow)) {
context.messages->Say(
context.at, "real->integer conversion overflowed"_en_US);
return {};
}
if (converted.flags.test(RealFlag::InvalidArgument)) {
context.messages->Say(
context.at, "real->integer conversion: invalid argument"_en_US);
return {};
}
}
return {std::move(converted.value)};
},
c.u);
}
template<int KIND>
auto IntegerExpr<KIND>::Negate::FoldScalar(
FoldingContext &context, const Scalar &c) -> std::optional<Scalar> {

View File

@ -152,9 +152,7 @@ public:
using Unary<ConvertReal, Result, GenericRealExpr,
CategoryScalar<Category::Real>>::Unary;
static std::optional<Scalar> FoldScalar(
FoldingContext &, const CategoryScalar<Category::Real> &) {
return {};
} // TODO
FoldingContext &, const CategoryScalar<Category::Real> &);
};
template<typename CRTP> using Un = Unary<CRTP, Result, Expr>;