[committed] PR fortran/95373 - [9/10/11 Regression] ICE in build_reference_type, at tree.c:7942

Message ID trinity-79403354-bdaa-4a09-8691-fe91036f327f-1590698279082@3c-app-gmx-bs20
State New
Headers show
Series
  • [committed] PR fortran/95373 - [9/10/11 Regression] ICE in build_reference_type, at tree.c:7942
Related show

Commit Message

Harald Anlauf May 28, 2020, 8:37 p.m.
The obvious patch attached was already OKed in the PR by Steve Kargl.
As it is a 9/10/11 regression, I will backport it in a few days.

Thanks,
Harald


PR fortran/95373 - [9/10/11 Regression] ICE in build_reference_type, at tree.c:7942

The use of KIND, LEN, RE, and IM inquiry references for applicable intrinsic
types is valid only for suffienctly new Fortran standards.  Add appropriate
check.

2020-05-28  Harald Anlauf  <anlauf@gmx.de>

gcc/fortran/
	PR fortran/95373
	* primary.c (is_inquiry_ref): Check validity of inquiry
	references against selected Fortran standard.

gcc/testsuite/
	PR fortran/95373
	* gfortran.dg/pr95373_1.f90: New test.
	* gfortran.dg/pr95373_2.f90: New test.

Patch

diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c
index d73898473df..67105cc9ab1 100644
--- a/gcc/fortran/primary.c
+++ b/gcc/fortran/primary.c
@@ -1998,6 +1998,28 @@  is_inquiry_ref (const char *name, gfc_ref **ref)
   else
     return false;

+  switch (type)
+    {
+    case INQUIRY_RE:
+    case INQUIRY_IM:
+      if (!gfc_notify_std (GFC_STD_F2008, "RE or IM part_ref at %C"))
+	return false;
+      break;
+
+    case INQUIRY_KIND:
+      if (!gfc_notify_std (GFC_STD_F2003, "KIND part_ref at %C"))
+	return false;
+      break;
+
+    case INQUIRY_LEN:
+      if (!gfc_notify_std (GFC_STD_F2003, "LEN part_ref at %C"))
+	return false;
+      break;
+
+    default:
+      gcc_unreachable ();
+    }
+
   if (ref)
     {
       *ref = gfc_get_ref ();
diff --git a/gcc/testsuite/gfortran.dg/pr95373_1.f90 b/gcc/testsuite/gfortran.dg/pr95373_1.f90
new file mode 100644
index 00000000000..f39b6a72346
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95373_1.f90
@@ -0,0 +1,15 @@ 
+! { dg-do compile }
+! { dg-options "-std=f95" }
+! PR fortran/95373 - ICE in build_reference_type, at tree.c:7942
+
+subroutine s (x)
+  complex, parameter :: z = 3
+  real(z% kind)      :: x       ! { dg-error "nonderived-type variable" }
+  type t
+     real    :: kind
+     logical :: re
+  end type t
+  type(t) :: b
+  print *, b% kind, b% re
+  print *, z% re                ! { dg-error "nonderived-type variable" }
+end
diff --git a/gcc/testsuite/gfortran.dg/pr95373_2.f90 b/gcc/testsuite/gfortran.dg/pr95373_2.f90
new file mode 100644
index 00000000000..2a654b43faa
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr95373_2.f90
@@ -0,0 +1,15 @@ 
+! { dg-do compile }
+! { dg-options "-std=f2003" }
+! PR fortran/95373 - ICE in build_reference_type, at tree.c:7942
+
+subroutine s (x)
+  complex, parameter :: z = 3
+  real(z% kind)      :: x
+  type t
+     real    :: kind
+     logical :: re
+  end type t
+  type(t) :: b
+  print *, b% kind, b% re
+  print *, z% re                ! { dg-error "nonderived-type variable" }
+end