[flang] Correct manipulation of mixed complex expressions

Ensure that mixed complex expressions (one operand complex,
the other not) are properly manipulated; add test.
This commit is contained in:
peter klausler 2020-08-12 16:35:26 -07:00
parent 51cfad3a1a
commit e5caa6b5ab
2 changed files with 34 additions and 3 deletions

View File

@ -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>>) {

View File

@ -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