public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/41479]  New: wrong code, mis-initialization
@ 2009-09-26 21:12 reuter at physik dot uni-freiburg dot de
  2009-09-26 21:14 ` [Bug fortran/41479] " reuter at physik dot uni-freiburg dot de
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: reuter at physik dot uni-freiburg dot de @ 2009-09-26 21:12 UTC (permalink / raw)
  To: gcc-bugs

The example below shows that besides the fact that declared as INTENT(OUT) the
component 'n' is not initialized per default the second time. This is demanded
by the FORTRAN standard. 
Example code:
program main

 type :: container_t
    integer :: n = 0
    ! if the following line is omitted, the problem disappears
    integer, dimension(:), allocatable :: a
 end type container_t

 type(container_t) :: container

 call init (container)
 print *, "Initial state:"
 call dump (container)

 container%n = 1
 print *, "Modified state:"
 call dump (container)

 call init (container)
 print *, "Initial state again:"
 call dump (container)

contains

 subroutine init (container)
   type(container_t), intent(out) :: container
 end subroutine init

 subroutine dump (container)
   type(container_t), intent(in) :: container
   print "(A,I0,1x,L)", "   value = ", container%n
 end subroutine dump

end program main


-- 
           Summary: wrong code, mis-initialization
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: blocker
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reuter at physik dot uni-freiburg dot de
 GCC build triplet: i386-32bit, MAC OS X Leopard
  GCC host triplet: i386-32bit, MAC OS X Leopard
GCC target triplet: i386-32bit, MAC OS X Leopard


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] wrong code, mis-initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
@ 2009-09-26 21:14 ` reuter at physik dot uni-freiburg dot de
  2009-09-27  0:50 ` jvdelisle at gcc dot gnu dot org
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: reuter at physik dot uni-freiburg dot de @ 2009-09-26 21:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from reuter at physik dot uni-freiburg dot de  2009-09-26 21:14 -------
Created an attachment (id=18661)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18661&action=view)
test case for the mis-initialization


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] wrong code, mis-initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
  2009-09-26 21:14 ` [Bug fortran/41479] " reuter at physik dot uni-freiburg dot de
@ 2009-09-27  0:50 ` jvdelisle at gcc dot gnu dot org
  2009-09-27  1:14 ` jvdelisle at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2009-09-27  0:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jvdelisle at gcc dot gnu dot org  2009-09-27 00:50 -------
gfortran is not considered release critical and so is never given a blocker
status.

Changing to normal.

Regarding the intent(out) issue.  I will defer to others.  


-- 

jvdelisle at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|blocker                     |normal


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] wrong code, mis-initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
  2009-09-26 21:14 ` [Bug fortran/41479] " reuter at physik dot uni-freiburg dot de
  2009-09-27  0:50 ` jvdelisle at gcc dot gnu dot org
@ 2009-09-27  1:14 ` jvdelisle at gcc dot gnu dot org
  2009-09-27 10:04 ` dominiq at lps dot ens dot fr
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jvdelisle at gcc dot gnu dot org @ 2009-09-27  1:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jvdelisle at gcc dot gnu dot org  2009-09-27 01:13 -------
The problem goes away if the allocatable specification is removed from the
declaration of 'a'

Problem also occurs on gfortran 4.3.0


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] wrong code, mis-initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (2 preceding siblings ...)
  2009-09-27  1:14 ` jvdelisle at gcc dot gnu dot org
@ 2009-09-27 10:04 ` dominiq at lps dot ens dot fr
  2009-09-27 17:03 ` [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization jv244 at cam dot ac dot uk
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: dominiq at lps dot ens dot fr @ 2009-09-27 10:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dominiq at lps dot ens dot fr  2009-09-27 10:04 -------
> Regarding the intent(out) issue.  I will defer to others.

If the issue is valid, this a [4.3/4.4/4.5 Regression]. On *-apple-darwin9 GCC
4.2.4 gives:

[ibook-dhum] f90/bug% gfc42 pr41479.f90
[ibook-dhum] f90/bug% a.out 
 Initial state:
   value = 0
 Modified state:
   value = 1
 Initial state again:
   value = 0


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (3 preceding siblings ...)
  2009-09-27 10:04 ` dominiq at lps dot ens dot fr
@ 2009-09-27 17:03 ` jv244 at cam dot ac dot uk
  2009-09-27 17:21 ` kargl at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jv244 at cam dot ac dot uk @ 2009-09-27 17:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jv244 at cam dot ac dot uk  2009-09-27 17:03 -------
target independent bug.


-- 

