forked from OSchip/llvm-project
[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:
parent
61c45394c0
commit
943b50289b
|
@ -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> {
|
||||
|
|
|
@ -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>;
|
||||
|
|
Loading…
Reference in New Issue