public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Fortran, Patch, pr66911, gcc-5, v1] ICE on allocate character with source as a derived type component
@ 2016-04-03 15:34 Andre Vehreschild
  2016-04-03 19:22 ` Jerry DeLisle
  0 siblings, 1 reply; 3+ messages in thread
From: Andre Vehreschild @ 2016-04-03 15:34 UTC (permalink / raw)
  To: GCC-Patches-ML, GCC-Fortran-ML

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

Hi all,

attached patch fixes the ICE when using a deferred length char array as
source= expression in an allocate for complicated source= expressions.
Before the patch the compiler was relying on having the string length
available in the ts of the expression, but when the expression is
sufficiently complicated it is not set there. In trunk the problem does
not arise, because the source= expression is evaluated in more cases.
In gcc-5 this is not available without doing a major rewrite of the
allocate() statement's conv-routine. Therefore this small portion of
extra code reliably does the trick and takes the string_length from the
se.string_length now.

Bootstrapped and regtested ok on x86_64-linux-gnu/F23. Ok for
gcc-5-branch?

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

[-- Attachment #2: pr66911_gcc-5_1.clog --]
[-- Type: application/octet-stream, Size: 392 bytes --]

gcc/fortran/ChangeLog:

2016-04-03  Andre Vehreschild  <vehre@gmx.de>

	PR fortran/66911
	* trans-stmt.c (gfc_trans_allocate): Get the deferred length of an
	expression by converting the expression when the length is not set
	in the symbol's ts.

gcc/testsuite/ChangeLog:

2016-04-03  Andre Vehreschild  <vehre@gmx.de>

	PR fortran/66911
	* gfortran.dg/deferred_character_16.f90: New test.



[-- Attachment #3: pr66911_gcc-5_1.patch --]
[-- Type: text/x-patch, Size: 1833 bytes --]

diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c
index b33bad7..25c2a0c 100644
--- a/gcc/fortran/trans-stmt.c
+++ b/gcc/fortran/trans-stmt.c
@@ -5536,14 +5536,23 @@ gfc_trans_allocate (gfc_code * code)
 	  if (expr3_len == NULL_TREE
 	      && code->expr3->ts.type == BT_CHARACTER)
 	    {
+	      gfc_init_se (&se, NULL);
 	      if (code->expr3->ts.u.cl
 		  && code->expr3->ts.u.cl->length)
 		{
-		  gfc_init_se (&se, NULL);
 		  gfc_conv_expr (&se, code->expr3->ts.u.cl->length);
 		  gfc_add_block_to_block (&block, &se.pre);
 		  expr3_len = gfc_evaluate_now (se.expr, &block);
 		}
+	      else
+		{
+		  /* The string_length is not set in the symbol, which prevents
+		     it being set in the ts.  Deduce it by converting expr3.  */
+		  gfc_conv_expr (&se, code->expr3);
+		  gfc_add_block_to_block (&block, &se.pre);
+		  gcc_assert (se.string_length);
+		  expr3_len = gfc_evaluate_now (se.string_length, &block);
+		}
 	      gcc_assert (expr3_len);
 	    }
 	  /* For character arrays only the kind's size is needed, because
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_16.f90 b/gcc/testsuite/gfortran.dg/deferred_character_16.f90
new file mode 100644
index 0000000..27fb112
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/deferred_character_16.f90
@@ -0,0 +1,24 @@
+! { dg-do run }
+
+program truc
+implicit none
+
+type t_env_table
+    character(len=:), allocatable :: key
+end type
+
+type(t_env_table), dimension(:), allocatable :: environment_table
+
+character(len=:), allocatable :: s
+
+allocate(environment_table(1))
+environment_table(1)%key='tt'
+
+allocate(s, source=environment_table(1)%key)
+
+if ( .not. allocated(s) ) call abort()
+if ( s /= "tt" ) call abort()
+if ( len(s) /= 2 ) call abort()
+!print *, 's:"', s, '" derived:"',environment_table(1)%key,'"'
+
+end program

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

* Re: [Fortran, Patch, pr66911, gcc-5, v1] ICE on allocate character with source as a derived type component
  2016-04-03 15:34 [Fortran, Patch, pr66911, gcc-5, v1] ICE on allocate character with source as a derived type component Andre Vehreschild
@ 2016-04-03 19:22 ` Jerry DeLisle
  2016-04-04  9:48   ` Andre Vehreschild
  0 siblings, 1 reply; 3+ messages in thread
From: Jerry DeLisle @ 2016-04-03 19:22 UTC (permalink / raw)
  To: Andre Vehreschild, GCC-Patches-ML, GCC-Fortran-ML

On 04/03/2016 08:33 AM, Andre Vehreschild wrote:
> Hi all,
> 
> attached patch fixes the ICE when using a deferred length char array as
> source= expression in an allocate for complicated source= expressions.
> Before the patch the compiler was relying on having the string length
> available in the ts of the expression, but when the expression is
> sufficiently complicated it is not set there. In trunk the problem does
> not arise, because the source= expression is evaluated in more cases.
> In gcc-5 this is not available without doing a major rewrite of the
> allocate() statement's conv-routine. Therefore this small portion of
> extra code reliably does the trick and takes the string_length from the
> se.string_length now.
> 
> Bootstrapped and regtested ok on x86_64-linux-gnu/F23. Ok for
> gcc-5-branch?
> 
> Regards,
> 	Andre
> 

Yes, OK

Thanks for your work.

Jerry

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

* Re: [Fortran, Patch, pr66911, gcc-5, v1] ICE on allocate character with source as a derived type component
  2016-04-03 19:22 ` Jerry DeLisle