jv244 at cam dot ac dot uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |32834
              nThis|                            |
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
  GCC build triplet|i386-32bit, MAC OS X Leopard|
   GCC host triplet|i386-32bit, MAC OS X Leopard|
 GCC target triplet|i386-32bit, MAC OS X Leopard|
           Keywords|                            |wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2009-09-27 17:03:28
               date|                            |
            Summary|wrong code, mis-            |[4.3/4.4/4.5 Regression]
                   |initialization              |intent(out) for types with
                   |                            |default initialization
   Target Milestone|---                         |4.3.5


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (4 preceding siblings ...)
  2009-09-27 17:03 ` [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization jv244 at cam dot ac dot uk
@ 2009-09-27 17:21 ` kargl at gcc dot gnu dot org
  2009-09-27 18:19 ` kargl at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2009-09-27 17:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from kargl at gcc dot gnu dot org  2009-09-27 17:20 -------
(In reply to comment #0)
> The example below shows that besides the fact that declared as INTENT(OUT) the
> component 'n' is not initialized per default the second time.

It's not initialized on the first call to INIT(), either.

Form -fdump-tree-original 


init (struct container_t & restrict container)
{
  if (container != 0)
    {
      if (container->a.data != 0B)
        {
          __builtin_free ((void *) container->a.data);
        }
      container->a.data = 0B;
    }
}

There is no assignment here.  If we look at MAIN

MAIN__ ()
{
  static struct container_t container = {.n=4242};
  static void init (struct container_t & restrict);
  static void dump (struct container_t & restrict);

  container.a.data = 0B;
  {
    struct container_t D.1317;
    struct container_t container_t.1;

    container_t.1.n = 4242;
    container_t.1.a.data = 0B;
    D.1317 = container;
    container = container_t.1;
    if (D.1317.a.data != 0B)
      {
        __builtin_free ((void *) D.1317.a.data);
      }
    D.1317.a.data = 0B;
  }
  init (&container);
  dump (&container);
  container.n = 1;
  dump (&container);
  init (&container);

we see the n = 4242 (I changed the value to 4242) from the
original declaration statement.

On a side note, if

   integer, dimension(:), allocatable :: a

is replaced with

   integer, dimension(:), pointer :: a

we get

REMOVE:kargl[272] ./z
   value = 4242
   value = 1
   value = 4242

and -fdump-tree-original shows

init (struct container_t & restrict container)
{
  if (container != 0)
    {
      {
        struct container_t D.1311;
        struct container_t container_t.1;

        container_t.1.n = 4242;
        D.1311 = container_t.1;
        *container = D.1311;
      }
    }
}

I suspect that this has been broken since allocatable component
were introduced into gfortran.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (5 preceding siblings ...)
  2009-09-27 17:21 ` kargl at gcc dot gnu dot org
@ 2009-09-27 18:19 ` kargl at gcc dot gnu dot org
  2009-09-29 15:47 ` jakub at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: kargl at gcc dot gnu dot org @ 2009-09-27 18:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from kargl at gcc dot gnu dot org  2009-09-27 18:18 -------
Checking the 4.2 branch and trans-expr.c in trunk, it appears that
this chunk of code in gfc_conv_function_call() has gone missing.

2148 /* If an INTENT(OUT) dummy of derived type has a default
2149    initializer, it must be (re)initialized here. */
2150 if (fsym->attr.intent == INTENT_OUT
2151     && fsym->ts.type == BT_DERIVED
2152     && fsym->value)
2153   {
2154     gcc_assert (!fsym->attr.allocatable);
2155     tmp = gfc_trans_assignment (e, fsym->value, false);
2156     gfc_add_expr_to_block (&se->pre, tmp);
2157   }


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (6 preceding siblings ...)
  2009-09-27 18:19 ` kargl at gcc dot gnu dot org
@ 2009-09-29 15:47 ` jakub at gcc dot gnu dot org
  2009-10-02  9:54 ` burnus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-09-29 15:47 UTC (permalink / raw)
  To: gcc-bugs



-- 

jakub at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (7 preceding siblings ...)
  2009-09-29 15:47 ` jakub at gcc dot gnu dot org
@ 2009-10-02  9:54 ` burnus at gcc dot gnu dot org
  2009-10-02 16:26 ` burnus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-10-02  9:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from burnus at gcc dot gnu dot org  2009-10-02 09:54 -------
