public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/111521] New: Polymorphic variable loses information about the actual type assigned when passed as function result
@ 2023-09-21 14:30 dcesari69 at gmail dot com
  2023-09-21 15:11 ` [Bug fortran/111521] " dcesari69 at gmail dot com
  0 siblings, 1 reply; 2+ messages in thread
From: dcesari69 at gmail dot com @ 2023-09-21 14:30 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111521

            Bug ID: 111521
           Summary: Polymorphic variable loses information about the
                    actual type assigned when passed as function result
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcesari69 at gmail dot com
  Target Milestone: ---

Created attachment 55961
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55961&action=edit
Program showing the described behavior

Hello, the attached program shows an anomalous behavior since gcc-gfortran
version 13, in the previous gfortran versions it worked as expected.

gcc version:
GNU Fortran (GCC) 13.2.1 20230728 (Red Hat 13.2.1-1)
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

OS (Fedora 38):
Linux trentotto 6.3.8-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Jun 15
02:15:40 UTC 2023 x86_64 GNU/Linux

Build command line:
gfortran -g -fcheck=all -o testpoli testpoli.f90

Actual program stdout:
 1.integer
 1.integer
 2.unknown type
 3.unknown type
           8          -1

Expected program stdout (e.g. when compiled with gfortran 12.2.1):
 1.integer
 2.integer
 3.integer
           8           8

Description:
The unlimited polymorphic derived type member %val is initialised with an
integer, but when passed back as a result of a chain of functions, it loses its
type. Additionally, the debugging print show that the function link_getval is
apparently executed twice, while it is called only once.

By executing the commented line `v => this%curr%getval()` instead of `v =>
this%getcurr()` the program gives the expected result with version 13, however
the original code was obviously more complex and this chained function call was
necessary.

The bug could be somehow related to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110415 also appearing in version
13.

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

* [Bug fortran/111521] Polymorphic variable loses information about the actual type assigned when passed as function result
  2023-09-21 14:30 [Bug fortran/111521] New: Polymorphic variable loses information about the actual type assigned when passed as function result dcesari69 at gmail dot com
@ 2023-09-21 15:11 ` dcesari69 at gmail dot com
  0 siblings, 0 replies; 2+ messages in thread
From: dcesari69 at gmail dot com @ 2023-09-21 15:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111521

--- Comment #1 from Davide Cesari <dcesari69 at gmail dot com> ---
An update:

By replacing the line

list_getcurr => this%curr%getval()

with

CLASS(*),POINTER :: l_p
l_p => this%curr%getval()
list_getcurr => l_p

i.e. assigning the upper function result to a temporary local pointer and
setting the current function result to that pointer gives the correct result.

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

end of thread, other threads:[~2023-09-21 15:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-21 14:30 [Bug fortran/111521] New: Polymorphic variable loses information about the actual type assigned when passed as function result dcesari69 at gmail dot com
2023-09-21 15:11 ` [Bug fortran/111521] " dcesari69 at gmail dot com

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