@ 2016-04-04  9:48   ` Andre Vehreschild
  0 siblings, 0 replies; 3+ messages in thread
From: Andre Vehreschild @ 2016-04-04  9:48 UTC (permalink / raw)
  To: Jerry DeLisle; +Cc: GCC-Patches-ML, GCC-Fortran-ML

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

Hi Jerry,

thank you for the review. Committed as r234712 to gcc-5-branch.

Regards,
	Andre

On Sun, 3 Apr 2016 12:22:31 -0700
Jerry DeLisle <jvdelisle@charter.net> wrote:

> On 04/03/2016 08:33 AM, Andre Vehreschild wrote:
> > Hi all,
> > 
> > attached patch fixes the ICE when using a deferred length char array as
> > source= expression in an allocate for complicated source= expressions.
> > Before the patch the compiler was relying on having the string length
> > available in the ts of the expression, but when the expression is
> > sufficiently complicated it is not set there. In trunk the problem does
> > not arise, because the source= expression is evaluated in more cases.
> > In gcc-5 this is not available without doing a major rewrite of the
> > allocate() statement's conv-routine. Therefore this small portion of
> > extra code reliably does the trick and takes the string_length from the
> > se.string_length now.
> > 
> > Bootstrapped and regtested ok on x86_64-linux-gnu/F23. Ok for
> > gcc-5-branch?
> > 
> > Regards,
> > 	Andre
> >   
> 
> Yes, OK
> 
> Thanks for your work.
> 
> Jerry


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

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

Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog	(Revision 234711)
+++ gcc/fortran/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,10 @@
+2016-04-04  Andre Vehreschild  <vehre@gmx.de>
+
+	PR fortran/66911
+	* trans-stmt.c (gfc_trans_allocate): Get the deferred length of an
+	expression by converting the expression when the length is not set
+	in the symbol's ts.
+
 2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>
 
 	PR fortran/65795
Index: gcc/fortran/trans-stmt.c
===================================================================
--- gcc/fortran/trans-stmt.c	(Revision 234710)
+++ gcc/fortran/trans-stmt.c	(Arbeitskopie)
@@ -5536,14 +5536,23 @@
 	  if (expr3_len == NULL_TREE
 	      && code->expr3->ts.type == BT_CHARACTER)
 	    {
+	      gfc_init_se (&se, NULL);
 	      if (code->expr3->ts.u.cl
 		  && code->expr3->ts.u.cl->length)
 		{
-		  gfc_init_se (&se, NULL);
 		  gfc_conv_expr (&se, code->expr3->ts.u.cl->length);
 		  gfc_add_block_to_block (&block, &se.pre);
 		  expr3_len = gfc_evaluate_now (se.expr, &block);
 		}
+	      else
+		{
+		  /* The string_length is not set in the symbol, which prevents
+		     it being set in the ts.  Deduce it by converting expr3.  */
+		  gfc_conv_expr (&se, code->expr3);
+		  gfc_add_block_to_block (&block, &se.pre);
+		  gcc_assert (se.string_length);
+		  expr3_len = gfc_evaluate_now (se.string_length, &block);
+		}
 	      gcc_assert (expr3_len);
 	    }
 	  /* For character arrays only the kind's size is needed, because
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog	(Revision 234711)
+++ gcc/testsuite/ChangeLog	(Arbeitskopie)
@@ -1,3 +1,8 @@
+2016-04-04  Andre Vehreschild  <vehre@gmx.de>
+
+	PR fortran/66911
+	* gfortran.dg/deferred_character_16.f90: New test.
+
 2016-04-04  Andre Vehreschild  <vehre@gcc.gnu.org>
 
 	PR fortran/65795
Index: gcc/testsuite/gfortran.dg/deferred_character_16.f90
===================================================================
--- gcc/testsuite/gfortran.dg/deferred_character_16.f90	(nicht existent)
+++ gcc/testsuite/gfortran.dg/deferred_character_16.f90	(Arbeitskopie)
@@ -0,0 +1,24 @@
+! { dg-do run }
+
+program truc
+implicit none
+
+type t_env_table
+    character(len=:), allocatable :: key
+end type
+
+type(t_env_table), dimension(:), allocatable :: environment_table
+
+character(len=:), allocatable :: s
+
+allocate(environment_table(1))
+environment_table(1)%key='tt'
+
+allocate(s, source=environment_table(1)%key)
+
+if ( .not. allocated(s) ) call abort()
+if ( s /= "tt" ) call abort()
+if ( len(s) /= 2 ) call abort()
+!print *, 's:"', s, '" derived:"',environment_table(1)%key,'"'
+
+end program

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

end of thread, other threads:[~2016-04-04  9:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-03 15:34 [Fortran, Patch, pr66911, gcc-5, v1] ICE on allocate character with source as a derived type component Andre Vehreschild
2016-04-03 19:22 ` Jerry DeLisle
2016-04-04  9:48   ` 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).