public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types
@ 2005-01-21 10:30 martin at mpa-garching dot mpg dot de
  2005-01-21 10:31 ` [Bug fortran/19561] " martin at mpa-garching dot mpg dot de
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: martin at mpa-garching dot mpg dot de @ 2005-01-21 10:30 UTC (permalink / raw)
  To: gcc-bugs

When compiling the following code with current gfortan, the resulting executable
produces the following output:

number, derived =     2
number, simple  =     1
number, simple  = *****

The (IMO) correct output would be

number, derived =     2
number, simple  =     1
number, simple  =     1

which is produced by most other compilers I tried.
Only Intel ifc 8.0 and 8.1 produce the same output as
gfortran.


module simpleObj
   implicit none

   type objA
      private
      integer :: i
   end type objA

   interface new
      module procedure oaInit
   end interface

   interface print
      module procedure oaPrint
   end interface

   private
   public objA,new,print

contains

   subroutine oaInit(oa,i)
      integer :: i
      type(objA) :: oa

      oa%i=i
   end subroutine oaInit

   subroutine oaPrint(oa)
      type(objA) :: oa

      print '("number, simple  = ",i5)', oa%i
   end subroutine oaPrint

end module simpleObj

! -----------------------------------------------------------------

module derivedObj
   use simpleObj
   implicit none

   type objB
      private
      integer :: i
      type(objA), pointer :: oa
   end type objB

   interface new
      module procedure obInit
   end interface

   interface print
      module procedure obPrint
   end interface

   private
   public objB,new,print,getOa

contains

   subroutine obInit(ob,oa,i)
      integer :: i
      type(objA), target :: oa
      type(objB) :: ob

      ob%i=i
      ob%oa=>oa
   end subroutine obInit

   subroutine obPrint(ob)
      type(objB) :: ob

      print '("number, derived = ",i5)', ob%i
      call print(ob%oa)
   end subroutine obPrint

   function getOa(ob) result(oa)
      type(objB),target :: ob
      type(objA), pointer :: oa

      oa=>ob%oa
   end function getOa
      
end module derivedObj

! -----------------------------------------------------------------

program test
   use simpleObj
   use derivedObj
   implicit none
   type(objA),target :: oa
   type(objB),target :: ob

   call new(oa,1)
   call new(ob,oa,2)

   call print(ob)
   call print(getOa(ob))
end program test

~/tmp>gfortran -v test.f90
Driving: gfortran -v test.f90 -lgfortranbegin -lgfortran -lm -shared-libgcc
Using built-in specs.
Configured with: /scratch/gcc/configure --quiet
--prefix=/afs/mpa/data/martin/ugcc --enable-languages=c++,f95
--with-gmp=/afs/mpa/data/martin/mygmp
Thread model: posix
gcc version 4.0.0 20050120 (experimental)
 /afs/mpa/data/martin/ugcc/libexec/gcc/i686-pc-linux-gnu/4.0.0/f951 test.f90
-quiet -dumpbase test.f90 -mtune=pentiumpro -auxbase test -version -o
/tmp/ccZa4zwg.s
GNU F95 version 4.0.0 20050120 (experimental) (i686-pc-linux-gnu)
        compiled by GNU C version 4.0.0 20050120 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
 as -V -Qy -o /tmp/cc0LLrQq.o /tmp/ccZa4zwg.s
GNU assembler version 2.14 (i686-pc-linux-gnu) using BFD version 2.14 20030612
 /afs/mpa/data/martin/ugcc/libexec/gcc/i686-pc-linux-gnu/4.0.0/collect2
--eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o
/usr/lib/crti.o
/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.0.0/crtbegin.o
-L/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.0.0
-L/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.0.0/../../..
/tmp/cc0LLrQq.o -lgfortranbegin -lgfortran -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc
/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.0.0/crtend.o /usr/lib/crtn.o
~/tmp>./a.out
number, derived =     2
number, simple  =     1
number, simple  = *****

-- 
           Summary: [gfortran] wrong code generation for pointers to derived
                    types
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: martin at mpa-garching dot mpg dot de
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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

* [Bug fortran/19561] [gfortran] wrong code generation for pointers to derived types
  2005-01-21 10:30 [Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types martin at mpa-garching dot mpg dot de
@ 2005-01-21 10:31 ` martin at mpa-garching dot mpg dot de
  2005-01-21 13:04 ` paulthomas2 at wanadoo dot fr
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: martin at mpa-garching dot mpg dot de @ 2005-01-21 10:31 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
      Known to fail|                            |4.0.0


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


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

* [Bug fortran/19561] [gfortran] wrong code generation for pointers to derived types
  2005-01-21 10:30 [Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types martin at mpa-garching dot mpg dot de
  2005-01-21 10:31 ` [Bug fortran/19561] " martin at mpa-garching dot mpg dot de
