fortran: ICE in gfc_conv_constant_to_tree PR93604
authorMark Eggleston <markeggleston@gcc.gnu.org>
Mon, 24 Feb 2020 14:33:35 +0000 (14:33 +0000)
committerMark Eggleston <markeggleston@gcc.gnu.org>
Mon, 24 Feb 2020 14:33:35 +0000 (14:33 +0000)
Using a BOZ constant in a structure constructor in a data statement
resulted in an ICE. Output a "BOZ literal constant cannot appear in
a structure constructor" error message instead.

Original patch provided by Steven G. Kargl  <kargl@gcc.gnu.org>.

Test case added later.

gcc/fortran/ChangeLog

PR fortran/93604
* decl.c (gfc_match_data) : Check whether the data expression
is a derived type and is a constructor. If a BOZ constant
is encountered in the constructor output an error and return
MATCH_ERROR.

gcc/testsuite/ChangeLog

PR fortran/93604
* gfortran.dg/pr93604.f90 : New test.

gcc/fortran/ChangeLog
gcc/fortran/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr93604.f90 [new file with mode: 0644]

index 94ceb5c8aa346c71fec57ca3dc41d7958972e25d..e25d05cf79431cdb8a150cd35197bbebf54d9027 100644 (file)
@@ -1,3 +1,11 @@
+2020-02-24  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/93604
+       * decl.c (gfc_match_data) : Check whether the data expression
+       is a derived type and is a constructor. If a BOZ constant
+       is encountered in the constructor output an error and return
+       MATCH_ERROR.
+
 2020-02-24  Tobias Burnus  <tobias@codesourcery.com>
 
        PR fortran/93552
index 499d2429aba652fc8dbf5a5745ec8f030aaafa43..7382fea03e4633d25530aeb912bc1e0998bdf9cc 100644 (file)
@@ -716,6 +716,22 @@ gfc_match_data (void)
       new_data->next = gfc_current_ns->data;
       gfc_current_ns->data = new_data;
 
+      /* A BOZ literal constant cannot appear in a structure constructor.
+        Check for that here for a data statement value.  */
+      if (new_data->value->expr->ts.type == BT_DERIVED
+         && new_data->value->expr->value.constructor)
+       {
+         gfc_constructor *c;
+         c = gfc_constructor_first (new_data->value->expr->value.constructor);
+         for (; c; c = gfc_constructor_next (c))
+           if (c->expr->ts.type == BT_BOZ)
+             {
+               gfc_error ("BOZ literal constant at %L cannot appear in a "
+                          "structure constructor", &c->expr->where);
+               return MATCH_ERROR;
+             }
+       }
+
       if (gfc_match_eos () == MATCH_YES)
        break;
 
index d92e40ec279b07cf6804868c4d935ee53d79e803..272d4ea478cf438eadb3d4e522e5ac6725423ced 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-20  Mark Eggleston  <mark.eggleston@codethink.com>
+
+       PR fortran/93604
+       * gfortran.dg/pr93604.f90 : New test.
+
 2020-02-24  Jakub Jelinek  <jakub@redhat.com>
 
        P1937R2 - Fixing inconsistencies between const{expr,eval} functions
diff --git a/gcc/testsuite/gfortran.dg/pr93604.f90 b/gcc/testsuite/gfortran.dg/pr93604.f90
new file mode 100644 (file)
index 0000000..2c695d3
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+
+program p
+   type t
+      integer :: a
+   end type
+   type(t) :: x
+   data x /t(z'1')/ ! { dg-error "cannot appear in a structure constructor" }
+end
+