User account creation filtered due to spam.

Bug 32903 - [regression] Default initializer and intent(OUT): default initializer not used
Summary: [regression] Default initializer and intent(OUT): default initializer not used
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Paul Thomas
URL:
Keywords: wrong-code
Depends on:
Blocks: 32834
  Show dependency treegraph
 
Reported: 2007-07-26 10:03 UTC by Tobias Burnus
Modified: 2007-07-27 09:04 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2007-07-26 20:02:36


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2007-07-26 10:03:53 UTC
I found the following program on my disc; it might well belong to some PR, but I could not find it anywhere in bugzilla.
I think the program is valid; due to the default initializer, it should print "2" (as it does with g95, NAG f95, ifort, openf95), but gfortran prints "4".

The problem looks similar to PR31205 in so far that gfortran did the initialization in the caller and not in the called procedure.

Dump:
set (x1) {  (void) 0; }

d.i = 4;
set (&d);


program test
  implicit none
  type data_type
    integer :: i=2
  end type data_type
  type(data_type) :: d
  d%i = 4
  call set(d)
  print *, d%i
contains
  subroutine set(x1)
    type(data_type),intent(out):: x1
  end subroutine set
end program test
Comment 1 Paul Thomas 2007-07-26 19:27:24 UTC
(In reply to comment #0)

> The problem looks similar to PR31205 in so far that gfortran did the

Tobias,

This PR is caused by the patch for pr31205. If you reference x1 in set, for example by another print, it works correctly.  I think that I need to set the symbol as referenced and to update the references.

Thanks

Paul
Comment 2 Paul Thomas 2007-07-26 20:02:36 UTC
This is fixed by:

Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c    (revision 126885)
+++ gcc/fortran/trans-decl.c    (working copy)
@@ -2735,8 +2735,7 @@

       /* 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_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);

I'll regtest and check against cp2k before committing as obvious.

Paul
Comment 3 Paul Thomas 2007-07-27 09:03:55 UTC
Subject: Bug 32903

Author: pault
Date: Fri Jul 27 09:03:41 2007
New Revision: 126974

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126974
Log:
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.


Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c

Comment 4 Paul Thomas 2007-07-27 09:04:31 UTC
Fixed as obvious.

Paul
Comment 5 Tobias Burnus 2007-07-27 09:50:06 UTC
Subject: Bug 32903

Author: burnus
Date: Fri Jul 27 09:49:55 2007
New Revision: 126975

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126975
Log:
2007-07-27  Tobias Burnus  <burnus@net-b.de>

	PR fortran/32903
	* gfortran.dg/initialization_11.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/initialization_11.f90
Modified:
    trunk/gcc/testsuite/ChangeLog