public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, Fortran, 71623, v1][5/6/7 Regression] Segfault when allocating deferred-length characters to size of a pointer
@ 2016-06-29 16:43 Andre Vehreschild
  2016-07-04 11:50 ` [Ping, Patch, " Andre Vehreschild
  0 siblings, 1 reply; 5+ messages in thread
From: Andre Vehreschild @ 2016-06-29 16:43 UTC (permalink / raw)
  To: GCC-Fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 521 bytes --]

Hi all,

the attached patch fixes the regression at least for trunk (I haven't
checked the others, but for 6 it should do either, 5 may need a little
bit more work). The issue here is that computing the typespec involved
code in se.pre that was not merged to the parent block.

Bootstrapped and regtested on x86_64-linux-gnu/F23? Ok for trunk?

I promise to do a backport to gcc-6 and -5 next week, once this patch
has been lifing in trunk a few days.

Regards,
	Andre
-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: pr71623_1.clog --]
[-- Type: text/plain, Size: 347 bytes --]

gcc/fortran/ChangeLog:

2016-06-28  Andre Vehreschild  <vehre@gcc.gnu.org>

	PR fortran/71623
	* trans-stmt.c (gfc_trans_allocate): Add code of pre block of typespec
	in allocate to parent block.

gcc/testsuite/ChangeLog:

2016-06-28  Andre Vehreschild  <vehre@gcc.gnu.org>

	PR fortran/71623
	* gfortran.dg/deferred_character_17.f90: New test.



[-- Attachment #3: pr71623_1.patch --]
[-- Type: text/x-patch, Size: 2517 bytes --]

diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 84bf749..5aa7778 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -5696,9 +5696,11 @@ gfc_trans_allocate (gfc_code * code)
 	  tmp = gfc_get_char_type (code->ext.alloc.ts.kind);
 	  tmp = TYPE_SIZE_UNIT (tmp);
 	  tmp = fold_convert (TREE_TYPE (se_sz.expr), tmp);
+	  gfc_add_block_to_block (&block, &se_sz.pre);
 	  expr3_esize = fold_build2_loc (input_location, MULT_EXPR,
 					 TREE_TYPE (se_sz.expr),
 					 tmp, se_sz.expr);
+	  expr3_esize = gfc_evaluate_now (expr3_esize, &block);
 	}
     }
 
@@ -5897,6 +5899,7 @@ gfc_trans_allocate (gfc_code * code)
 		 source= or mold= expression.  */
 	      gfc_init_se (&se_sz, NULL);
 	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+	      gfc_add_block_to_block (&block, &se_sz.pre);
 	      gfc_add_modify (&block, al_len,
 			      fold_convert (TREE_TYPE (al_len),
 					    se_sz.expr));
@@ -5981,11 +5984,19 @@ gfc_trans_allocate (gfc_code * code)
 		 specified by a type spec for deferred length character
 		 arrays or unlimited polymorphic objects without a
 		 source= or mold= expression.  */
-	      gfc_init_se (&se_sz, NULL);
-	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
-	      gfc_add_modify (&block, al_len,
-			      fold_convert (TREE_TYPE (al_len),
-					    se_sz.expr));
+	      if (expr3_esize == NULL_TREE || code->ext.alloc.ts.kind != 1)
+		{
+		  gfc_init_se (&se_sz, NULL);
+		  gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+		  gfc_add_block_to_block (&block, &se_sz.pre);
+		  gfc_add_modify (&block, al_len,
+				  fold_convert (TREE_TYPE (al_len),
+						se_sz.expr));
+		}
+	      else
+		gfc_add_modify (&block, al_len,
+				fold_convert (TREE_TYPE (al_len),
+					      expr3_esize));
 	    }
 	  else
 	    /* No length information needed, because type to allocate
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_17.f90 b/gcc/testsuite/gfortran.dg/deferred_character_17.f90
new file mode 100644
index 0000000..5a9d725
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/deferred_character_17.f90
@@ -0,0 +1,13 @@
+!{ dg-do run }
+
+! Check fix for PR fortran/71623
+
+program allocatemvce
+  implicit none
+  character(len=:), allocatable :: string
+  integer, dimension(4), target :: array = [1,2,3,4]
+  integer, dimension(:), pointer :: array_ptr
+  array_ptr => array
+  ! The allocate used to segfault
+  allocate(character(len=size(array_ptr))::string)
+end program allocatemvce

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Ping, Patch, Fortran, 71623, v1][5/6/7 Regression] Segfault when allocating deferred-length characters to size of a pointer
  2016-06-29 16:43 [Patch, Fortran, 71623, v1][5/6/7 Regression] Segfault when allocating deferred-length characters to size of a pointer Andre Vehreschild
@ 2016-07-04 11:50 ` Andre Vehreschild
  2016-07-04 16:01   ` Jerry DeLisle
  0 siblings, 1 reply; 5+ messages in thread
From: Andre Vehreschild @ 2016-07-04 11:50 UTC (permalink / raw)
  To: GCC-Fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 819 bytes --]

Ping!

Additionally did I get the time to check the patch for gcc-6 and -5. It
applies cleanly to both and has no regressions. Ok for trunk and with
one week delay for gcc-6 and -5?

- Andre

On Wed, 29 Jun 2016 18:43:27 +0200
Andre Vehreschild <vehre@gmx.de> wrote:

> Hi all,
> 
> the attached patch fixes the regression at least for trunk (I haven't
> checked the others, but for 6 it should do either, 5 may need a little
> bit more work). The issue here is that computing the typespec involved
> code in se.pre that was not merged to the parent block.
> 
> Bootstrapped and regtested on x86_64-linux-gnu/F23? Ok for trunk?
> 
> I promise to do a backport to gcc-6 and -5 next week, once this patch
> has been lifing in trunk a few days.
> 
> Regards,
> 	Andre


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: pr71623_1.patch --]
[-- Type: text/x-patch, Size: 2517 bytes --]

diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index 84bf749..5aa7778 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -5696,9 +5696,11 @@ gfc_trans_allocate (gfc_code * code)
 	  tmp = gfc_get_char_type (code->ext.alloc.ts.kind);
 	  tmp = TYPE_SIZE_UNIT (tmp);
 	  tmp = fold_convert (TREE_TYPE (se_sz.expr), tmp);
+	  gfc_add_block_to_block (&block, &se_sz.pre);
 	  expr3_esize = fold_build2_loc (input_location, MULT_EXPR,
 					 TREE_TYPE (se_sz.expr),
 					 tmp, se_sz.expr);
+	  expr3_esize = gfc_evaluate_now (expr3_esize, &block);
 	}
     }
 
@@ -5897,6 +5899,7 @@ gfc_trans_allocate (gfc_code * code)
 		 source= or mold= expression.  */
 	      gfc_init_se (&se_sz, NULL);
 	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+	      gfc_add_block_to_block (&block, &se_sz.pre);
 	      gfc_add_modify (&block, al_len,
 			      fold_convert (TREE_TYPE (al_len),
 					    se_sz.expr));
@@ -5981,11 +5984,19 @@ gfc_trans_allocate (gfc_code * code)
 		 specified by a type spec for deferred length character
 		 arrays or unlimited polymorphic objects without a
 		 source= or mold= expression.  */
-	      gfc_init_se (&se_sz, NULL);
-	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
-	      gfc_add_modify (&block, al_len,
-			      fold_convert (TREE_TYPE (al_len),
-					    se_sz.expr));
+	      if (expr3_esize == NULL_TREE || code->ext.alloc.ts.kind != 1)
+		{
+		  gfc_init_se (&se_sz, NULL);
+		  gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+		  gfc_add_block_to_block (&block, &se_sz.pre);
+		  gfc_add_modify (&block, al_len,
+				  fold_convert (TREE_TYPE (al_len),
+						se_sz.expr));
+		}
+	      else
+		gfc_add_modify (&block, al_len,
+				fold_convert (TREE_TYPE (al_len),
+					      expr3_esize));
 	    }
 	  else
 	    /* No length information needed, because type to allocate
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_17.f90 b/gcc/testsuite/gfortran.dg/deferred_character_17.f90
new file mode 100644
index 0000000..5a9d725
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/deferred_character_17.f90
@@ -0,0 +1,13 @@
+!{ dg-do run }
+
+! Check fix for PR fortran/71623
+
+program allocatemvce
+  implicit none
+  character(len=:), allocatable :: string
+  integer, dimension(4), target :: array = [1,2,3,4]
+  integer, dimension(:), pointer :: array_ptr
+  array_ptr => array
+  ! The allocate used to segfault
+  allocate(character(len=size(array_ptr))::string)
+end program allocatemvce

[-- Attachment #3: pr71623_1.clog --]
[-- Type: text/plain, Size: 347 bytes --]

gcc/fortran/ChangeLog:

2016-06-28  Andre Vehreschild  <vehre@gcc.gnu.org>

	PR fortran/71623
	* trans-stmt.c (gfc_trans_allocate): Add code of pre block of typespec
	in allocate to parent block.

gcc/testsuite/ChangeLog:

2016-06-28  Andre Vehreschild  <vehre@gcc.gnu.org>

	PR fortran/71623
	* gfortran.dg/deferred_character_17.f90: New test.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Ping, Patch, Fortran, 71623, v1][5/6/7 Regression] Segfault when allocating deferred-length characters to size of a pointer
  2016-07-04 11:50 ` [Ping, Patch, " Andre Vehreschild
@ 2016-07-04 16:01   ` Jerry DeLisle
  2016-07-05 12:08     ` Andre Vehreschild
  0 siblings, 1 reply; 5+ messages in thread
From: Jerry DeLisle @ 2016-07-04 16:01 UTC (permalink / raw)
  To: fortran

On 07/04/2016 04:49 AM, Andre Vehreschild wrote:
> Ping!
>
> Additionally did I get the time to check the patch for gcc-6 and -5. It
> applies cleanly to both and has no regressions. Ok for trunk and with
> one week delay for gcc-6 and -5?
>


  OK, OK and OK! Thanks for your work.

Jerry

> - Andre
>
> On Wed, 29 Jun 2016 18:43:27 +0200
> Andre Vehreschild <vehre@gmx.de> wrote:
>
>> Hi all,
>>
>> the attached patch fixes the regression at least for trunk (I haven't
>> checked the others, but for 6 it should do either, 5 may need a little
>> bit more work). The issue here is that computing the typespec involved
>> code in se.pre that was not merged to the parent block.
>>
>> Bootstrapped and regtested on x86_64-linux-gnu/F23? Ok for trunk?
>>
>> I promise to do a backport to gcc-6 and -5 next week, once this patch
>> has been lifing in trunk a few days.
>>
>> Regards,
>> 	Andre
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Ping, Patch, Fortran, 71623, v1][5/6/7 Regression] Segfault when allocating deferred-length characters to size of a pointer
  2016-07-04 16:01   ` Jerry DeLisle
@ 2016-07-05 12:08     ` Andre Vehreschild
  2016-07-13 17:33       ` Andre Vehreschild
  0 siblings, 1 reply; 5+ messages in thread
From: Andre Vehreschild @ 2016-07-05 12:08 UTC (permalink / raw)
  To: Jerry DeLisle; +Cc: fortran

[-- Attachment #1: Type: text/plain, Size: 1255 bytes --]

Hi Jerry,

thanks for the kind review. Committed to trunk as r238002. I will wait
one week before applying to gcc-6/5.

Thanks again,
	Andre

On Mon, 4 Jul 2016 09:01:07 -0700
Jerry DeLisle <jvdelisle@charter.net> wrote:

> On 07/04/2016 04:49 AM, Andre Vehreschild wrote:
> > Ping!
> >
> > Additionally did I get the time to check the patch for gcc-6 and
> > -5. It applies cleanly to both and has no regressions. Ok for trunk
> > and with one week delay for gcc-6 and -5?
> >  
> 
> 
>   OK, OK and OK! Thanks for your work.
> 
> Jerry
> 
> > - Andre
> >
> > On Wed, 29 Jun 2016 18:43:27 +0200
> > Andre Vehreschild <vehre@gmx.de> wrote:
> >  
> >> Hi all,
> >>
> >> the attached patch fixes the regression at least for trunk (I
> >> haven't checked the others, but for 6 it should do either, 5 may
> >> need a little bit more work). The issue here is that computing the
> >> typespec involved code in se.pre that was not merged to the parent
> >> block.
> >>
> >> Bootstrapped and regtested on x86_64-linux-gnu/F23? Ok for trunk?
> >>
> >> I promise to do a backport to gcc-6 and -5 next week, once this
> >> patch has been lifing in trunk a few days.
> >>
> >> Regards,
> >> 	Andre  
> >
> >  
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 3368 bytes --]

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 238001)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,9 @@
+2016-07-05  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/71623
+	* trans-stmt.c (gfc_trans_allocate): Add code of pre block of typespec
+	in allocate to parent block.
+
 2016-07-04  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
 	PR fortran/66575
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c	(Revision 238001)
+++ gcc/fortran/trans-stmt.c	(Arbeitskopie)
@@ -5696,9 +5696,11 @@
 	  tmp = gfc_get_char_type (code->ext.alloc.ts.kind);
 	  tmp = TYPE_SIZE_UNIT (tmp);
 	  tmp = fold_convert (TREE_TYPE (se_sz.expr), tmp);
+	  gfc_add_block_to_block (&block, &se_sz.pre);
 	  expr3_esize = fold_build2_loc (input_location, MULT_EXPR,
 					 TREE_TYPE (se_sz.expr),
 					 tmp, se_sz.expr);
+	  expr3_esize = gfc_evaluate_now (expr3_esize, &block);
 	}
     }
 
@@ -5897,6 +5899,7 @@
 		 source= or mold= expression.  */
 	      gfc_init_se (&se_sz, NULL);
 	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+	      gfc_add_block_to_block (&block, &se_sz.pre);
 	      gfc_add_modify (&block, al_len,
 			      fold_convert (TREE_TYPE (al_len),
 					    se_sz.expr));
@@ -5981,11 +5984,19 @@
 		 specified by a type spec for deferred length character
 		 arrays or unlimited polymorphic objects without a
 		 source= or mold= expression.  */
-	      gfc_init_se (&se_sz, NULL);
-	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
-	      gfc_add_modify (&block, al_len,
-			      fold_convert (TREE_TYPE (al_len),
-					    se_sz.expr));
+	      if (expr3_esize == NULL_TREE || code->ext.alloc.ts.kind != 1)
+		{
+		  gfc_init_se (&se_sz, NULL);
+		  gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+		  gfc_add_block_to_block (&block, &se_sz.pre);
+		  gfc_add_modify (&block, al_len,
+				  fold_convert (TREE_TYPE (al_len),
+						se_sz.expr));
+		}
+	      else
+		gfc_add_modify (&block, al_len,
+				fold_convert (TREE_TYPE (al_len),
+					      expr3_esize));
 	    }
 	  else
 	    /* No length information needed, because type to allocate
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 238001)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@
+2016-07-05  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	PR fortran/71623
+	* gfortran.dg/deferred_character_17.f90: New test.
+
 2016-07-05  Christophe Lyon  <christophe.lyon@linaro.org>
 
 	* gcc.target/arm/neon/polytypes.c: Move to ...
Index: gcc/testsuite/gfortran.dg/deferred_character_17.f90
===================================================================
--- gcc/testsuite/gfortran.dg/deferred_character_17.f90	(nicht existent)
+++ gcc/testsuite/gfortran.dg/deferred_character_17.f90	(Arbeitskopie)
@@ -0,0 +1,13 @@
+!{ dg-do run }
+
+! Check fix for PR fortran/71623
+
+program allocatemvce
+  implicit none
+  character(len=:), allocatable :: string
+  integer, dimension(4), target :: array = [1,2,3,4]
+  integer, dimension(:), pointer :: array_ptr
+  array_ptr => array
+  ! The allocate used to segfault
+  allocate(character(len=size(array_ptr))::string)
+end program allocatemvce

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Ping, Patch, Fortran, 71623, v1][5/6/7 Regression] Segfault when allocating deferred-length characters to size of a pointer
  2016-07-05 12:08     ` Andre Vehreschild
