PR fortran/78571 -- Avoid ICE in invalid CHARACTER initialization

Message ID 20180608001624.GA55065@troutmask.apl.washington.edu
State New
Headers show
Series
  • PR fortran/78571 -- Avoid ICE in invalid CHARACTER initialization
Related show

Commit Message

Steve Kargl June 8, 2018, 12:16 a.m.
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

Comments

Thomas König June 8, 2018, 7:01 p.m. | #1
Hi Steve,

> Regression tested on x86_64-*-freebsd.  OK to commit?


OK, and thanks!

	Thomas
Steve Kargl June 8, 2018, 7:12 p.m. | #2
On Fri, Jun 08, 2018 at 09:01:11PM +0200, Thomas König wrote:
> > Regression tested on x86_64-*-freebsd.  OK to commit?

> 

> OK, and thanks!

> 


Thanks.  Committed to trunk.

-- 
Steve

Patch

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