[PATCH] D84936: [flang] Fix CMPLX folding with complex arguments
Jean Perier via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 05:34:15 PDT 2020
jeanPerier created this revision.
jeanPerier added reviewers: klausler, schweitz, sscalpone.
jeanPerier added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
jeanPerier requested review of this revision.
CMPLX folding was expecting only one arguments in case X argument
is complex. This is wrong since there is also the optional KIND
argument.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84936
Files:
flang/lib/Evaluate/fold-complex.cpp
flang/test/Evaluate/folding01.f90
Index: flang/test/Evaluate/folding01.f90
===================================================================
--- flang/test/Evaluate/folding01.f90
+++ flang/test/Evaluate/folding01.f90
@@ -63,6 +63,14 @@
logical, parameter :: test_ne_i1 =.NOT.(2.NE.2)
logical, parameter :: test_ne_i2 = -2.NE.2
+! Check conversions
+ logical, parameter :: test_cmplx1 = cmplx((1._4, -1._4)).EQ.((1._4, -1._4))
+ logical, parameter :: test_cmplx2 = cmplx((1._4, -1._4), 8).EQ.((1._8, -1._8))
+ logical, parameter :: test_cmplx3 = cmplx(1._4, -1._4).EQ.((1._4, -1._4))
+ logical, parameter :: test_cmplx4 = cmplx(1._4, -1._4, 8).EQ.((1._8, -1._8))
+ logical, parameter :: test_cmplx5 = cmplx(1._4).EQ.((1._4, 0._4))
+ logical, parameter :: test_cmplx6 = cmplx(1._4, kind=8).EQ.((1._8, 0._8))
+
! Check integer intrinsic operation folding
logical, parameter :: test_unaryminus_i = (-(-1)).EQ.1
logical, parameter :: test_unaryplus_i = (+1).EQ.1
Index: flang/lib/Evaluate/fold-complex.cpp
===================================================================
--- flang/lib/Evaluate/fold-complex.cpp
+++ flang/lib/Evaluate/fold-complex.cpp
@@ -36,7 +36,7 @@
context, std::move(funcRef), &Scalar<T>::CONJG);
} else if (name == "cmplx") {
using Part = typename T::Part;
- if (args.size() == 1) {
+ if (args.size() == 2) { // CMPLX(X, [KIND])
if (auto *x{UnwrapExpr<Expr<SomeComplex>>(args[0])}) {
return Fold(context, ConvertToType<T>(std::move(*x)));
}
@@ -46,7 +46,8 @@
Expr<T>{ComplexConstructor<KIND>{ToReal<KIND>(context, std::move(re)),
ToReal<KIND>(context, std::move(im))}});
}
- CHECK(args.size() == 2 || args.size() == 3);
+ // CMPLX(X, [Y, KIND])
+ CHECK(args.size() == 3);
Expr<SomeType> re{std::move(*args[0].value().UnwrapExpr())};
Expr<SomeType> im{args[1] ? std::move(*args[1].value().UnwrapExpr())
: AsGenericExpr(Constant<Part>{Scalar<Part>{}})};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84936.281891.patch
Type: text/x-patch
Size: 1988 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200730/0a85a83c/attachment.bin>
More information about the llvm-commits
mailing list