@ 2005-01-21 13:04 ` paulthomas2 at wanadoo dot fr
  2005-01-21 14:48 ` pbrook at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paulthomas2 at wanadoo dot fr @ 2005-01-21 13:04 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From paulthomas2 at wanadoo dot fr  2005-01-21 13:03 -------
Confirmed on Cygwin and RH9

In an attempt to reduce this a bit, I have produced a slightly more startling 
error:

$ cat point.f90
module mpoint
  type           ::       mytype
    integer      ::       i
  end type mytype
contains
  function get (a) result (b)
    type (mytype), target   ::      a
    type (mytype), pointer  ::      b
    b => a
  end function get
end module mpoint
program point
  use mpoint
  type (mytype), target  ::       x
  type (mytype), pointer ::       y
  x = mytype (42)
  print *, get (x)
end program point

$ d:/irun/bin/gfortran -c -v point.f90
Using built-in specs.
Configured with: ../gcc/configure --with-gmp=/usr/local --with-
mpfr=/usr/local -
-enable-languages=c,f95,c++ --prefix=/cygdrive/d/irun : 
(reconfigured) ../gcc/co
nfigure --with-gmp=/usr/local --with-mpfr=/usr/local --
prefix=/cygdrive/d/irun -
-with-gcc-version-trigger=/cygdrive/d/gcc-cvs/gcc/gcc/version.c --enable-
languag
es=c,c++,f95 --no-create --no-recursion : (reconfigured) ../gcc/configure --
with
-gmp=/usr/local --with-mpfr=/usr/local --prefix=/cygdrive/d/irun --with-gcc-
vers
ion-trigger=/cygdrive/d/gcc-cvs/gcc/gcc/version.c --enable-
languages=c,c++,f95 -
-no-create --no-recursion
Thread model: single
gcc version 4.0.0 20050116 (experimental)
 /cygdrive/d/irun/libexec/gcc/i686-pc-cygwin/4.0.0/f951.exe point.f90 -quiet -
du
mpbase point.f90 -mtune=pentiumpro -auxbase point -version -
o /cygdrive/c/DOCUME
~1/PAULTH~1/LOCALS~1/Temp/cc6mI8lv.s
GNU F95 version 4.0.0 20050117 (experimental) (i686-pc-cygwin)
        compiled by GNU C version 3.3.1 (cygming special).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
point.f90: In function 'MAIN__':
point.f90:16: internal compiler error: tree check: expected record_type or 
union
_type or qual_union_type, have pointer_type in find_compatible_field, at 
tree.c:
5995

-- 


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


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

