Fortran: simplification of FINDLOC for constant complex arguments [PR110585]
Checks
Commit Message
Dear all,
I intend to commit the attached obvious patch within 24h unless
someone objects. gfc_compare_expr() did not handle the case of
complex constants, which may be compared for equality. This
case is needed in the simplification of the FINDLOC intrinsic.
Regtested on x86_64-pc-linux-gnu.
Thanks,
Harald
Comments
Hi Harald,
This is indeed obvious :-)
Thanks for the patch.
Paul
On Fri, 7 Jul 2023 at 19:32, Harald Anlauf via Fortran
<fortran@gcc.gnu.org> wrote:
>
> Dear all,
>
> I intend to commit the attached obvious patch within 24h unless
> someone objects. gfc_compare_expr() did not handle the case of
> complex constants, which may be compared for equality. This
> case is needed in the simplification of the FINDLOC intrinsic.
>
> Regtested on x86_64-pc-linux-gnu.
>
> Thanks,
> Harald
>
From b6c4f70d2dac4863335874f0bd3486ea7db348d7 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Fri, 7 Jul 2023 20:25:06 +0200
Subject: [PATCH] Fortran: simplification of FINDLOC for constant complex
arguments [PR110585]
gcc/fortran/ChangeLog:
PR fortran/110585
* arith.cc (gfc_compare_expr): Handle equality comparison of constant
complex gfc_expr arguments.
gcc/testsuite/ChangeLog:
PR fortran/110585
* gfortran.dg/findloc_9.f90: New test.
---
gcc/fortran/arith.cc | 5 +++++
gcc/testsuite/gfortran.dg/findloc_9.f90 | 19 +++++++++++++++++++
2 files changed, 24 insertions(+)
create mode 100644 gcc/testsuite/gfortran.dg/findloc_9.f90
@@ -1120,6 +1120,11 @@ gfc_compare_expr (gfc_expr *op1, gfc_expr *op2, gfc_intrinsic_op op)
|| (op1->value.logical && !op2->value.logical));
break;
+ case BT_COMPLEX:
+ gcc_assert (op == INTRINSIC_EQ);
+ rc = mpc_cmp (op1->value.complex, op2->value.complex);
+ break;
+
default:
gfc_internal_error ("gfc_compare_expr(): Bad basic type");
}
new file mode 100644
@@ -0,0 +1,19 @@
+! { dg-do compile }
+! { dg-options "-fdump-tree-original" }
+! PR fortran/110585 - simplification of FINDLOC for constant complex arguments
+
+program mvce
+ implicit none
+ integer, parameter :: a(*) = findloc([(1.,0.),(2.,1.)], (2.,0.))
+ integer, parameter :: b(*) = findloc([(1.,0.),(2.,1.)], (2.,0.), back=.true.)
+ integer, parameter :: c(*) = findloc([(1.,0.),(2.,1.)], (2.,1.))
+ integer, parameter :: d(*) = findloc([(1.,0.),(2.,1.)], (2.,1.), back=.true.)
+ integer, parameter :: e = findloc([(1.,0.),(2.,1.)], (2.,1.), dim=1)
+ if (a(1) /= 0) stop 1
+ if (b(1) /= 0) stop 2
+ if (c(1) /= 2) stop 3
+ if (d(1) /= 2) stop 4
+ if (e /= 2) stop 5
+end
+
+! { dg-final { scan-tree-dump-not "_gfortran_stop_numeric" "original" } }
--
2.35.3