public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF  returns the wrong result if the polymorphic variable is unallocated
@ 2011-01-05 14:29 burnus at gcc dot gnu.org
  2011-01-05 14:38 ` [Bug fortran/47180] " janus at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-01-05 14:29 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: [OOP] EXTENDS_TYPE_OF  returns the wrong result if the
                    polymorphic variable is unallocated
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: burnus@gcc.gnu.org
                CC: janus@gcc.gnu.org


Found when looking at PR 41580.

The following program should print 6 times "T" but it prints trice "F" followed
by trice "T".

>From Fortran 2008:
"13.7.60 EXTENDS_TYPE_OF (A, MOLD)"

"Result Value.  [unlimited polymorphic] ; otherwise if the dynamic type of A or
MOLD is extensible, the result is true if and only if the dynamic type of A is
an extension type of the dynamic type of MOLD; otherwise the result is
processor dependent."

"NOTE 13.12  The dynamic type of a disassociated pointer or unallocated
allocatable variable is its declared type."


(NAG 5.1 ICEs and ifort prints the same result as gfortran; nevertheless, I
expect that the code is correct, which is in line with NOTE 13.12.)


implicit none
type t1
  integer :: a
end type t1
type, extends(t1):: t11
  integer :: b
end type t11

type(t1) a1
type(t11) a11
class(t1), allocatable :: b1
class(t11), allocatable :: b11

print *, extends_type_of(b1,a1)   ! T - currently, gfortran prints "F"
print *, extends_type_of(b11,a1)  ! T - currently, gfortran prints "F"
print *, extends_type_of(b11,a11) ! T - currently, gfortran prints "F"

allocate(t1 :: b1)
allocate(t11 :: b11)

print *, extends_type_of(b1,a1)   ! T
print *, extends_type_of(b11,a1)  ! T
print *, extends_type_of(b11,a11) ! T
end


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF  returns the wrong result if the polymorphic variable is unallocated
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
@ 2011-01-05 14:38 ` janus at gcc dot gnu.org
  2011-01-05 14:48 ` burnus at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-01-05 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from janus at gcc dot gnu.org 2011-01-05 14:37:26 UTC ---
(In reply to comment #0)
> Found when looking at PR 41580.
> 
> The following program should print 6 times "T" but it prints trice "F" followed
> by trice "T".

Actually it does print six time "T" for me!

Are you sure your trunk is up to date?

Note that r168505 is crucial here, which is the fix for PR47024 that I just
committed a few hours ago, and which fixes this very issue ...


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF  returns the wrong result if the polymorphic variable is unallocated
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
  2011-01-05 14:38 ` [Bug fortran/47180] " janus at gcc dot gnu.org