* [Bug fortran/19561] [gfortran] wrong code generation for pointers to derived types
  2005-01-21 10:30 [Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types martin at mpa-garching dot mpg dot de
  2005-01-21 10:31 ` [Bug fortran/19561] " martin at mpa-garching dot mpg dot de
  2005-01-21 13:04 ` paulthomas2 at wanadoo dot fr
@ 2005-01-21 14:48 ` pbrook at gcc dot gnu dot org
  2005-01-21 14:58 ` pbrook at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pbrook at gcc dot gnu dot org @ 2005-01-21 14:48 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pbrook at gcc dot gnu dot org  2005-01-21 14:48 -------
Testcase invokes undefined behaviour.
http://gcc.gnu.org/ml/fortran/2005-01/msg00234.html

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


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


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

* [Bug fortran/19561] [gfortran] wrong code generation for pointers to derived types
  2005-01-21 10:30 [Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types martin at mpa-garching dot mpg dot de
                   ` (3 preceding siblings ...)
  2005-01-21 14:58 ` pbrook at gcc dot gnu dot org
@ 2005-01-21 14:58 ` pbrook at gcc dot gnu dot org
  2005-01-22  6:23 ` paulthomas2 at wanadoo dot fr
  2005-06-21  8:41 ` tobi at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: pbrook at gcc dot gnu dot org @ 2005-01-21 14:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pbrook at gcc dot gnu dot org  2005-01-21 14:57 -------
My bad, this is in fact legal and well defined.

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


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


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

* [Bug fortran/19561] [gfortran] wrong code generation for pointers to derived types
  2005-01-21 10:30 [Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types martin at mpa-garching dot mpg dot de
                   ` (2 preceding siblings ...)
  2005-01-21 14:48 ` pbrook at gcc dot gnu dot org
@ 2005-01-21 14:58 ` pbrook at gcc dot gnu dot org
  2005-01-21 14:58 ` pbrook at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pbrook at gcc dot gnu dot org @ 2005-01-21 14:58 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-01-21 14:58:16
               date|                            |


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


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

* [Bug fortran/19561] [gfortran] wrong code generation for pointers to derived types
  2005-01-21 10:30 [Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types martin at mpa-garching dot mpg dot de
                   ` (4 preceding siblings ...)
  2005-01-21 14:58 ` pbrook at gcc dot gnu dot org
@ 2005-01-22  6:23 ` paulthomas2 at wanadoo dot fr
  2005-06-21  8:41 ` tobi at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: paulthomas2 at wanadoo dot fr @ 2005-01-22  6:23 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From paulthomas2 at wanadoo dot fr  2005-01-22 06:19 -------
The problem is in the main program

   type(objA),target :: oa
   type(objB),target :: ob
   call new(oa,1)
   call new(ob,oa,2)
   call print(ob)
   call print(getOa(ob))   !<<here
end program test

This works

   type(objA),target :: oa
   type(objA),pointer :: ot  !<<<
   type(objB),target :: ob
   call new(oa,1)
   call new(ob,oa,2)
   call print(ob)
   ot=>getOa(ob)             !<<< temporary pointer does
   call print(ot)            !<<< not survive. This does.
end program test


-- 


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


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

* [Bug fortran/19561] [gfortran] wrong code generation for pointers to derived types
  2005-01-21 10:30 [Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types martin at mpa-garching dot mpg dot de
                   ` (5 preceding siblings ...)
  2005-01-22  6:23 ` paulthomas2 at wanadoo dot fr
@ 2005-06-21  8:41 ` tobi at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: tobi at gcc dot gnu dot org @ 2005-06-21  8:41 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From tobi at gcc dot gnu dot org  2005-06-21 08:41 -------
Works on both the 4.0 branch and the mainline.  Testcase forthcoming.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |tobi at gcc dot gnu dot org
             Status|NEW                         |RESOLVED
      Known to fail|4.0.0                       |
      Known to work|                            |4.0.1 4.1.0
         Resolution|                            |WORKSFORME
   Target Milestone|---                         |4.0.1


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


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

end of thread, other threads:[~2005-06-21  8:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-21 10:30 [Bug fortran/19561] New: [gfortran] wrong code generation for pointers to derived types martin at mpa-garching dot mpg dot de
2005-01-21 10:31 ` [Bug fortran/19561] " martin at mpa-garching dot mpg dot de
2005-01-21 13:04 ` paulthomas2 at wanadoo dot fr
2005-01-21 14:48 ` pbrook at gcc dot gnu dot org
2005-01-21 14:58 ` pbrook at gcc dot gnu dot org
2005-01-21 14:58 ` pbrook at gcc dot gnu dot org
2005-01-22  6:23 ` paulthomas2 at wanadoo dot fr
2005-06-21  8:41 ` tobi 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).