[gcc/devel/omp/gcc-9] backport: re PR fortran/90290 (-std=f2008 should reject non-constant stop and error stop codes)

Tobias Burnus burnus@gcc.gnu.org
Thu Mar 5 14:02:00 GMT 2020


https://gcc.gnu.org/g:ab7b24942d2903c73744108d38803d4950d3fb47

commit ab7b24942d2903c73744108d38803d4950d3fb47
Author: Steven G. Kargl <kargl@gcc.gnu.org>
Date:   Fri Jun 21 00:54:28 2019 +0000

    backport: re PR fortran/90290 (-std=f2008 should reject non-constant stop and error stop codes)
    
    2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
    
    	Backport from mainline
    	PR fortran/90290
    	* match.c (gfc_match_stopcode): Check F2008 condition on stop code.
    
    2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
    
    	Backport from mainline
    	PR fortran/90290
    	* gfortran.dg/pr90290.f90: New test.
    
    From-SVN: r272541

Diff:
---
 gcc/fortran/ChangeLog                 |  6 ++++++
 gcc/fortran/match.c                   | 17 ++++++++++++++---
 gcc/testsuite/ChangeLog               |  6 ++++++
 gcc/testsuite/gfortran.dg/pr90290.f90 |  7 +++++++
 4 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 8fad5e8..35d3091 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,6 +1,12 @@
 2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
 
 	Backport from mainline
+	PR fortran/90290
+	* match.c (gfc_match_stopcode): Check F2008 condition on stop code.
+
+2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+	Backport from mainline
 	PR fortran/90002
 	* array.c (gfc_free_array_spec): When freeing an array-spec, avoid
 	an ICE for assumed-shape coarrays 
diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c
index bc780ce..156d7a0 100644
--- a/gcc/fortran/match.c
+++ b/gcc/fortran/match.c
@@ -2955,7 +2955,7 @@ gfc_match_stopcode (gfc_statement st)
 {
   gfc_expr *e = NULL;
   match m;
-  bool f95, f03;
+  bool f95, f03, f08;
 
   /* Set f95 for -std=f95.  */
   f95 = (gfc_option.allow_std == GFC_STD_OPT_F95);
@@ -2963,6 +2963,9 @@ gfc_match_stopcode (gfc_statement st)
   /* Set f03 for -std=f2003.  */
   f03 = (gfc_option.allow_std == GFC_STD_OPT_F03);
 
+  /* Set f08 for -std=f2008.  */
+  f08 = (gfc_option.allow_std == GFC_STD_OPT_F08);
+
   /* Look for a blank between STOP and the stop-code for F2008 or later.  */
   if (gfc_current_form != FORM_FIXED && !(f95 || f03))
     {
@@ -3051,8 +3054,8 @@ gfc_match_stopcode (gfc_statement st)
       /* Test for F95 and F2003 style STOP stop-code.  */
       if (e->expr_type != EXPR_CONSTANT && (f95 || f03))
 	{
-	  gfc_error ("STOP code at %L must be a scalar CHARACTER constant or "
-		     "digit[digit[digit[digit[digit]]]]", &e->where);
+	  gfc_error ("STOP code at %L must be a scalar CHARACTER constant "
+		     "or digit[digit[digit[digit[digit]]]]", &e->where);
 	  goto cleanup;
 	}
 
@@ -3062,6 +3065,14 @@ gfc_match_stopcode (gfc_statement st)
       gfc_reduce_init_expr (e);
       gfc_init_expr_flag = false;
 
+      /* Test for F2008 style STOP stop-code.  */
+      if (e->expr_type != EXPR_CONSTANT && f08)
+	{
+	  gfc_error ("STOP code at %L must be a scalar default CHARACTER or "
+		     "INTEGER constant expression", &e->where);
+	  goto cleanup;
+	}
+
       if (!(e->ts.type == BT_CHARACTER || e->ts.type == BT_INTEGER))
 	{
 	  gfc_error ("STOP code at %L must be either INTEGER or CHARACTER type",
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fd0afe0..7ad4fa2 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,12 @@
 2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
 
 	Backport from mainline
+	PR fortran/90290
+	* gfortran.dg/pr90290.f90: New test.
+
+2019-06-20  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+	Backport from mainline
 	PR fortran/90002
 	* gfortran.dg/pr90002.f90: New test.
 
diff --git a/gcc/testsuite/gfortran.dg/pr90290.f90 b/gcc/testsuite/gfortran.dg/pr90290.f90
new file mode 100644
index 0000000..280d7de
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr90290.f90
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! { dg-options "-std=f2008" }
+program errorstop
+  integer :: ec
+  read *, ec
+  stop ec      ! { dg-error "STOP code at " }
+end program



More information about the Gcc-cvs mailing list