Fortran: Fix deferred character lengths in array constructors [PR98517].
authorPaul Thomas <pault@gcc.gnu.org>
Mon, 25 Jan 2021 10:27:51 +0000 (10:27 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Mon, 25 Jan 2021 10:27:51 +0000 (10:27 +0000)
2021-01-25  Steve Kargl  <kargl@gcc.gnu.org>

gcc/fortran
PR fortran/98517
* resolve.c (resolve_charlen): Check that length expression is
present before testing for scalar/integer..

gcc/testsuite/
PR fortran/98517
* gfortran.dg/charlen_18.f90 : New test.

gcc/fortran/resolve.c
gcc/testsuite/gfortran.dg/charlen_18.f90 [new file with mode: 0644]

index c075d0fa0c4269c1fe81e1833371f322a32b9cca..11b5dbc7a0336595bd9475cb29691b0ff68ae27b 100644 (file)
@@ -12446,7 +12446,8 @@ resolve_charlen (gfc_charlen *cl)
        }
 
       /* cl->length has been resolved.  It should have an integer type.  */
-      if (cl->length->ts.type != BT_INTEGER || cl->length->rank != 0)
+      if (cl->length
+         && (cl->length->ts.type != BT_INTEGER || cl->length->rank != 0))
        {
          gfc_error ("Scalar INTEGER expression expected at %L",
                     &cl->length->where);
diff --git a/gcc/testsuite/gfortran.dg/charlen_18.f90 b/gcc/testsuite/gfortran.dg/charlen_18.f90
new file mode 100644 (file)
index 0000000..5ad2874
--- /dev/null
@@ -0,0 +1,18 @@
+! { dg-do compile }
+! { dg-options "-fdec-structure" }
+!
+! Check fix for PR98517
+!
+! Contributed by Eric Reischer  <emr-gnu@hev.psu.edu>
+!
+      SUBROUTINE TEST_BUG
+      IMPLICIT NONE
+
+      CHARACTER*(*) DEF_VAL
+      PARAMETER (DEF_VAL = 'ABCDEFGH')
+
+      STRUCTURE /SOME_STRUCT/
+          CHARACTER*64    SOME_VAR /DEF_VAL/
+      END STRUCTURE
+
+      END