public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/44541]  New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
@ 2010-06-15  7:45 burnus at gcc dot gnu dot org
  2010-06-15 18:41 ` [Bug fortran/44541] " janus at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-06-15  7:45 UTC (permalink / raw)
  To: gcc-bugs

Follow up to PR 43388 (ALLOCATE with MOLD, a F2008 feature), but it also
applies to polymorphic variables with INTENT(OUT) (i.e. to F2003).

In either cases, a potentially existing default initializer of the *effective
type* needs to be applied. That means that this data has to be available in the
vtable.

See also: http://j3-fortran.org/pipermail/j3/2010-June/003621.html

(Thanks to Janus for spotting the problem (for MOLD) at the first place; thanks
to Bill Long for confirmation and mentioning INTENT(OUT); and to Aleksandar
Donev for the comments.)

Testing shows that other vendors have also overlooked these cases.
(For intent out, there seem to be compiler which do not set the variable at all
(e.g. gfortran) or those which only use the base type for the initialization;
similarly, for MOLD where unspecified initialization happens (via malloc),
possibly with base-type initialization on top.)

---------- INTENT(OUT) test case -----------------
! Expected: a= 1  b= 3
  implicit none
  type t
    integer :: a = 1
  end type t
  type, extends(t) :: t2
    integer :: b = 3
  end type t2

  type(t2) :: y
  y%a = 44
  y%b = 55
  call intent_out (y)
  print *, 'a=', y%a, ' b=', y%b
contains
  subroutine intent_out(x)
    class(t), intent(out) :: x
    select type (x)
      type is (t2)
      print *, 'a=', x%a, ' b=', x%b
    end select
  end subroutine
end

---------- MOLD test case ------------------------
! Expected:
!  a= 1  b= 3
! (Wrong is "a= 1  b= 0" or "a= 0  b= 0" or garbage)
implicit none
type t
  integer :: a = 1
end type t

type, extends(t) :: t2
  integer :: b = 3
end type t2

class(t), allocatable :: x, y

allocate (t2 :: y)
select type (y)
  type is (t2)
    y%a = 44
    y%b = 55
end select

allocate ( x, mold=y)
select type (x)
  type is (t2)
   print *, 'a=', x%a, ' b=', x%b
end select
end


-- 
           Summary: [OOP] wrong code for polymorphic variable with
                    INTENT(OUT)/Alloc w/ MOLD
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org
 BugsThisDependsOn: 43388


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


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

* [Bug fortran/44541] [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
  2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
@ 2010-06-15 18:41 ` janus at gcc dot gnu dot org
  2010-06-21 10:18 ` janus at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-06-15 18:41 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from janus at gcc dot gnu dot org  2010-06-15 18:40 -------
(In reply to comment #0)
> Follow up to PR 43388 (ALLOCATE with MOLD, a F2008 feature)


For the MOLD problem we already have a test case in allocate_alloc_opt_10.f90
(which is put behind comments right now, but should be uncommented once this PR
is fixed).


-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-06-15 18:40:31
               date|                            |


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


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

* [Bug fortran/44541] [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
  2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
  2010-06-15 18:41 ` [Bug fortran/44541] " janus at gcc dot gnu dot org
@ 2010-06-21 10:18 ` janus at gcc dot gnu dot org
  2010-08-21 12:51 ` burnus at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-06-21 10:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from janus at gcc dot gnu dot org  2010-06-21 10:18 -------
My first idea to fix this was to add a new field to the vtabs, let's call it
$def_init, which would be the fourth field in the vtab structure (after $hash,
$size and $extends), and would contain the default initialization values for
the type.

However, this approach does not work, since the field needed for default
initialization would have to be of the derived type which the vtab belongs to.
This however can have different sizes, so that the PPCs in the vtab will not be
aligned any more for extended types, which messes up dynamic dispatch.

Alternatives:
(1) make $def_init a pointer (problem: initialization of $def_init itself)
(2) add standalone variables a la "type_t$def_init" to carry default
initialization for each type
(3) ...?


-- 


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


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

