diff mbox series

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

Message ID trinity-e72ed1bb-b1b8-4e97-88f1-5ce4c98d0ef8-1590785324455@3c-app-gmx-bap60
State New
Headers show
Series [part2] PR fortran/95373 - [9/10/11 Regression] ICE in build_reference_type, at tree.c:7942 | expand

Commit Message

Harald Anlauf May 29, 2020, 8:48 p.m. UTC
The initial attempt to fix this PR unfortunately produced a regression
in the testsuite  that was overlooked.  The real fix is to apply this
check in the appropriate place.

Regtested on x86_64-pc-linux-gnu.  Really.

OK for master and backports?

Thanks,
Harald


PR fortran/95373 - 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
checks in the appropriate place.

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

gcc/fortran/
	PR fortran/95373
	* primary.c (is_inquiry_ref): Move validity check of inquiry
	references against selected Fortran standard from here...
	(gfc_match_varspec) ...to here.

gcc/testsuite/
	PR fortran/95373
	* gfortran.dg/pr95373_1.f90: Adjust error messages.
	* gfortran.dg/pr95373_2.f90: Adjust error message.

Comments

Paul Richard Thomas May 30, 2020, 4:12 p.m. UTC | #1
Hi Harald,

That looks good to me for all three branches.

Cheers

Paul


On Fri, 29 May 2020 at 23:00, Harald Anlauf <anlauf@gmx.de> wrote:

> The initial attempt to fix this PR unfortunately produced a regression
> in the testsuite  that was overlooked.  The real fix is to apply this
> check in the appropriate place.
>
> Regtested on x86_64-pc-linux-gnu.  Really.
>
> OK for master and backports?
>
> Thanks,
> Harald
>
>
> PR fortran/95373 - 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
> checks in the appropriate place.
>
> 2020-05-28  Harald Anlauf  <anlauf@gmx.de>
>
> gcc/fortran/
>         PR fortran/95373
>         * primary.c (is_inquiry_ref): Move validity check of inquiry
>         references against selected Fortran standard from here...
>         (gfc_match_varspec) ...to here.
>
> gcc/testsuite/
>         PR fortran/95373
>         * gfortran.dg/pr95373_1.f90: Adjust error messages.
>         * gfortran.dg/pr95373_2.f90: Adjust error message.
>
diff mbox series

Patch

diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c
index 67105cc9ab1..7c221c8d209 100644
--- a/gcc/fortran/primary.c
+++ b/gcc/fortran/primary.c
@@ -1998,28 +1998,6 @@  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 ();
@@ -2267,6 +2245,27 @@  gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
 	    {
 	      if (tmp)
 		{
+		  switch (tmp->u.i)
+		    {
+		    case INQUIRY_RE:
+		    case INQUIRY_IM:
+		      if (!gfc_notify_std (GFC_STD_F2008,
+					   "RE or IM part_ref at %C"))
+			return MATCH_ERROR;
+		      break;
+
+		    case INQUIRY_KIND:
+		      if (!gfc_notify_std (GFC_STD_F2003,
+					   "KIND part_ref at %C"))
+			return MATCH_ERROR;
+		      break;
+
+		    case INQUIRY_LEN:
+		      if (!gfc_notify_std (GFC_STD_F2003, "LEN part_ref at %C"))
+			return MATCH_ERROR;
+		      break;
+		    }
+
 		  if ((tmp->u.i == INQUIRY_RE || tmp->u.i == INQUIRY_IM)
 		      && primary->ts.type != BT_COMPLEX)
 		    {
diff --git a/gcc/testsuite/gfortran.dg/pr95373_1.f90 b/gcc/testsuite/gfortran.dg/pr95373_1.f90
index f39b6a72346..59a9e7a81e0 100644
--- a/gcc/testsuite/gfortran.dg/pr95373_1.f90
+++ b/gcc/testsuite/gfortran.dg/pr95373_1.f90
@@ -4,12 +4,12 @@ 

 subroutine s (x)
   complex, parameter :: z = 3
-  real(z% kind)      :: x       ! { dg-error "nonderived-type variable" }
+  real(z% kind)      :: x       ! { dg-error "Fortran 2003: KIND part_ref" }
   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" }
+  print *, z% re                ! { dg-error "Fortran 2008: RE or IM part_ref" }
 end
diff --git a/gcc/testsuite/gfortran.dg/pr95373_2.f90 b/gcc/testsuite/gfortran.dg/pr95373_2.f90
index 2a654b43faa..b0f3da0a20d 100644
--- a/gcc/testsuite/gfortran.dg/pr95373_2.f90
+++ b/gcc/testsuite/gfortran.dg/pr95373_2.f90
@@ -11,5 +11,5 @@  subroutine s (x)
   end type t
   type(t) :: b
   print *, b% kind, b% re
-  print *, z% re                ! { dg-error "nonderived-type variable" }
+  print *, z% re                ! { dg-error "Fortran 2008: RE or IM part_ref" }
 end