public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/103782  - [9/10/11/12 Regression] internal error occurs when overloading intrinsic
@ 2022-01-13 20:56 Harald Anlauf
  2022-01-14  3:16 ` Jerry D
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2022-01-13 20:56 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 439 bytes --]

Dear all,

there was a regression handling overloaded elemental intrinsics,
leading to an ICE on valid code.  Reported by Urban Jost.

The logic for when we need to scalarize a call to an intrinsic
seems to have been broken during the 9-release.  The attached
patch fixes the ICE and seems to work on the extended testcase
as well as regtests fine on x86_64-pc-linux-gnu.

OK for mainline?  Backport to affected branches?

Thanks,
Harald


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-fix-ICE-overloading-elemental-intrinsics.patch --]
[-- Type: text/x-patch, Size: 2530 bytes --]

From 5b914bef991528aebfe9734b4e7af7bae039e66a Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Thu, 13 Jan 2022 21:50:45 +0100
Subject: [PATCH] Fortran: fix ICE overloading elemental intrinsics

gcc/fortran/ChangeLog:

	PR fortran/103782
	* expr.c (gfc_simplify_expr): Adjust logic for when to scalarize a
	call of an intrinsic which may have been overloaded.

gcc/testsuite/ChangeLog:

	PR fortran/103782
	* gfortran.dg/overload_4.f90: New test.
---
 gcc/fortran/expr.c                       |  5 ++---
 gcc/testsuite/gfortran.dg/overload_4.f90 | 27 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gfortran.dg/overload_4.f90

diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c
index a87686d8217..20b88a8ef56 100644
--- a/gcc/fortran/expr.c
+++ b/gcc/fortran/expr.c
@@ -2219,10 +2219,9 @@ gfc_simplify_expr (gfc_expr *p, int type)
 	  && gfc_intrinsic_func_interface (p, 1) == MATCH_ERROR)
 	return false;

-      if (p->expr_type == EXPR_FUNCTION)
+      if (p->symtree && (p->value.function.isym || p->ts.type == BT_UNKNOWN))
 	{
-	  if (p->symtree)
-	    isym = gfc_find_function (p->symtree->n.sym->name);
+	  isym = gfc_find_function (p->symtree->n.sym->name);
 	  if (isym && isym->elemental)
 	    scalarize_intrinsic_call (p, false);
 	}
diff --git a/gcc/testsuite/gfortran.dg/overload_4.f90 b/gcc/testsuite/gfortran.dg/overload_4.f90
new file mode 100644
index 00000000000..43207e358ba
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/overload_4.f90
@@ -0,0 +1,27 @@
+! { dg-do run }
+! { dg-additional-options "-Wno-intrinsic-shadow" }
+! PR fortran/103782 - ICE overloading an intrinsic like dble or real
+! Contributed by Urban Jost
+
+program runtest
+  implicit none
+  interface dble
+     procedure to_double
+  end interface dble
+  interface real
+     procedure floor ! not really FLOOR...
+  end interface real
+  if (any (dble ([10.0d0,20.0d0]) - [10.0d0,20.0d0] /= 0.d0)) stop 1
+  if (any (real ([1.5,2.5])       - [1.5,2.5]       /= 0.0 )) stop 2
+contains
+  elemental function to_double (valuein) result(d_out)
+    doubleprecision,intent(in) :: valuein
+    doubleprecision            :: d_out
+    d_out=valuein
+  end function to_double
+  elemental function floor (valuein) result(d_out) ! not really FLOOR...
+    real, intent(in) :: valuein
+    real             :: d_out
+    d_out=valuein
+  end function floor
+end program runtest
--
2.31.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PR fortran/103782 - [9/10/11/12 Regression] internal error occurs when overloading intrinsic
  2022-01-13 20:56 [PATCH] PR fortran/103782 - [9/10/11/12 Regression] internal error occurs when overloading intrinsic Harald Anlauf
@ 2022-01-14  3:16 ` Jerry D
  0 siblings, 0 replies; 2+ messages in thread
From: Jerry D @ 2022-01-14  3:16 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

On 1/13/22 12:56 PM, Harald Anlauf via Fortran wrote:
> Dear all,
>
> there was a regression handling overloaded elemental intrinsics,
> leading to an ICE on valid code.  Reported by Urban Jost.
>
> The logic for when we need to scalarize a call to an intrinsic
> seems to have been broken during the 9-release.  The attached
> patch fixes the ICE and seems to work on the extended testcase
> as well as regtests fine on x86_64-pc-linux-gnu.
>
> OK for mainline?  Backport to affected branches?
>
Looks good to me. Go for mainline and backport.

Regards,

Jerry

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-14  3:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13 20:56 [PATCH] PR fortran/103782 - [9/10/11/12 Regression] internal error occurs when overloading intrinsic Harald Anlauf
2022-01-14  3:16 ` Jerry D

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).