public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "james.s.spencer at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/59781] New: Incorrect initialisation of derived type
Date: Sun, 12 Jan 2014 21:26:00 -0000	[thread overview]
Message-ID: <bug-59781-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 59781
           Summary: Incorrect initialisation of derived type
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: james.s.spencer at gmail dot com

Created attachment 31818
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=31818&action=edit
Tarball containing example code, tree produced by gfortran 4.8.2 and Makefile.

(Complete modules and a makefile is attached.  Also confirmed against 4.6.3)

With the definition

type dSFMT_t
    private
    type(c_ptr) :: dSFMT_state = c_null_ptr
    real(c_double), allocatable :: random_store(:)
end type dSFMT_t

the dSFMT_t objects in the following module should both be initialised with a
null pointer for the dSFMT_state component:

module hilbert_space
implicit none
contains
    subroutine test_rng()
        use dSFMT_interface
        type(dSFMT_t) :: rng
        call dSFMT_init(7, 50000, rng)
    end subroutine test_rng
    subroutine estimate_hilbert_space()
        use dSFMT_interface
        type(dSFMT_t) :: rng
        call dSFMT_init(7, 50000, rng)
    end subroutine estimate_hilbert_space
end module hilbert_space

Instead only the rng object in estimate_hilbert_space is correctly initialised.
 The relevant parts of the tree are:

estimate_hilbert_space ()                                                       
{                                                                               
  struct dsfmt_t rng;                                                           

  try                                                                           
    {                                                                           
      {                                                                         
        struct dsfmt_t dsfmt_t.0;                                               

        dsfmt_t.0.dsfmt_state = 0B;                                             
        dsfmt_t.0.random_store.data = 0B;                                       
        rng = dsfmt_t.0;                                                        
      }                                                                         
      [...]
    }                                                                           
}                                                                               


test_rng ()                                                                     
{                                                                               
  struct dsfmt_t rng;                                                           

  try                                                                           
    {                                                                           
      rng.random_store.data = 0B;
      [...]
    }                                                                           
}     


This bug is tricky to observe---small changes to the code (e.g. making rng a
pointer, code reorganisation, having additional or fewer procedures in the same
file, removing the random_store allocatable component etc. can lead to the
dSFMT_t objects being correctly initialised.  I had the above code (with
additions) in a large code base for several months until an innocuous
refactoring revealed it.

See also discussion at
https://groups.google.com/forum/#!topic/comp.lang.fortran/WogpvhUny4c, where
Janus posted a smaller example which breaks under gfortran trunk.


             reply	other threads:[~2014-01-12 21:26 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-12 21:26 james.s.spencer at gmail dot com [this message]
2014-01-12 21:41 ` [Bug fortran/59781] [4.9 Regression] [F03] " janus at gcc dot gnu.org
2014-01-12 21:56 ` janus at gcc dot gnu.org
2014-01-13  8:38 ` [Bug fortran/59781] [4.7/4.8/4.9 " janus at gcc dot gnu.org
2014-01-13  8:56 ` dominiq at lps dot ens.fr
2014-01-13  9:18 ` jakub at gcc dot gnu.org
2014-01-13 15:49 ` janus at gcc dot gnu.org
2014-01-13 19:58 ` janus at gcc dot gnu.org
2014-04-22 11:38 ` [Bug fortran/59781] [4.7/4.8/4.9/4.10 " jakub at gcc dot gnu.org
2014-07-16 13:30 ` [Bug fortran/59781] [4.8/4.9/4.10 " jakub at gcc dot gnu.org
2014-10-30 10:42 ` [Bug fortran/59781] [4.8/4.9/5 " jakub at gcc dot gnu.org
2015-06-26 19:56 ` [Bug fortran/59781] [4.9/5/6 " jakub at gcc dot gnu.org
2015-06-26 20:28 ` jakub 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-59781-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: link
Be 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).