diff mbox

[Fortran,PR72698,v1,5/6/7,Regression] ICE in lhd_incomplete_type_error, at langhooks.c:205

Message ID 20160811095827.2eb0de57@vepi2
State New
Headers show

Commit Message

Andre Vehreschild Aug. 11, 2016, 7:58 a.m. UTC
Hi all,

committed to gcc-6-branch as r239352 to catch the next release.

And while on it to gcc-5-branch as r239353.

Regards,
	Andre

On Mon, 8 Aug 2016 11:49:54 +0200
Andre Vehreschild <vehre@gmx.de> wrote:

> Hi Thomas,
> 
> thanks for the review. I have changed the test to run and result check
> as requested. Committed to trunk as r239236.
> 
> Will commit to gcc-6 and -5-branch in one week.
> 
> Regards,
> 	Andre
> 
> On Mon, 8 Aug 2016 08:42:08 +0200
> Thomas Koenig <tkoenig@netcologne.de> wrote:
> 
> > Am 07.08.2016 um 13:52 schrieb Andre Vehreschild:
> > Hi Andre,
> >   
> > > attached patch fixes the ICE caused by a zero-sized string.
> > > Assigning that string to a temporary variable obviously did not
> > > work out. The patch fixes this by checking for zero-sized strings
> > > in SOURCE= and not producing the code to assign "nothing" to the
> > > temporary variable and later to the allocated memory. The version
> > > for gcc-5 had to be adapted slightly, because the version of the
> > > ALLOCATE() implementation is way behind.
> > >
> > > Bootstrapped and regtested on x86_64-linux-gnu/F23. Ok for trunk,
> > > gcc-6 and gcc-5?    
> > 
> > Looks good.
> > 
> > With the test case, you might consider changing that into a runtime
> > test to make sure that the correct result is obtained.
> > 
> > So, OK with that change.
> > 
> > Regards
> > 
> > 	Thomas
> >   
> 
>
diff mbox

Patch

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 239352)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,10 @@ 
+2016-08-11  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	Backport from trunk:
+	PR fortran/72698
+	* trans-stmt.c (gfc_trans_allocate): Prevent generating code for
+	copy of zero sized string and with it an ICE.
+
 2016-08-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
 	Backport from trunk
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c	(Revision 239352)
+++ gcc/fortran/trans-stmt.c	(Arbeitskopie)
@@ -5303,7 +5303,8 @@ 
   stmtblock_t block;
   stmtblock_t post;
   tree nelems;
-  bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set;
+  bool upoly_expr, tmp_expr3_len_flag = false, al_len_needs_set,
+      do_assign = true;
   gfc_symtree *newsym = NULL;
 
   if (!code->ext.alloc.list)
@@ -5393,6 +5394,14 @@ 
 		  expr3_len = se.string_length;
 		  gfc_add_block_to_block (&block, &se.pre);
 		  gfc_add_block_to_block (&post, &se.post);
+		  /* Special case when string in expr3 is zero.  */
+		  if (code->expr3->ts.type == BT_CHARACTER
+		      && integer_zerop (se.string_length))
+		    {
+		      expr3 = expr3_tmp = NULL_TREE;
+		      expr3_len = integer_zero_node;
+		      do_assign = false;
+		    }
 		}
 	      /* else expr3 = NULL_TREE set above.  */
 	    }
@@ -5415,8 +5424,17 @@ 
 	      gfc_add_block_to_block (&block, &se.pre);
 	      gfc_add_block_to_block (&post, &se.post);
 
-	      if (!VAR_P (se.expr))
+	      /* Special case when string in expr3 is zero.  */
+	      if (code->expr3->ts.type == BT_CHARACTER
+		  && integer_zerop (se.string_length))
 		{
+		  gfc_init_se (&se, NULL);
+		  expr3_len = integer_zero_node;
+		  tmp = NULL_TREE;
+		  do_assign = false;
+		}
+	      else if (!VAR_P (se.expr))
+		{
 		  tree var;
 
 		  tmp = is_coarray ? se.expr
@@ -5956,7 +5974,7 @@ 
 			    fold_convert (TREE_TYPE (al_len),
 					  integer_zero_node));
 	}
-      if (code->expr3 && !code->expr3->mold)
+      if (code->expr3 && !code->expr3->mold && do_assign)
 	{
 	  /* Initialization via SOURCE block
 	     (or static default initializer).  */
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 239352)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,9 @@ 
+2016-08-11  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	Backport from trunk:
+	PR fortran/72698
+	* gfortran.dg/allocate_with_source_20.f03: New test.
+
 2016-08-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
 	Backport from trunk
Index: gcc/testsuite/gfortran.dg/allocate_with_source_20.f03
===================================================================
--- gcc/testsuite/gfortran.dg/allocate_with_source_20.f03	(nicht existent)
+++ gcc/testsuite/gfortran.dg/allocate_with_source_20.f03	(Arbeitskopie)
@@ -0,0 +1,21 @@ 
+! { dg-do run }
+
+! Check that PR72698 is fixed.
+! Contributed by Gerhard Steinmetz
+
+module m
+contains
+   integer function f()
+      f = 4
+   end
+end
+program p
+   use m
+   character(3), parameter :: c = 'abc'
+   character(:), allocatable :: z
+   allocate (z, source=repeat(c(2:1), f()))
+   if (len(z) /= 0) call abort()
+   if (z /= "") call abort()
+end
+
+