[flang-commits] [PATCH] D136904: [flang] Warn about overflow from folding complex ABS()
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Sat Oct 29 16:07:15 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG78d59a6500df: [flang] Warn about overflow from folding complex ABS() (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D136904/new/
https://reviews.llvm.org/D136904
Files:
flang/lib/Evaluate/fold-real.cpp
flang/test/Evaluate/errors01.f90
Index: flang/test/Evaluate/errors01.f90
===================================================================
--- flang/test/Evaluate/errors01.f90
+++ flang/test/Evaluate/errors01.f90
@@ -105,5 +105,7 @@
real, parameter :: ok2 = scale(1.0, -99999) ! 0.0
!CHECK: SCALE intrinsic folding overflow
real, parameter :: bad1 = scale(1.0, 99999)
+ !CHECK: complex ABS intrinsic folding overflow
+ real, parameter :: bad2 = abs(cmplx(huge(0.),huge(0.)))
end subroutine
end module
Index: flang/lib/Evaluate/fold-real.cpp
===================================================================
--- flang/lib/Evaluate/fold-real.cpp
+++ flang/lib/Evaluate/fold-real.cpp
@@ -105,8 +105,14 @@
context, std::move(funcRef), &Scalar<T>::ABS);
} else if (auto *z{UnwrapExpr<Expr<SomeComplex>>(args[0])}) {
return FoldElementalIntrinsic<T, ComplexT>(context, std::move(funcRef),
- ScalarFunc<T, ComplexT>([](const Scalar<ComplexT> &z) -> Scalar<T> {
- return z.ABS().value;
+ ScalarFunc<T, ComplexT>([&name, &context](
+ const Scalar<ComplexT> &z) -> Scalar<T> {
+ ValueWithRealFlags<Scalar<T>> y{z.ABS()};
+ if (y.flags.test(RealFlag::Overflow)) {
+ context.messages().Say(
+ "complex ABS intrinsic folding overflow"_warn_en_US, name);
+ }
+ return y.value;
}));
} else {
common::die(" unexpected argument type inside abs");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136904.471791.patch
Type: text/x-patch
Size: 1512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221029/7b6d9833/attachment.bin>
More information about the flang-commits
mailing list