Patchwork [Fortran] PR 47421 - Don't nullify allocatable scalar (character) dummy arguments

login
register
mail settings
Submitter Tobias Burnus
Date Jan. 23, 2011, 4 p.m.
Message ID <4D3C50B6.1090400@net-b.de>
Download mbox | patch
Permalink /patch/80065/
State New
Headers show

Comments

Tobias Burnus - Jan. 23, 2011, 4 p.m.
For scalar allocatable character strings with "LEN=<expr>", gfortran 
nullified the dummy and freed it on on exit.

The patch is simple: Don't do this.

Build and regtested on x86-64-linux.
OK for the trunk? What about 4.5?

Tobias
Jerry DeLisle - Jan. 23, 2011, 9:54 p.m.
On 01/23/2011 08:00 AM, Tobias Burnus wrote:
> For scalar allocatable character strings with "LEN=<expr>", gfortran nullified
> the dummy and freed it on on exit.
>
> The patch is simple: Don't do this.
>
> Build and regtested on x86-64-linux.
> OK for the trunk? What about 4.5?
>
> Tobias

This is OK, thanks,

Jerry

Patch

2011-01-23  Tobias Burnus  <burnus@net-b.de>

	PR fortran/47421
	* trans-decl.c (gfc_trans_deferred_vars): Do not nullify
	scalar allocatable dummy arguments.

2011-01-23  Tobias Burnus  <burnus@net-b.de>

	PR fortran/47421
	* gfortran.dg/allocatable_scalar_12.f90: New.

diff --git a/gcc/fortran/trans-decl.c b/gcc/fortran/trans-decl.c
index 254db76..5e3afbe 100644
--- a/gcc/fortran/trans-decl.c
+++ b/gcc/fortran/trans-decl.c
@@ -3304,9 +3304,10 @@  gfc_trans_deferred_vars (gfc_symbol * proc_sym, gfc_wrapped_block * block)
 	  if (sym_has_alloc_comp && !seen_trans_deferred_array)
 	    gfc_trans_deferred_array (sym, block);
 	}
-      else if (sym->attr.allocatable
-	       || (sym->ts.type == BT_CLASS
-		   && CLASS_DATA (sym)->attr.allocatable))
+      else if (!sym->attr.dummy
+		&& (sym->attr.allocatable
+		    || (sym->ts.type == BT_CLASS
+			&& CLASS_DATA (sym)->attr.allocatable)))
 	{
 	  if (!sym->attr.save)
 	    {
--- /dev/null	2011-01-14 07:32:07.372000004 +0100
+++ gcc/testsuite/gfortran.dg/allocatable_scalar_12.f90	2011-01-23 15:49:56.000000000 +0100
@@ -0,0 +1,30 @@ 
+! { dg-do run }
+!
+! PR fortran/47421
+!
+! Don't auto-deallocatable scalar character allocatables.
+!
+implicit none
+character(len=5), allocatable :: str
+allocate(str)
+str = '1bcde'
+if(str /= '1bcde') call abort()
+call sub(str,len(str))
+if(str /= '1bcde') call abort()
+call subOUT(str,len(str))
+if (len(str) /= 5) call abort()
+if(allocated(str)) call abort()
+contains
+  subroutine sub(x,n)
+     integer :: n
+     character(len=n), allocatable :: x
+     if(len(x) /= 5) call abort()
+     if(x /= '1bcde') call abort()
+  end subroutine sub
+  subroutine subOUT(x,n)
+     integer :: n
+     character(len=n), allocatable,intent(out) :: x
+     if(allocated(x)) call abort()
+     if(len(x) /= 5) call abort()
+  end subroutine subOUT
+end