This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [Patch, fortran] PR32903 - [regression] Default initializer and intent(OUT): default initializer not used
- From: Tobias Burnus <burnus at net-b dot de>
- Cc: Fortran List <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 27 Jul 2007 11:53:31 +0200
- Subject: Re: [Patch, fortran] PR32903 - [regression] Default initializer and intent(OUT): default initializer not used
- References: <46A9B5C8.7040106@wanadoo.fr>
Paul Thomas wrote:
> I have committed a patch for this as 'obvious'. It was a regression
> that I caused by forgetting to set intent(out) derived types, to which
> the default initializer is applied, as referenced. The patch is a one
> and a half liner.
Thanks. I now added also the test case to make sure it will never regress.
Tobias
My Patch:
Index: gcc/testsuite/ChangeLog
===================================================================
--- gcc/testsuite/ChangeLog (Revision 126974)
+++ gcc/testsuite/ChangeLog (Arbeitskopie)
@@ -1,3 +1,8 @@
+2007-07-27 Tobias Burnus <burnus@net-b.de>
+
+ PR fortran/32903
+ * gfortran.dg/initialization_11.f90: New test.
+
2007-07-27 Richard Sandiford <richard@codesourcery.com>
* gcc.target/mips/ins-1.c: New test.
Index: gcc/testsuite/gfortran.dg/initialization_11.f90
===================================================================
--- gcc/testsuite/gfortran.dg/initialization_11.f90 (Revision 0)
+++ gcc/testsuite/gfortran.dg/initialization_11.f90 (Revision 0)
@@ -0,0 +1,20 @@
+! { dg-do run }
+! PR fortran/32903
+!
+program test
+ implicit none
+ type data_type
+ integer :: i=2
+ end type data_type
+ type(data_type) :: d
+ d%i = 4
+ call set(d)
+ if(d%i /= 2) then
+ print *, 'Expect: 2, got: ', d%i
+ call abort()
+ end if
+contains
+ subroutine set(x1)
+ type(data_type),intent(out):: x1
+ end subroutine set
+end program test
Paul's patch:
Index: gcc/fortran/ChangeLog
===================================================================
--- gcc/fortran/ChangeLog (Revision 126973)
+++ gcc/fortran/ChangeLog (Revision 126974)
@@ -1,10 +1,17 @@
+2007-07-27 Paul Thomas <pault@gcc.gnu.org>
+
+ PR fortran/32903
+ * trans-decl.c (gfc_trans_deferred_vars): Set intent(out)
+ derived types as referenced, if they have the the default
+ initializer set.
+
Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c (Revision 126973)
+++ gcc/fortran/trans-decl.c (Revision 126974)
@@ -2735,8 +2735,7 @@ gfc_trans_deferred_vars (gfc_symbol * pr
/* If an INTENT(OUT) dummy of derived type has a default
initializer, it must be initialized here. */
- if (f->sym && f->sym->attr.referenced
- && f->sym->attr.intent == INTENT_OUT
+ if (f->sym && f->sym->attr.intent == INTENT_OUT
&& f->sym->ts.type == BT_DERIVED
&& !f->sym->ts.derived->attr.alloc_comp
&& f->sym->value)
@@ -2744,6 +2743,7 @@ gfc_trans_deferred_vars (gfc_symbol * pr
gfc_expr *tmpe;
tree tmp, present;
gcc_assert (!f->sym->attr.allocatable);
+ gfc_set_sym_referenced (f->sym);
tmpe = gfc_lval_expr_from_sym (f->sym);
tmp = gfc_trans_assignment (tmpe, f->sym->value, false);