@ 2011-01-05 14:48 ` burnus at gcc dot gnu.org
  2011-01-05 14:55 ` [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers janus at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-01-05 14:48 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

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

--- Comment #2 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-01-05 14:46:29 UTC ---
(In reply to comment #1)
> Actually it does print six time "T" for me!
> Are you sure your trunk is up to date?
> Note that r168505 is crucial here, which is the fix for PR47024 that I just
> committed a few hours ago, and which fixes this very issue ...

I think that my vanilla trunk is then not sufficiently up to date; I have
another build which contains your patch - but also a draft patch for PR 41580
and is thus not reliably.

Thus, I believe your result: Close as FIXED.


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
  2011-01-05 14:38 ` [Bug fortran/47180] " janus at gcc dot gnu.org
  2011-01-05 14:48 ` burnus at gcc dot gnu.org
@ 2011-01-05 14:55 ` janus at gcc dot gnu.org
  2011-01-05 15:09 ` janus at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-01-05 14:55 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |NEW
   Last reconfirmed|                            |2011.01.05 14:48:38
         Resolution|FIXED                       |
            Summary|[OOP] EXTENDS_TYPE_OF       |[OOP] EXTENDS_TYPE_OF
                   |returns the wrong result if |returns the wrong result
                   |the polymorphic variable is |for disassociated
                   |unallocated                 |polymorphic pointers
     Ever Confirmed|0                           |1

--- Comment #3 from janus at gcc dot gnu.org 2011-01-05 14:48:38 UTC ---
(In reply to comment #1)
> Note that r168505 is crucial here, which is the fix for PR47024 that I just
> committed a few hours ago, and which fixes this very issue ...

Anyway r168505 only fixed the issue for allocatables, not pointers! Therefore
the following variant indeed still gives the wrong output:


implicit none
type t1
  integer :: a
end type t1
type, extends(t1):: t11
  integer :: b
end type t11

type(t1), target :: a1
type(t11), target :: a11
class(t1), pointer :: b1
class(t11), pointer :: b11

b1 => NULL()
b11 => NULL()

print *, extends_type_of(b1,a1)   ! T - currently, gfortran prints "F"
print *, extends_type_of(b11,a1)  ! T - currently, gfortran prints "F"
print *, extends_type_of(b11,a11) ! T - currently, gfortran prints "F"

b1 => a1
b11 => a11

print *, extends_type_of(b1,a1)   ! T
print *, extends_type_of(b11,a1)  ! T
print *, extends_type_of(b11,a11) ! T
end


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2011-01-05 14:55 ` [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers janus at gcc dot gnu.org
@ 2011-01-05 15:09 ` janus at gcc dot gnu.org
  2011-01-05 18:09 ` janus at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-01-05 15:09 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |janus at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #4 from janus at gcc dot gnu.org 2011-01-05 15:08:09 UTC ---
Draft patch:


Index: gcc/fortran/trans-expr.c
===================================================================
--- gcc/fortran/trans-expr.c    (revision 168504)
+++ gcc/fortran/trans-expr.c    (working copy)
@@ -6121,25 +6121,24 @@ gfc_trans_class_assign (gfc_expr *expr1, gfc_expr
   if (expr2->ts.type != BT_CLASS)
     {
       /* Insert an additional assignment which sets the '_vptr' field.  */
+      gfc_symbol *vtab;
+      gfc_symtree *st;
+
       lhs = gfc_copy_expr (expr1);
       gfc_add_vptr_component (lhs);
+
       if (expr2->ts.type == BT_DERIVED)
-    {
-      gfc_symbol *vtab;
-      gfc_symtree *st;
-      vtab = gfc_find_derived_vtab (expr2->ts.u.derived);
-      gcc_assert (vtab);
-      rhs = gfc_get_expr ();
-      rhs->expr_type = EXPR_VARIABLE;
-      gfc_find_sym_tree (vtab->name, vtab->ns, 1, &st);
-      rhs->symtree = st;
-      rhs->ts = vtab->ts;
-    }
+    vtab = gfc_find_derived_vtab (expr2->ts.u.derived);
       else if (expr2->expr_type == EXPR_NULL)
-    rhs = gfc_get_int_expr (gfc_default_integer_kind, NULL, 0);
-      else
-    gcc_unreachable ();
+    vtab = gfc_find_derived_vtab (expr1->ts.u.derived);
+      gcc_assert (vtab);

+      rhs = gfc_get_expr ();
+      rhs->expr_type = EXPR_VARIABLE;
+      gfc_find_sym_tree (vtab->name, vtab->ns, 1, &st);
+      rhs->symtree = st;
+      rhs->ts = vtab->ts;
+
       tmp = gfc_trans_pointer_assignment (lhs, rhs);
       gfc_add_expr_to_block (&block, tmp);


Will commit as obvious after regtesting.


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2011-01-05 15:09 ` janus at gcc dot gnu.org
@ 2011-01-05 18:09 ` janus at gcc dot gnu.org
  2011-01-05 18:18 ` janus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-01-05 18:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from janus at gcc dot gnu.org 2011-01-05 18:06:25 UTC ---
Author: janus
Date: Wed Jan  5 18:06:21 2011
New Revision: 168524

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

    PR fortran/47180
    * trans-expr.c (gfc_trans_class_assign): For a polymorphic NULL pointer
    assignment, set the _vptr component to the declared type.


2011-01-05  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/47180
    * gfortran.dg/extends_type_of_2.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/extends_type_of_2.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2011-01-05 18:09 ` janus at gcc dot gnu.org
@ 2011-01-05 18:18 ` janus at gcc dot gnu.org
  2011-01-05 18:31 ` dominiq at lps dot ens.fr
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-01-05 18:18 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

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

--- Comment #6 from janus at gcc dot gnu.org 2011-01-05 18:12:48 UTC ---
Fixed with r168524. Closing.


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2011-01-05 18:18 ` janus at gcc dot gnu.org
@ 2011-01-05 18:31 ` dominiq at lps dot ens.fr
  2011-01-05 18:41 ` burnus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dominiq at lps dot ens.fr @ 2011-01-05 18:31 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2011-01-05 18:18:34 UTC ---
Compiling revision 168524 gives:

../../work/gcc/fortran/trans-expr.c: In function 'gfc_trans_class_assign':
../../work/gcc/fortran/trans-expr.c:6172:42: error: 'vtab' may be used
uninitialized in this function [-Werror=uninitialized]
cc1: all warnings being treated as errors


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2011-01-05 18:31 ` dominiq at lps dot ens.fr
@ 2011-01-05 18:41 ` burnus at gcc dot gnu.org
  2011-01-05 19:05 ` dominiq at lps dot ens.fr
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: burnus at gcc dot gnu.org @ 2011-01-05 18:41 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

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

--- Comment #8 from Tobias Burnus <burnus at gcc dot gnu.org> 2011-01-05 18:34:10 UTC ---
REOPEN: Causes build issues (cf. comment 7).

      gfc_symbol *vtab;
      if (expr2->ts.type == BT_DERIVED)
        vtab = gfc_find_derived_vtab (expr2->ts.u.derived);
      else if (expr2->expr_type == EXPR_NULL)
        vtab = gfc_find_derived_vtab (expr1->ts.u.derived);
      gcc_assert (vtab);

Which means that "vtab" is not initialized if the "if"/"if else" branch is not
entered.

Simple solution:

-     gfc_symbol *vtab;
+     gfc_symbol *vtab = NULL;


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2011-01-05 18:41 ` burnus at gcc dot gnu.org
@ 2011-01-05 19:05 ` dominiq at lps dot ens.fr
  2011-01-05 19:12 ` janus at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: dominiq at lps dot ens.fr @ 2011-01-05 19:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Dominique d'Humieres <dominiq at lps dot ens.fr> 2011-01-05 18:41:36 UTC ---
> Simple solution:
>
> -     gfc_symbol *vtab;
> +     gfc_symbol *vtab = NULL;

This is the fix I have also reached and it allows gcc/fortran/trans-expr.c to
be compiled.


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2011-01-05 19:05 ` dominiq at lps dot ens.fr
@ 2011-01-05 19:12 ` janus at gcc dot gnu.org
  2011-01-05 19:18 ` janus at gcc dot gnu.org
  2011-01-05 19:49 ` janus at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-01-05 19:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from janus at gcc dot gnu.org 2011-01-05 18:55:59 UTC ---
(In reply to comment #8)
> REOPEN: Causes build issues (cf. comment 7).

Thanks for noticing, and sorry for the breakage.


> Simple solution:
> 
> -     gfc_symbol *vtab;
> +     gfc_symbol *vtab = NULL;

Yes, I'll commit shortly.


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2011-01-05 19:12 ` janus at gcc dot gnu.org
@ 2011-01-05 19:18 ` janus at gcc dot gnu.org
  2011-01-05 19:49 ` janus at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-01-05 19:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from janus at gcc dot gnu.org 2011-01-05 19:15:19 UTC ---
Author: janus
Date: Wed Jan  5 19:14:56 2011
New Revision: 168526

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

    PR fortran/47180
    * trans-expr.c (gfc_trans_class_assign): Bugfix for r168524 (make sure
    'vtab' is initialized).

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


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

* [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers
  2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
                   ` (10 preceding siblings ...)
  2011-01-05 19:18 ` janus at gcc dot gnu.org
@ 2011-01-05 19:49 ` janus at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: janus at gcc dot gnu.org @ 2011-01-05 19:49 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

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

--- Comment #12 from janus at gcc dot gnu.org 2011-01-05 19:21:18 UTC ---
Ok. Build problem fixed. Closing, finally.


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

end of thread, other threads:[~2011-01-05 19:21 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-05 14:29 [Bug fortran/47180] New: [OOP] EXTENDS_TYPE_OF returns the wrong result if the polymorphic variable is unallocated burnus at gcc dot gnu.org
2011-01-05 14:38 ` [Bug fortran/47180] " janus at gcc dot gnu.org
2011-01-05 14:48 ` burnus at gcc dot gnu.org
2011-01-05 14:55 ` [Bug fortran/47180] [OOP] EXTENDS_TYPE_OF returns the wrong result for disassociated polymorphic pointers janus at gcc dot gnu.org
2011-01-05 15:09 ` janus at gcc dot gnu.org
2011-01-05 18:09 ` janus at gcc dot gnu.org
2011-01-05 18:18 ` janus at gcc dot gnu.org
2011-01-05 18:31 ` dominiq at lps dot ens.fr
2011-01-05 18:41 ` burnus at gcc dot gnu.org
2011-01-05 19:05 ` dominiq at lps dot ens.fr
2011-01-05 19:12 ` janus at gcc dot gnu.org
2011-01-05 19:18 ` janus at gcc dot gnu.org
2011-01-05 19:49 ` janus at gcc dot gnu.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).