[flang-commits] [flang] e5caa6b - [flang] Correct manipulation of mixed complex expressions
peter klausler via flang-commits
flang-commits at lists.llvm.org
Thu Aug 13 09:04:47 PDT 2020
Author: peter klausler
Date: 2020-08-13T09:04:00-07:00
New Revision: e5caa6b5abfa3484fa6107961a62173c6955a8ef
URL: https://github.com/llvm/llvm-project/commit/e5caa6b5abfa3484fa6107961a62173c6955a8ef
DIFF: https://github.com/llvm/llvm-project/commit/e5caa6b5abfa3484fa6107961a62173c6955a8ef.diff
LOG: [flang] Correct manipulation of mixed complex expressions
Ensure that mixed complex expressions (one operand complex,
the other not) are properly manipulated; add test.
Added:
flang/test/Evaluate/folding11.f90
Modified:
flang/lib/Evaluate/tools.cpp
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 677b263408b3..6cc411f22adb 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -242,9 +242,9 @@ std::optional<Expr<SomeType>> MixedComplexLeft(
// (a,b) * x -> (a*x, b*x)
// (a,b) / x -> (a/x, b/x)
auto copy{iry};
- auto rr{NumericOperation<Multiply>(messages, AsGenericExpr(std::move(zr)),
+ auto rr{NumericOperation<OPR>(messages, AsGenericExpr(std::move(zr)),
AsGenericExpr(std::move(iry)), defaultRealKind)};
- auto ri{NumericOperation<Multiply>(messages, AsGenericExpr(std::move(zi)),
+ auto ri{NumericOperation<OPR>(messages, AsGenericExpr(std::move(zi)),
AsGenericExpr(std::move(copy)), defaultRealKind)};
if (auto parts{common::AllPresent(std::move(rr), std::move(ri))}) {
return Package(ConstructComplex(messages, std::get<0>(std::move(*parts)),
@@ -287,7 +287,7 @@ std::optional<Expr<SomeType>> MixedComplexRight(
std::is_same_v<OPR<LargestReal>, Multiply<LargestReal>>) {
// x + (a,b) -> (a,b) + x -> (a+x, b)
// x * (a,b) -> (a,b) * x -> (a*x, b*x)
- return MixedComplexLeft<Add, LCAT>(
+ return MixedComplexLeft<OPR, LCAT>(
messages, std::move(zy), std::move(irx), defaultRealKind);
} else if constexpr (std::is_same_v<OPR<LargestReal>,
Subtract<LargestReal>>) {
diff --git a/flang/test/Evaluate/folding11.f90 b/flang/test/Evaluate/folding11.f90
new file mode 100644
index 000000000000..89983889d573
--- /dev/null
+++ b/flang/test/Evaluate/folding11.f90
@@ -0,0 +1,31 @@
+! RUN: %S/test_folding.sh %s %t %f18
+module m
+ complex, parameter :: z1 = 1. + (2., 3.)
+ logical, parameter :: test_z1 = z1 == (3., 3.)
+ complex, parameter :: z2 = 1 + (2., 3.)
+ logical, parameter :: test_z2 = z2 == (3., 3.)
+ complex, parameter :: z3 = 2. * (3., 4.)
+ logical, parameter :: test_z3 = z3 == (6., 8.)
+ complex, parameter :: z4 = 2 * (3., 4.)
+ logical, parameter :: test_z4 = z4 == (6., 8.)
+ complex, parameter :: z5 = 5. - (3., 4.)
+ logical, parameter :: test_z5 = z5 == (2., -4.)
+ complex, parameter :: z6 = 5 - (3., 4.)
+ logical, parameter :: test_z6 = z6 == (2., -4.)
+ complex, parameter :: z11 = (2., 3.) + 1.
+ logical, parameter :: test_z11 = z11 == (3., 3.)
+ complex, parameter :: z12 = (2., 3.) + 1
+ logical, parameter :: test_z12 = z12 == (3., 3.)
+ complex, parameter :: z13 = (3., 4.) * 2.
+ logical, parameter :: test_z13 = z13 == (6., 8.)
+ complex, parameter :: z14 = (3., 4.) * 2
+ logical, parameter :: test_z14 = z14 == (6., 8.)
+ complex, parameter :: z15 = (3., 4.) - 1.
+ logical, parameter :: test_z15 = z15 == (2., 4.)
+ complex, parameter :: z16 = (3., 4.) - 1
+ logical, parameter :: test_z16 = z16 == (2., 4.)
+ complex, parameter :: z17 = (3., 4.) / 2.
+ logical, parameter :: test_z17 = z17 == (1.5, 2.)
+ complex, parameter :: z18 = (3., 4.) / 2
+ logical, parameter :: test_z18 = z18 == (1.5, 2.)
+end module
More information about the flang-commits
mailing list