public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/98573] New: Dynamic type lost on assignment
@ 2021-01-06 19:04 davidhneill at gmail dot com
2021-01-06 19:12 ` [Bug fortran/98573] " davidhneill at gmail dot com
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: davidhneill at gmail dot com @ 2021-01-06 19:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
Bug ID: 98573
Summary: Dynamic type lost on assignment
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: davidhneill at gmail dot com
Target Milestone: ---
Created attachment 49904
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49904&action=edit
Minimal reproducer
In the following example, the dynamic type of an unlimited polymorphic array is
lost on an assignment but conserved (as expected) on a sourced allocation.
This happens in all versions I've tried: 7.5.0, 8.4.0, 9.3.0, 10.2.0
My system is Ubuntu 20.04 on Intel hardware with all gfortran versions
installed directly from the Ubuntu repositories.
$ cat type_lost.f90
module foo
type, public:: box
class(*), allocatable :: val(:)
end type
contains
subroutine store1(this, val)
class(box), intent(out) :: this
class(*), intent(in) :: val(:)
this%val = val
end subroutine store1
subroutine store2(this, val)
class(box), intent(out) :: this
class(*), intent(in) :: val(:)
allocate(this%val, source=val)
end subroutine store2
subroutine vector_type(val)
class(*), intent(in) :: val(:)
select type (val)
type is (integer)
print '("INTEGER")'
class default
print '("OTHER")'
end select
end subroutine vector_type
end module foo
program prog
use foo
type(box) :: b
call store1(b, [1, 2, 3])
call vector_type(b%val) ! OTHER
call store2(b, [1, 2, 3])
call vector_type(b%val) ! INTEGER
end program
$ gfortran -g -Wall -Wextra minimal.f90
$ ./a.out
OTHER
INTEGER
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/98573] Dynamic type lost on assignment
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
@ 2021-01-06 19:12 ` davidhneill at gmail dot com
2021-01-06 19:13 ` davidhneill at gmail dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: davidhneill at gmail dot com @ 2021-01-06 19:12 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
--- Comment #1 from David Neill Asanza <davidhneill at gmail dot com> ---
Removing the derived type container triggers a segfault.
$ cat segfault.f90
module foo
contains
subroutine store1(arr, val)
class(*), allocatable, intent(out) :: arr(:)
class(*), intent(in) :: val(:)
arr = val
end subroutine store1
subroutine store2(arr, val)
class(*), allocatable, intent(out) :: arr(:)
class(*), intent(in) :: val(:)
allocate(arr, source=val)
end subroutine store2
end module foo
program prog
use foo
class(*), allocatable :: arr(:)
call store1(arr, [1, 2, 3]) ! SEGFAULT
call store2(arr, [1, 2, 3]) ! NO PROBLEM
end program
$ gfortran -g -Wall -Wextra minimal.f90
$ ./a.out
Program received signal SIGSEGV: Segmentation fault - invalid memory reference.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/98573] Dynamic type lost on assignment
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
2021-01-06 19:12 ` [Bug fortran/98573] " davidhneill at gmail dot com
@ 2021-01-06 19:13 ` davidhneill at gmail dot com
2021-01-06 21:17 ` davidhneill at gmail dot com
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: davidhneill at gmail dot com @ 2021-01-06 19:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
--- Comment #2 from David Neill Asanza <davidhneill at gmail dot com> ---
Created attachment 49905
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49905&action=edit
Minimal reproducer for segmentation fault.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/98573] Dynamic type lost on assignment
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
2021-01-06 19:12 ` [Bug fortran/98573] " davidhneill at gmail dot com
2021-01-06 19:13 ` davidhneill at gmail dot com
@ 2021-01-06 21:17 ` davidhneill at gmail dot com
2021-01-06 21:18 ` davidhneill at gmail dot com
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: davidhneill at gmail dot com @ 2021-01-06 21:17 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
--- Comment #3 from David Neill Asanza <davidhneill at gmail dot com> ---
A related case when the array is 0-length. In this case, the dynamic type is
lost in both assignment and sourced allocation.
$ cat type_lost_0_length.f90
module foo
type, public:: box
class(*), allocatable :: val(:)
end type
contains
subroutine store1(this, val)
class(box), intent(out) :: this
class(*), intent(in) :: val(:)
this%val = val
end subroutine store1
subroutine store2(this, val)
class(box), intent(out) :: this
class(*), intent(in) :: val(:)
allocate(this%val, source=val)
end subroutine store2
subroutine vector_type(val)
class(*), intent(in) :: val(:)
select type (val)
type is (integer)
print '("INTEGER")'
class default
print '("OTHER")'
end select
end subroutine vector_type
end module foo
program prog
use foo
type(box) :: b
integer, allocatable :: arr1(:)
integer, dimension(0) :: arr2
allocate(arr1(0))
call store1(b, arr1)
call vector_type(b%val) ! OTHER
call store2(b, arr1)
call vector_type(b%val) ! OTHER
call store1(b, arr2)
call vector_type(b%val) ! OTHER
call store2(b, arr2)
call vector_type(b%val) ! OTHER
end program
$ gfortran -g -Wall -Wextra type_lost_0_length.f90
$ ./a.out
OTHER
OTHER
OTHER
OTHER
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/98573] Dynamic type lost on assignment
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
` (2 preceding siblings ...)
2021-01-06 21:17 ` davidhneill at gmail dot com
@ 2021-01-06 21:18 ` davidhneill at gmail dot com
2021-01-21 18:18 ` pault at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: davidhneill at gmail dot com @ 2021-01-06 21:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
--- Comment #4 from David Neill Asanza <davidhneill at gmail dot com> ---
Created attachment 49906
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49906&action=edit
Reproducer for 0-length case.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/98573] Dynamic type lost on assignment
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
` (3 preceding siblings ...)
2021-01-06 21:18 ` davidhneill at gmail dot com
@ 2021-01-21 18:18 ` pault at gcc dot gnu.org
2021-01-21 18:46 ` dominiq at lps dot ens.fr
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pault at gcc dot gnu.org @ 2021-01-21 18:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
Paul Thomas <pault at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pault at gcc dot gnu.org
Assignee|unassigned at gcc dot gnu.org |pault at gcc dot gnu.org
--- Comment #5 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 50023
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50023&action=edit
Fix for all three tests
I believe that attached does the job although I don't quite see as many failing
cases as you.
It regtests too :-)
I will investigate a bit further before I submit.
Thanks for the report.
Paul
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/98573] Dynamic type lost on assignment
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
` (4 preceding siblings ...)
2021-01-21 18:18 ` pault at gcc dot gnu.org
@ 2021-01-21 18:46 ` dominiq at lps dot ens.fr
2021-01-22 15:01 ` davidhneill at gmail dot com
2021-02-20 12:18 ` dominiq at lps dot ens.fr
7 siblings, 0 replies; 9+ messages in thread
From: dominiq at lps dot ens.fr @ 2021-01-21 18:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
Dominique d'Humieres <dominiq at lps dot ens.fr> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2021-01-21
Ever confirmed|0 |1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/98573] Dynamic type lost on assignment
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
` (5 preceding siblings ...)
2021-01-21 18:46 ` dominiq at lps dot ens.fr
@ 2021-01-22 15:01 ` davidhneill at gmail dot com
2021-02-20 12:18 ` dominiq at lps dot ens.fr
7 siblings, 0 replies; 9+ messages in thread
From: davidhneill at gmail dot com @ 2021-01-22 15:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
--- Comment #6 from David Neill Asanza <davidhneill at gmail dot com> ---
Thanks for looking into this Paul.
I'm looking forward to having this fixed. :)
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/98573] Dynamic type lost on assignment
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
` (6 preceding siblings ...)
2021-01-22 15:01 ` davidhneill at gmail dot com
@ 2021-02-20 12:18 ` dominiq at lps dot ens.fr
7 siblings, 0 replies; 9+ messages in thread
From: dominiq at lps dot ens.fr @ 2021-02-20 12:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98573
--- Comment #7 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
A patch has been submitted at
https://gcc.gnu.org/pipermail/fortran/2021-January/055624.html
and approved at
https://gcc.gnu.org/pipermail/fortran/2021-January/055644.html
More comments at
https://gcc.gnu.org/pipermail/fortran/2021-January/055651.html
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2021-02-20 12:18 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-06 19:04 [Bug fortran/98573] New: Dynamic type lost on assignment davidhneill at gmail dot com
2021-01-06 19:12 ` [Bug fortran/98573] " davidhneill at gmail dot com
2021-01-06 19:13 ` davidhneill at gmail dot com
2021-01-06 21:17 ` davidhneill at gmail dot com
2021-01-06 21:18 ` davidhneill at gmail dot com
2021-01-21 18:18 ` pault at gcc dot gnu.org
2021-01-21 18:46 ` dominiq at lps dot ens.fr
2021-01-22 15:01 ` davidhneill at gmail dot com
2021-02-20 12:18 ` dominiq at lps dot ens.fr
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).