* [Bug fortran/44541] [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
  2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
  2010-06-15 18:41 ` [Bug fortran/44541] " janus at gcc dot gnu dot org
  2010-06-21 10:18 ` janus at gcc dot gnu dot org
@ 2010-08-21 12:51 ` burnus at gcc dot gnu dot org
  2010-08-21 15:14 ` janus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-21 12:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from burnus at gcc dot gnu dot org  2010-08-21 12:51 -------
Is this now fixable using the default pointer initialization?


-- 


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


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

* [Bug fortran/44541] [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
  2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-08-21 12:51 ` burnus at gcc dot gnu dot org
@ 2010-08-21 15:14 ` janus at gcc dot gnu dot org
  2010-08-29 21:10 ` janus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-08-21 15:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from janus at gcc dot gnu dot org  2010-08-21 15:14 -------
(In reply to comment #3)
> Is this now fixable using the default pointer initialization?

At least pointer initialization enables us to initalize the $def_init pointer
component. But still we will need a default-initialized variable which
$def_init can point to.

The question is if we even need a $def_init component in the vtab (I think the
answer is yes, since we don't know the dynamic type to use for initialization
in the general case).


-- 


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


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

* [Bug fortran/44541] [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
  2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-08-21 15:14 ` janus at gcc dot gnu dot org
@ 2010-08-29 21:10 ` janus at gcc dot gnu dot org
  2010-09-01 20:51 ` janus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-08-29 21:10 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from janus at gcc dot gnu dot org  2010-08-29 21:10 -------
Mine (working on a patch).


-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |janus at gcc dot gnu dot org
                   |dot org                     |
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2010-06-15 18:40:31         |2010-08-29 21:10:26
               date|                            |


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


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

* [Bug fortran/44541] [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
  2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2010-08-29 21:10 ` janus at gcc dot gnu dot org
@ 2010-09-01 20:51 ` janus at gcc dot gnu dot org
  2010-09-01 21:25 ` burnus at gcc dot gnu dot org
  2010-09-02 12:35 ` janus at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-09-01 20:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from janus at gcc dot gnu dot org  2010-09-01 20:51 -------
Subject: Bug 44541

Author: janus
Date: Wed Sep  1 20:50:46 2010
New Revision: 163744

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=163744
Log:
2010-09-01  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/44541
        * class.c (gfc_find_derived_vtab): Add component '$def_init'.
        * resolve.c (resolve_allocate_expr): Defer handling of default
        initialization to 'gfc_trans_allocate'.
        (apply_default_init,resolve_symbol): Handle polymorphic dummies.
        (resolve_fl_derived): Suppress error messages for vtypes.
        * trans-stmt.c (gfc_trans_allocate): Handle initialization via
        polymorphic MOLD expression.
        * trans-expr.c (gfc_trans_class_init_assign): Now only used for
        dummy initialization.


2010-09-01  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/44541
        * gfortran.dg/allocate_alloc_opt_10.f90: Extended.
        * gfortran.dg/class_dummy_1.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_dummy_1.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/class.c
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/fortran/trans-stmt.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/allocate_alloc_opt_10.f90


-- 


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


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

* [Bug fortran/44541] [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
  2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2010-09-01 20:51 ` janus at gcc dot gnu dot org
@ 2010-09-01 21:25 ` burnus at gcc dot gnu dot org
  2010-09-02 12:35 ` janus at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-09-01 21:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from burnus at gcc dot gnu dot org  2010-09-01 21:25 -------
Close as fixed (on the 4.6 trunk).

Thanks for the patch, Janus!


-- 

burnus at gcc dot gnu dot org changed:

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


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


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

* [Bug fortran/44541] [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD
  2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2010-09-01 21:25 ` burnus at gcc dot gnu dot org
@ 2010-09-02 12:35 ` janus at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-09-02 12:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from janus at gcc dot gnu dot org  2010-09-02 12:34 -------
Subject: Bug 44541

Author: janus
Date: Thu Sep  2 12:34:26 2010
New Revision: 163773

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=163773
Log:
2010-09-02  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/44541
        * resolve.c (resolve_symbol): Correct check for attributes of CLASS
        variable.

Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c


-- 


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


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

end of thread, other threads:[~2010-09-02 12:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-15  7:45 [Bug fortran/44541] New: [OOP] wrong code for polymorphic variable with INTENT(OUT)/Alloc w/ MOLD burnus at gcc dot gnu dot org
2010-06-15 18:41 ` [Bug fortran/44541] " janus at gcc dot gnu dot org
2010-06-21 10:18 ` janus at gcc dot gnu dot org
2010-08-21 12:51 ` burnus at gcc dot gnu dot org
2010-08-21 15:14 ` janus at gcc dot gnu dot org
2010-08-29 21:10 ` janus at gcc dot gnu dot org
2010-09-01 20:51 ` janus at gcc dot gnu dot org
2010-09-01 21:25 ` burnus at gcc dot gnu dot org
2010-09-02 12:35 ` janus 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).