]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: fix ICE in check_charlen_present [PR108420]
authorHarald Anlauf <anlauf@gmx.de>
Mon, 16 Jan 2023 20:41:09 +0000 (21:41 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sat, 28 Jan 2023 21:27:47 +0000 (22:27 +0100)
gcc/fortran/ChangeLog:

PR fortran/108420
* iresolve.cc (check_charlen_present): Preserve character length if
there is no array constructor.

gcc/testsuite/ChangeLog:

PR fortran/108420
* gfortran.dg/pr108420.f90: New test.

(cherry picked from commit e6669c0a50ed8aee9e5997d61e6271668d149218)

gcc/fortran/iresolve.cc
gcc/testsuite/gfortran.dg/pr108420.f90 [new file with mode: 0644]

index dea19358b17175e6c88bd3ad33e23273bfa5aa78..a21ebb14c761bf5151b5e0ded7d59d00bc4d4558 100644 (file)
@@ -94,9 +94,12 @@ check_charlen_present (gfc_expr *source)
   else if (source->expr_type == EXPR_ARRAY)
     {
       gfc_constructor *c = gfc_constructor_first (source->value.constructor);
-      source->ts.u.cl->length
-               = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
-                                   c->expr->value.character.length);
+      if (c)
+       source->ts.u.cl->length
+         = gfc_get_int_expr (gfc_charlen_int_kind, NULL,
+                             c->expr->value.character.length);
+      if (source->ts.u.cl->length == NULL)
+       gfc_internal_error ("check_charlen_present(): length not set");
     }
 }
 
diff --git a/gcc/testsuite/gfortran.dg/pr108420.f90 b/gcc/testsuite/gfortran.dg/pr108420.f90
new file mode 100644 (file)
index 0000000..985c0b3
--- /dev/null
@@ -0,0 +1,10 @@
+! { dg-do compile }
+! PR fortran/108420
+! Contributed by G.Steinmetz
+
+program p
+  character :: c = 'c'
+  logical   :: m = .true.
+  print *, merge(transfer('a', 'b', 0), c, .true.)
+  print *, merge(transfer('a', 'b', 0), c, m)
+end