[flang-commits] [PATCH] D135203: [flang] Don't force SET_EXPONENT(I=...) argument to integer(4)
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Oct 4 14:54:35 PDT 2022
klausler created this revision.
klausler added a reviewer: jeanPerier.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
The implementation of the folding code for SET_EXPONENT() was written
in such a fashion as to convert the I= actual argument value to a 32-bit
integer. Which is usually not a problem, but it's not always correct
and a test case ran into trouble with it. Fix to allow any kind of
INTEGER without conversion.
https://reviews.llvm.org/D135203
Files:
flang/lib/Evaluate/fold-real.cpp
Index: flang/lib/Evaluate/fold-real.cpp
===================================================================
--- flang/lib/Evaluate/fold-real.cpp
+++ flang/lib/Evaluate/fold-real.cpp
@@ -257,11 +257,18 @@
byExpr->u);
}
} else if (name == "set_exponent") {
- return FoldElementalIntrinsic<T, T, Int4>(context, std::move(funcRef),
- ScalarFunc<T, T, Int4>(
- [&](const Scalar<T> &x, const Scalar<Int4> &i) -> Scalar<T> {
- return x.SET_EXPONENT(i.ToInt64());
- }));
+ if (const auto *iExpr{UnwrapExpr<Expr<SomeInteger>>(args[1])}) {
+ return common::visit(
+ [&](const auto &iVal) {
+ using TY = ResultType<decltype(iVal)>;
+ return FoldElementalIntrinsic<T, T, TY>(context, std::move(funcRef),
+ ScalarFunc<T, T, TY>(
+ [&](const Scalar<T> &x, const Scalar<TY> &i) -> Scalar<T> {
+ return x.SET_EXPONENT(i.ToInt64());
+ }));
+ },
+ iExpr->u);
+ }
} else if (name == "sign") {
return FoldElementalIntrinsic<T, T, T>(
context, std::move(funcRef), &Scalar<T>::SIGN);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135203.465172.patch
Type: text/x-patch
Size: 1177 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221004/3f9bba43/attachment.bin>
More information about the flang-commits
mailing list