(In reply to comment #7)
> Checking the 4.2 branch and trans-expr.c in trunk, it appears that
> this chunk of code in gfc_conv_function_call() has gone missing.

It was removed with the following patch:


Date: Tue Jul 24 19:16:36 2007
New Revision: 126885 / 126886

URL: http://gcc.gnu.org/viewcvs?view=revision&revision=126885
     http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126886
Log:
2007-07-24 Paul Thomas <pault@gcc.gnu.org>

        PR fortran/31205
        PR fortran/32842
        * trans-expr.c (gfc_conv_function_call): Remove the default
        initialization of intent(out) derived types.

>From http://gcc.gnu.org/ml/gcc-patches/2007-06/msg02151.html:
  (ii) Remove the initialization of derived types with a default
  initializer from the caller to the callee.  The reasons for doing this
  are discussed in the PR (PR31205).  It has a gratifying effect on passing
  derived types with allocatable components, in that the amount of
  generated code goes down (see alloc_comp_basics_1.f90).

Thus I think that part is OK. (Doing the default initialization in the caller
leads to wrong code if the caller does not know the interface of called
procedure.) However, some callee initialization is now missing.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (8 preceding siblings ...)
  2009-10-02  9:54 ` burnus at gcc dot gnu dot org
@ 2009-10-02 16:26 ` burnus at gcc dot gnu dot org
  2009-10-05  9:19 ` burnus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-10-02 16:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from burnus at gcc dot gnu dot org  2009-10-02 16:26 -------
Subject: Bug 41479

Author: burnus
Date: Fri Oct  2 16:25:50 2009
New Revision: 152407

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=152407
Log:
2009-10-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41479
        * trans-decl.c (gfc_init_default_dt): Check for presence of
        the argument only if it is optional or in entry master.
        (init_intent_out_dt): Ditto; call gfc_init_default_dt
        for all derived types with initializers.

2009-10-02  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41479
        * gfortran.dg/intent_out_5.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/intent_out_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (9 preceding siblings ...)
  2009-10-02 16:26 ` burnus at gcc dot gnu dot org
@ 2009-10-05  9:19 ` burnus at gcc dot gnu dot org
  2009-10-05  9:20 ` burnus at gcc dot gnu dot org
  2009-10-05  9:20 ` burnus at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-10-05  9:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from burnus at gcc dot gnu dot org  2009-10-05 09:19 -------
Subject: Bug 41479

Author: burnus
Date: Mon Oct  5 09:19:13 2009
New Revision: 152444

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=152444
Log:
2009-10-05  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41479
        (init_intent_out_dt): Call gfc_init_default_dt
        for all derived types with initializers.

2009-10-05  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41479
        * gfortran.dg/intent_out_5.f90: New test.


Added:
    branches/gcc-4_4-branch/gcc/testsuite/gfortran.dg/intent_out_5.f90
Modified:
    branches/gcc-4_4-branch/gcc/fortran/ChangeLog
    branches/gcc-4_4-branch/gcc/fortran/trans-decl.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (11 preceding siblings ...)
  2009-10-05  9:20 ` burnus at gcc dot gnu dot org
@ 2009-10-05  9:20 ` burnus at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-10-05  9:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from burnus at gcc dot gnu dot org  2009-10-05 09:20 -------
Subject: Bug 41479

Author: burnus
Date: Mon Oct  5 09:19:52 2009
New Revision: 152445

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=152445
Log:
2009-10-05  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41479
        (init_intent_out_dt): Call gfc_init_default_dt
        for all derived types with initializers.

2009-10-05  Tobias Burnus  <burnus@net-b.de>

        PR fortran/41479
        * gfortran.dg/intent_out_5.f90: New test.


Added:
    branches/gcc-4_3-branch/gcc/testsuite/gfortran.dg/intent_out_5.f90
Modified:
    branches/gcc-4_3-branch/gcc/fortran/ChangeLog
    branches/gcc-4_3-branch/gcc/fortran/trans-decl.c
    branches/gcc-4_3-branch/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

* [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization
  2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
                   ` (10 preceding siblings ...)
  2009-10-05  9:19 ` burnus at gcc dot gnu dot org
@ 2009-10-05  9:20 ` burnus at gcc dot gnu dot org
  2009-10-05  9:20 ` burnus at gcc dot gnu dot org
  12 siblings, 0 replies; 14+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-10-05  9:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from burnus at gcc dot gnu dot org  2009-10-05 09:20 -------
FIXED on the trunk (4.5) and on the 4.3 and 4.4 branches.

Thanks for the report!


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41479


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

end of thread, other threads:[~2009-10-05  9:20 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-26 21:12 [Bug fortran/41479] New: wrong code, mis-initialization reuter at physik dot uni-freiburg dot de
2009-09-26 21:14 ` [Bug fortran/41479] " reuter at physik dot uni-freiburg dot de
2009-09-27  0:50 ` jvdelisle at gcc dot gnu dot org
2009-09-27  1:14 ` jvdelisle at gcc dot gnu dot org
2009-09-27 10:04 ` dominiq at lps dot ens dot fr
2009-09-27 17:03 ` [Bug fortran/41479] [4.3/4.4/4.5 Regression] intent(out) for types with default initialization jv244 at cam dot ac dot uk
2009-09-27 17:21 ` kargl at gcc dot gnu dot org
2009-09-27 18:19 ` kargl at gcc dot gnu dot org
2009-09-29 15:47 ` jakub at gcc dot gnu dot org
2009-10-02  9:54 ` burnus at gcc dot gnu dot org
2009-10-02 16:26 ` burnus at gcc dot gnu dot org
2009-10-05  9:19 ` burnus at gcc dot gnu dot org
2009-10-05  9:20 ` burnus at gcc dot gnu dot org
2009-10-05  9:20 ` burnus at gcc dot gnu dot org

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).