public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jkozdon at gmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/54784] New: [oop] allocation of extended types with polymorphic allocatable members Date: Tue, 02 Oct 2012 20:07:00 -0000 [thread overview] Message-ID: <bug-54784-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54784 Bug #: 54784 Summary: [oop] allocation of extended types with polymorphic allocatable members Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned@gcc.gnu.org ReportedBy: jkozdon@gmail.com (Error also occurs with gcc 4.7.1) When I have a container module with stores a collection of polymorphics types, I sometimes get an error that a pointer is being freed which was not allocated. An example program is below. It can be compiled without errors gfortran bug.f90 It contains four modules each with an associated type. If the type 'block' in 'block_module' the member nFields is commented out the code runs fine. If a print statement is added in the program the code runs fine If the dimension of the member 'x' of types block_cart1d and block_cart2d are changed so that they are not 3 and 4 (only one must be changed), the program works. Finally, if the order in the program of the addBlock command is reversed the bug.f90 -------- module block_module implicit none private public :: block type,abstract :: block ! if commented out code works fine integer ,private :: nFields = 0 end type block end module block_module module block1d_module use block_module, only : block type,extends(block) :: block1d real,dimension(:,:,:),allocatable,private :: fields end type end module module block2d_module use block_module, only : block type,extends(block) :: block2d real,dimension(:,:,:,:),allocatable,private :: fields end type end module module domain_module use block_module, only : block implicit none type :: list class(block),allocatable :: B end type type :: domain type(list),dimension(10) :: L contains procedure :: addBlock end type contains subroutine addBlock(this,i,b) implicit none class(domain),intent(inout) :: this integer,intent(in) :: i class(block),intent(in) :: b allocate(this%L(i)%B,source=b) end subroutine end module program bug use domain_module, only : domain use block1d_module, only : block1d use block2d_module, only : block2d implicit none type(domain) :: d type(block1d) :: b1 type(block2d) :: b2 ! crashes with "pointer being freed was not allocated" call d%addBlock(1,b1) call d%addBlock(2,b2) ! crashes with "invalid memory reference" ! call d%addBlock(2,b2) ! call d%addBlock(1,b1) ! runs fine ! call d%addBlock(1,b2) ! call d%addBlock(2,b1) end program bug
next reply other threads:[~2012-10-02 20:07 UTC|newest] Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-10-02 20:07 jkozdon at gmail dot com [this message] 2012-10-02 21:52 ` [Bug fortran/54784] [OOP] " janus at gcc dot gnu.org 2012-10-02 22:15 ` jkozdon at gmail dot com 2012-10-02 22:36 ` janus at gcc dot gnu.org 2012-10-02 22:46 ` janus at gcc dot gnu.org 2012-10-02 23:44 ` janus at gcc dot gnu.org 2012-10-03 10:38 ` janus at gcc dot gnu.org 2012-10-03 16:09 ` [Bug fortran/54784] [4.7/4.8 Regression] [OOP] wrong code in polymorphic allocation with SOURCE janus at gcc dot gnu.org 2012-10-08 16:23 ` sfilippone at uniroma2 dot it 2012-10-09 10:00 ` sfilippone at uniroma2 dot it 2012-10-10 11:49 ` janus at gcc dot gnu.org 2012-10-11 17:53 ` janus at gcc dot gnu.org 2012-10-11 17:58 ` janus at gcc dot gnu.org 2012-10-14 22:16 ` janus at gcc dot gnu.org 2012-10-14 22:27 ` janus at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-54784-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).