@ 2016-07-13 17:33       ` Andre Vehreschild
  0 siblings, 0 replies; 5+ messages in thread
From: Andre Vehreschild @ 2016-07-13 17:33 UTC (permalink / raw)
  To: Jerry DeLisle; +Cc: fortran

[-- Attachment #1: Type: text/plain, Size: 1570 bytes --]

Hi all,

backported to

gcc-6-branch as r238304, and
gcc-5-branch as r238308.

Thanks again for the review.

Regards,
	Andre

On Tue, 5 Jul 2016 14:07:45 +0200
Andre Vehreschild <vehre@gmx.de> wrote:

> Hi Jerry,
> 
> thanks for the kind review. Committed to trunk as r238002. I will wait
> one week before applying to gcc-6/5.
> 
> Thanks again,
> 	Andre
> 
> On Mon, 4 Jul 2016 09:01:07 -0700
> Jerry DeLisle <jvdelisle@charter.net> wrote:
> 
> > On 07/04/2016 04:49 AM, Andre Vehreschild wrote:  
> > > Ping!
> > >
> > > Additionally did I get the time to check the patch for gcc-6 and
> > > -5. It applies cleanly to both and has no regressions. Ok for
> > > trunk and with one week delay for gcc-6 and -5?
> > >    
> > 
> > 
> >   OK, OK and OK! Thanks for your work.
> > 
> > Jerry
> >   
> > > - Andre
> > >
> > > On Wed, 29 Jun 2016 18:43:27 +0200
> > > Andre Vehreschild <vehre@gmx.de> wrote:
> > >    
> > >> Hi all,
> > >>
> > >> the attached patch fixes the regression at least for trunk (I
> > >> haven't checked the others, but for 6 it should do either, 5 may
> > >> need a little bit more work). The issue here is that computing
> > >> the typespec involved code in se.pre that was not merged to the
> > >> parent block.
> > >>
> > >> Bootstrapped and regtested on x86_64-linux-gnu/F23? Ok for trunk?
> > >>
> > >> I promise to do a backport to gcc-6 and -5 next week, once this
> > >> patch has been lifing in trunk a few days.
> > >>
> > >> Regards,
> > >> 	Andre    
> > >
> > >    
> >   
> 
> 


-- 
Andre Vehreschild * Email: vehre ad gmx dot de 

[-- Attachment #2: submit-gcc-6.diff --]
[-- Type: text/x-patch, Size: 3397 bytes --]

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 238303)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,10 @@
+2016-07-13  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	Backport from trunk:
+	PR fortran/71623
+	* trans-stmt.c (gfc_trans_allocate): Add code of pre block of typespec
+	in allocate to parent block.
+
 2016-07-09  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
 	Backport from trunk:
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c	(Revision 238303)
+++ gcc/fortran/trans-stmt.c	(Arbeitskopie)
@@ -5694,9 +5694,11 @@
 	  tmp = gfc_get_char_type (code->ext.alloc.ts.kind);
 	  tmp = TYPE_SIZE_UNIT (tmp);
 	  tmp = fold_convert (TREE_TYPE (se_sz.expr), tmp);
+	  gfc_add_block_to_block (&block, &se_sz.pre);
 	  expr3_esize = fold_build2_loc (input_location, MULT_EXPR,
 					 TREE_TYPE (se_sz.expr),
 					 tmp, se_sz.expr);
+	  expr3_esize = gfc_evaluate_now (expr3_esize, &block);
 	}
     }
 
@@ -5895,6 +5897,7 @@
 		 source= or mold= expression.  */
 	      gfc_init_se (&se_sz, NULL);
 	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+	      gfc_add_block_to_block (&block, &se_sz.pre);
 	      gfc_add_modify (&block, al_len,
 			      fold_convert (TREE_TYPE (al_len),
 					    se_sz.expr));
@@ -5979,11 +5982,19 @@
 		 specified by a type spec for deferred length character
 		 arrays or unlimited polymorphic objects without a
 		 source= or mold= expression.  */
-	      gfc_init_se (&se_sz, NULL);
-	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
-	      gfc_add_modify (&block, al_len,
-			      fold_convert (TREE_TYPE (al_len),
-					    se_sz.expr));
+	      if (expr3_esize == NULL_TREE || code->ext.alloc.ts.kind != 1)
+		{
+		  gfc_init_se (&se_sz, NULL);
+		  gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+		  gfc_add_block_to_block (&block, &se_sz.pre);
+		  gfc_add_modify (&block, al_len,
+				  fold_convert (TREE_TYPE (al_len),
+						se_sz.expr));
+		}
+	      else
+		gfc_add_modify (&block, al_len,
+				fold_convert (TREE_TYPE (al_len),
+					      expr3_esize));
 	    }
 	  else
 	    /* No length information needed, because type to allocate
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 238303)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,9 @@
+2016-07-13  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	Backport from trunk:
+	PR fortran/71623
+	* gfortran.dg/deferred_character_17.f90: New test.
+
 2016-07-13  Ilya Enkovich  <ilya.enkovich@intel.com>
 
 	Backport from mainline r238086.
Index: gcc/testsuite/gfortran.dg/deferred_character_17.f90
===================================================================
--- gcc/testsuite/gfortran.dg/deferred_character_17.f90	(nicht existent)
+++ gcc/testsuite/gfortran.dg/deferred_character_17.f90	(Arbeitskopie)
@@ -0,0 +1,13 @@
+!{ dg-do run }
+
+! Check fix for PR fortran/71623
+
+program allocatemvce
+  implicit none
+  character(len=:), allocatable :: string
+  integer, dimension(4), target :: array = [1,2,3,4]
+  integer, dimension(:), pointer :: array_ptr
+  array_ptr => array
+  ! The allocate used to segfault
+  allocate(character(len=size(array_ptr))::string)
+end program allocatemvce

[-- Attachment #3: submit-gcc-5.diff --]
[-- Type: text/x-patch, Size: 3399 bytes --]

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 238304)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,10 @@
+2016-07-13  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	Backport from trunk:
+	PR fortran/71623
+	* trans-stmt.c (gfc_trans_allocate): Add code of pre block of typespec
+	in allocate to parent block.
+
 2016-07-11  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
 	Backport from trunk:
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c	(Revision 238304)
+++ gcc/fortran/trans-stmt.c	(Arbeitskopie)
@@ -5651,9 +5651,11 @@
 	  tmp = gfc_get_char_type (code->ext.alloc.ts.kind);
 	  tmp = TYPE_SIZE_UNIT (tmp);
 	  tmp = fold_convert (TREE_TYPE (se_sz.expr), tmp);
+	  gfc_add_block_to_block (&block, &se_sz.pre);
 	  expr3_esize = fold_build2_loc (input_location, MULT_EXPR,
 					 TREE_TYPE (se_sz.expr),
 					 tmp, se_sz.expr);
+	  expr3_esize = gfc_evaluate_now (expr3_esize, &block);
 	}
     }
 
@@ -5848,6 +5850,7 @@
 		 source= or mold= expression.  */
 	      gfc_init_se (&se_sz, NULL);
 	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+	      gfc_add_block_to_block (&block, &se_sz.pre);
 	      gfc_add_modify (&block, al_len,
 			      fold_convert (TREE_TYPE (al_len),
 					    se_sz.expr));
@@ -5932,11 +5935,19 @@
 		 specified by a type spec for deferred length character
 		 arrays or unlimited polymorphic objects without a
 		 source= or mold= expression.  */
-	      gfc_init_se (&se_sz, NULL);
-	      gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
-	      gfc_add_modify (&block, al_len,
-			      fold_convert (TREE_TYPE (al_len),
-					    se_sz.expr));
+	      if (expr3_esize == NULL_TREE || code->ext.alloc.ts.kind != 1)
+		{
+		  gfc_init_se (&se_sz, NULL);
+		  gfc_conv_expr (&se_sz, code->ext.alloc.ts.u.cl->length);
+		  gfc_add_block_to_block (&block, &se_sz.pre);
+		  gfc_add_modify (&block, al_len,
+				  fold_convert (TREE_TYPE (al_len),
+						se_sz.expr));
+		}
+	      else
+		gfc_add_modify (&block, al_len,
+				fold_convert (TREE_TYPE (al_len),
+					      expr3_esize));
 	    }
 	  else
 	    /* No length information needed, because type to allocate
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 238304)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,10 @@
+2016-07-13  Andre Vehreschild  <vehre@gcc.gnu.org>
+
+	Backport from trunk:
+	PR fortran/71623
+	* gfortran.dg/deferred_character_18.f90: New test.
+
+
 2016-07-12  Segher Boessenkool  <segher@kernel.crashing.org>
 
 	Backport from mainline
Index: gcc/testsuite/gfortran.dg/deferred_character_18.f90
===================================================================
--- gcc/testsuite/gfortran.dg/deferred_character_18.f90	(nicht existent)
+++ gcc/testsuite/gfortran.dg/deferred_character_18.f90	(Arbeitskopie)
@@ -0,0 +1,13 @@
+!{ dg-do run }
+
+! Check fix for PR fortran/71623
+
+program allocatemvce
+  implicit none
+  character(len=:), allocatable :: string
+  integer, dimension(4), target :: array = [1,2,3,4]
+  integer, dimension(:), pointer :: array_ptr
+  array_ptr => array
+  ! The allocate used to segfault
+  allocate(character(len=size(array_ptr))::string)
+end program allocatemvce

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-07-13 17:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-29 16:43 [Patch, Fortran, 71623, v1][5/6/7 Regression] Segfault when allocating deferred-length characters to size of a pointer Andre Vehreschild
2016-07-04 11:50 ` [Ping, Patch, " Andre Vehreschild
2016-07-04 16:01   ` Jerry DeLisle
2016-07-05 12:08     ` Andre Vehreschild
2016-07-13 17:33       ` Andre Vehreschild

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).