diff --git a/flang/lib/Evaluate/fold-complex.cpp b/flang/lib/Evaluate/fold-complex.cpp --- a/flang/lib/Evaluate/fold-complex.cpp +++ b/flang/lib/Evaluate/fold-complex.cpp @@ -36,7 +36,7 @@ context, std::move(funcRef), &Scalar::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>(args[0])}) { return Fold(context, ConvertToType(std::move(*x))); } @@ -46,7 +46,8 @@ Expr{ComplexConstructor{ToReal(context, std::move(re)), ToReal(context, std::move(im))}}); } - CHECK(args.size() == 2 || args.size() == 3); + // CMPLX(X, [Y, KIND]) + CHECK(args.size() == 3); Expr re{std::move(*args[0].value().UnwrapExpr())}; Expr im{args[1] ? std::move(*args[1].value().UnwrapExpr()) : AsGenericExpr(Constant{Scalar{}})}; diff --git a/flang/test/Evaluate/folding01.f90 b/flang/test/Evaluate/folding01.f90 --- a/flang/test/Evaluate/folding01.f90 +++ b/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