[committed] PR fortran/99256 - ICE in variable_check, at fortran/check.c:1012

Message ID trinity-1d428669-e000-4397-8174-fb7194524b3a-1642193773780@3c-app-gmx-bap59
State New
Headers show
Series
  • [committed] PR fortran/99256 - ICE in variable_check, at fortran/check.c:1012
Related show

Commit Message

Kewen.Lin via Gcc-patches Jan. 14, 2022, 8:56 p.m.
Dear all,

this is a rather satisfying mini-patch which removes code to fix a bug.

The intrinsics MOVE_ALLOC, C_F_POINTER, and C_F_PROCPOINTER require
deferred checks of part of their actual argument types which may be of
"any" type.  This however excludes alternate return specifiers which
therefore must be unconditionally rejected for all standard intrinsics.

OK'ed by Steve (see PR), and committed to mainline as obvious after
regtesting on x86_64-pc-linux-gnu.

Thanks,
Harald

Patch

From 70e24c9682ddbcade0301665bccd8e7f928d0082 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Fri, 14 Jan 2022 21:48:15 +0100
Subject: [PATCH] Fortran: always reject alternate return specifier as argument
 of intrinsics

The intrinsics MOVE_ALLOC, C_F_POINTER, and C_F_PROCPOINTER require
deferred checks of part of their actual argument types which may be of
"any" type.  This however excludes alternate return specifiers which
therefore must be unconditionally rejected for all standard intrinsics.

gcc/fortran/ChangeLog:

	PR fortran/99256
	* intrinsic.c: Do not check formal argument type when checking
	arguments of intrinsics for alternate return specifiers.

gcc/testsuite/ChangeLog:

	PR fortran/99256
	* gfortran.dg/altreturn_11.f90: New test.
---
 gcc/fortran/intrinsic.c                    |  2 +-
 gcc/testsuite/gfortran.dg/altreturn_11.f90 | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gfortran.dg/altreturn_11.f90

diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c
index a7ecdb401ef..9746cd5ddb6 100644
--- a/gcc/fortran/intrinsic.c
+++ b/gcc/fortran/intrinsic.c
@@ -4420,7 +4420,7 @@  do_sort:
   FOR_EACH_VEC_ELT (dummy_args, idx, f)
     {
       a = ordered_actual_args[idx];
-      if (a && a->label != NULL && f->ts.type)
+      if (a && a->label != NULL)
 	{
 	  gfc_error ("ALTERNATE RETURN not permitted at %L", where);
 	  return false;
diff --git a/gcc/testsuite/gfortran.dg/altreturn_11.f90 b/gcc/testsuite/gfortran.dg/altreturn_11.f90
new file mode 100644
index 00000000000..be42971d781
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/altreturn_11.f90
@@ -0,0 +1,15 @@ 
+! { dg-do compile }
+! { dg-prune-output "Obsolescent feature: Alternate-return argument" }
+! PR fortran/99256 - ICE in variable_check
+! Contributed by G.Steimetz
+
+program test
+  use iso_c_binding
+  type(c_ptr)    :: i
+  type(c_funptr) :: p
+  call move_alloc     (*1, *2) ! { dg-error "ALTERNATE RETURN" }
+  call c_f_pointer     (i, *1) ! { dg-error "ALTERNATE RETURN" }
+  call c_f_procpointer (p, *2) ! { dg-error "ALTERNATE RETURN" }
+1 continue
+2 stop
+end
--
2.31.1