This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[PATCH] PR fortran/78571 -- Avoid ICE in invalid CHARACTER initialization
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Thu, 7 Jun 2018 17:16:24 -0700
- Subject: [PATCH] PR fortran/78571 -- Avoid ICE in invalid CHARACTER initialization
- Reply-to: sgk at troutmask dot apl dot washington dot edu
Regression tested on x86_64-*-freebsd. OK to commit?
2018-06-07 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/78571
* data.c (create_character_initializer): Return early if type is
incompatible with CHARACTER.
2018-06-07 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/78571
* gfortran.dg/pr78571.f90: New test.
--
Steve
Index: gcc/fortran/data.c
===================================================================
--- gcc/fortran/data.c (revision 261285)
+++ gcc/fortran/data.c (working copy)
@@ -107,7 +107,10 @@ create_character_initializer (gfc_expr *init, gfc_type
HOST_WIDE_INT len, start, end, tlen;
gfc_char_t *dest;
bool alloced_init = false;
-
+
+ if (init && init->ts.type != BT_CHARACTER)
+ return NULL;
+
gfc_extract_hwi (ts->u.cl->length, &len);
if (init == NULL)
Index: gcc/testsuite/gfortran.dg/pr78571.f90
===================================================================
--- gcc/testsuite/gfortran.dg/pr78571.f90 (nonexistent)
+++ gcc/testsuite/gfortran.dg/pr78571.f90 (working copy)
@@ -0,0 +1,9 @@
+! { dg-do compile }
+! PR fortran/78571
+program p
+ type t
+ character :: c
+ end type
+ character :: x = t('a') ! { dg-error "convert TYPE" }
+ data x /'b'/
+end