Patchwork [fortran] PR46678 Wrong code with strings

login
register
mail settings
Submitter Jerry DeLisle
Date Nov. 27, 2010, 11:57 p.m.
Message ID <4CF19B05.3060201@frontier.com>
Download mbox | patch
Permalink /patch/73306/
State New
Headers show

Comments

Jerry DeLisle - Nov. 27, 2010, 11:57 p.m.
Hi all,

This patch is simple and obvious.  Credit goes to Tobias for the idea.  I 
tracked down the correct function to put this and fixed up a test case.

Regression tested on x86-64-linux-gnu.

As a side note, I tested changing all cases of gfc_start_block with 
gfc_init_block in trans-decl.c and also got no regressions.  I leave that idea 
for later discussion.

Test case attached.

OK for Trunk?

Jerry

2010-11-27  Tobias Burnus  <burnus@net-b.de>
	    Jerry DeLisle  <jvdelisle@gcc.gnu.org>

	PR fortran/46678
	trans-decl.c (gfc_trans_auto_character_variable): Use gfc_init_block
	instead of gfc_start_block.
! { dg-do run }
! PR46678 Wrong code with strings
! Test case prepared by Jerry DeLisle  <jvdelisle@gcc.gnu.org>
program test
   implicit none
   integer a(2)
   call sub(a,5)
end program test

subroutine sub(a,n)
   implicit none
   integer n
   integer a(n)
   character(25) :: results
   character(size(a)) :: string
   print *, size(a)
   string = '1234567890'
   write(results,'(a)') string
   if (results.ne.'12345') call abort
end subroutine sub
Steve Kargl - Nov. 28, 2010, 12:23 a.m.
On Sat, Nov 27, 2010 at 03:57:57PM -0800, Jerry DeLisle wrote:
> Hi all,
> 
> This patch is simple and obvious.  Credit goes to Tobias for the idea.  I 
> tracked down the correct function to put this and fixed up a test case.
> 
> Regression tested on x86-64-linux-gnu.
> 
> As a side note, I tested changing all cases of gfc_start_block with 
> gfc_init_block in trans-decl.c and also got no regressions.  I leave that 
> idea for later discussion.
> 
> Test case attached.
> 
> OK for Trunk?
> 

OK

Patch

Index: trans-decl.c
===================================================================
--- trans-decl.c	(revision 167208)
+++ trans-decl.c	(working copy)
@@ -2952,7 +2968,7 @@  gfc_trans_auto_character_variable (gfc_symbol * sy
   gcc_assert (sym->backend_decl);
   gcc_assert (sym->ts.u.cl && sym->ts.u.cl->length);
 
-  gfc_start_block (&init);
+  gfc_init_block (&init);
 
   /* Evaluate the string length expression.  */
   gfc_conv_string_length (sym->ts.u.cl, NULL, &init);