public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/64230] [4.9/5 Regression] Segmentation fault - invalid memory reference in a compiler-generated finalizer for a complicated type hierarchy when a polymorphic variable is allocated in an external procedure.
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
@ 2014-12-08 21:45 ` Joost.VandeVondele at mat dot ethz.ch
  2014-12-09 12:38 ` rguenth at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2014-12-08 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-12-08
                 CC|                            |Joost.VandeVondele at mat dot ethz
                   |                            |.ch
      Known to work|                            |4.8.3
   Target Milestone|---                         |4.9.3
            Summary|Segmentation fault -        |[4.9/5 Regression]
                   |invalid memory reference in |Segmentation fault -
                   |a compiler-generated        |invalid memory reference in
                   |finalizer for a complicated |a compiler-generated
                   |type hierarchy when a       |finalizer for a complicated
                   |polymorphic variable is     |type hierarchy when a
                   |allocated in an external    |polymorphic variable is
                   |procedure.                  |allocated in an external
                   |                            |procedure.
     Ever confirmed|0                           |1
      Known to fail|                            |4.9.2, 5.0

--- Comment #1 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> ---
yes, confirmed, also with trunk (and -fsanitize=undefined)

> gfortran -g -fno-omit-frame-pointer -fsanitize=undefined t.f90 && ./a.out
t.f90:24: runtime error: member access within null pointer of type 'struct t6'


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

* [Bug fortran/64230] [4.9/5 Regression] Segmentation fault - invalid memory reference in a compiler-generated finalizer for a complicated type hierarchy when a polymorphic variable is allocated in an external procedure.
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
  2014-12-08 21:45 ` [Bug fortran/64230] [4.9/5 Regression] Segmentation fault - invalid memory reference in a compiler-generated finalizer for a complicated type hierarchy when a polymorphic variable is allocated in an external procedure Joost.VandeVondele at mat dot ethz.ch
@ 2014-12-09 12:38 ` rguenth at gcc dot gnu.org
  2014-12-15 19:12 ` janus at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-12-09 12:38 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4


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

* [Bug fortran/64230] [4.9/5 Regression] Segmentation fault - invalid memory reference in a compiler-generated finalizer for a complicated type hierarchy when a polymorphic variable is allocated in an external procedure.
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
  2014-12-08 21:45 ` [Bug fortran/64230] [4.9/5 Regression] Segmentation fault - invalid memory reference in a compiler-generated finalizer for a complicated type hierarchy when a polymorphic variable is allocated in an external procedure Joost.VandeVondele at mat dot ethz.ch
  2014-12-09 12:38 ` rguenth at gcc dot gnu.org
@ 2014-12-15 19:12 ` janus at gcc dot gnu.org
  2015-01-19 14:10 ` janus at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu.org @ 2014-12-15 19:12 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
                 CC|                            |janus at gcc dot gnu.org

--- Comment #2 from janus at gcc dot gnu.org ---
Here is a somewhat reduced test case, which gets rid of parts of the insane
inheritance chain:


Program main
  Implicit None
  Type :: t1
  End Type
  Type, Extends (t1) :: t2
    Integer, Allocatable :: i
  End Type
  Type, Extends (t2) :: t3
    Integer, Allocatable :: j
  End Type
  Class (t1), Allocatable :: t
  Allocate (t3 :: t)
  print *,"allocated!"
  Deallocate (t)
End


$ gfortran-5.0 -g -fsanitize=undefined c0.f90 && ./a.out
 allocated!
c0.f90:1: runtime error: member access within null pointer of type 'struct t2'

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x7FC890D235F7
#1  0x7FC890D23C3E
#2  0x7FC88F557D9F
#3  0x402423 in __final_main_T2 at c0.f90:1 (discriminator 12)
#4  0x4015B1 in __final_main_T3 at c0.f90:1 (discriminator 8)
#5  0x401806 in MAIN__ at c0.f90:14 (discriminator 3)
Speicherzugriffsfehler (Speicherabzug geschrieben)


The segfault obviously happens in the deallocate statement, for which
-fdump-tree-original shows the following translation:

      if (t._data == 0B)
        {
          _gfortran_runtime_error_at (...);
        }
      else
        {
          if (t._vptr->_final != 0B)
            {
              {
                struct array0_t1 desc.13;

                desc.13.dtype = 40;
                desc.13.data = (void * restrict) t._data;
                t._vptr->_final (&desc.13, t._vptr->_size, 0);
              }
            }
          __builtin_free ((void *) t._data);
        }
      t._data = 0B;
      (struct __vtype_main_T1 *) t._vptr = &__vtab_main_T1;


So, yeah, the problem is somewhere in the finalizer call ("t._vptr->_final"),
but I don't directly see where in the finalization routine it occurs (the
compiler generates a 500+ line dump for a 15-line program here).


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

* [Bug fortran/64230] [4.9/5 Regression] Segmentation fault - invalid memory reference in a compiler-generated finalizer for a complicated type hierarchy when a polymorphic variable is allocated in an external procedure.
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2014-12-15 19:12 ` janus at gcc dot gnu.org
@ 2015-01-19 14:10 ` janus at gcc dot gnu.org
  2015-01-26 15:57 ` [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component janus at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu.org @ 2015-01-19 14:10 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |janus at gcc dot gnu.org

--- Comment #3 from janus at gcc dot gnu.org ---
Have a patch ...


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

* [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2015-01-19 14:10 ` janus at gcc dot gnu.org
@ 2015-01-26 15:57 ` janus at gcc dot gnu.org
  2015-01-26 18:54 ` janus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu.org @ 2015-01-26 15:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from janus at gcc dot gnu.org ---
Author: janus
Date: Mon Jan 26 15:56:03 2015
New Revision: 220125

URL: https://gcc.gnu.org/viewcvs?rev=220125&root=gcc&view=rev
Log:
2015-01-26  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/64230
    * class.c (finalize_component): New argument 'sub_ns'. Insert code to
    check if 'expr' is associated.
    (generate_finalization_wrapper): Rename 'ptr' symbols to 'ptr1' and
    'ptr2'. Pass 'sub_ns' to finalize_component.

2015-01-26  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/64230
    * gfortran.dg/class_allocate_18.f90: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_allocate_18.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/class.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2015-01-26 15:57 ` [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component janus at gcc dot gnu.org
@ 2015-01-26 18:54 ` janus at gcc dot gnu.org
  2015-01-26 18:55 ` janus at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu.org @ 2015-01-26 18:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from janus at gcc dot gnu.org ---
Author: janus
Date: Mon Jan 26 18:53:42 2015
New Revision: 220130

URL: https://gcc.gnu.org/viewcvs?rev=220130&root=gcc&view=rev
Log:
2015-01-26  Janus Weil  <janus@gcc.gnu.org>

    Backport from mainline
    PR fortran/64230
    * class.c (finalize_component): New argument 'sub_ns'. Insert code to
    check if 'expr' is associated.
    (generate_finalization_wrapper): Rename 'ptr' symbols to 'ptr1' and
    'ptr2'. Pass 'sub_ns' to finalize_component.

2015-01-26  Janus Weil  <janus@gcc.gnu.org>

    Backport from mainline
    PR fortran/64230
    * gfortran.dg/class_allocate_18.f90: New.

Added:
    branches/gcc-4_9-branch/gcc/testsuite/gfortran.dg/class_allocate_18.f90
Modified:
    branches/gcc-4_9-branch/gcc/fortran/ChangeLog
    branches/gcc-4_9-branch/gcc/fortran/class.c
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog


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

* [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2015-01-26 18:54 ` janus at gcc dot gnu.org
@ 2015-01-26 18:55 ` janus at gcc dot gnu.org
  2015-01-27 18:37 ` janus at gcc dot gnu.org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu.org @ 2015-01-26 18:55 UTC (permalink / raw)
  To: gcc-bugs

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

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from janus at gcc dot gnu.org ---
Fixed on trunk and 4.9. Closing.

Thanks for the report!


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

* [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2015-01-26 18:55 ` janus at gcc dot gnu.org
@ 2015-01-27 18:37 ` janus at gcc dot gnu.org
  2015-01-27 19:50 ` janus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu.org @ 2015-01-27 18:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from janus at gcc dot gnu.org ---
Author: janus
Date: Tue Jan 27 18:36:52 2015
New Revision: 220181

URL: https://gcc.gnu.org/viewcvs?rev=220181&root=gcc&view=rev
Log:
2015-01-27  Janus Weil  <janus@gcc.gnu.org>

    PR fortran/64230
    * gfortran.dg/class_allocate_18.f90: Remove -fsanitize option to
    prevent linking errors.

Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/class_allocate_18.f90


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

* [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2015-01-27 18:37 ` janus at gcc dot gnu.org
@ 2015-01-27 19:50 ` janus at gcc dot gnu.org
  2015-04-24 12:39 ` mathewc at nag dot co.uk
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu.org @ 2015-01-27 19:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from janus at gcc dot gnu.org ---
Author: janus
Date: Tue Jan 27 19:49:55 2015
New Revision: 220187

URL: https://gcc.gnu.org/viewcvs?rev=220187&root=gcc&view=rev
Log:
2015-01-27  Janus Weil  <janus@gcc.gnu.org>

    Backport from mainline
    PR fortran/64230
    * gfortran.dg/class_allocate_18.f90: Remove -fsanitize option to
    prevent linking errors.

Modified:
    branches/gcc-4_9-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_9-branch/gcc/testsuite/gfortran.dg/class_allocate_18.f90


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

* [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2015-01-27 19:50 ` janus at gcc dot gnu.org
@ 2015-04-24 12:39 ` mathewc at nag dot co.uk
  2015-04-25  7:49 ` dominiq at lps dot ens.fr
  2015-04-27  6:45 ` mathewc at nag dot co.uk
  11 siblings, 0 replies; 12+ messages in thread
From: mathewc at nag dot co.uk @ 2015-04-24 12:39 UTC (permalink / raw)
  To: gcc-bugs

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

Mat Cross <mathewc at nag dot co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--- Comment #9 from Mat Cross <mathewc at nag dot co.uk> ---
Thanks for the progress so far.

I built 4.9.3 to try on my larger piece of code. The problem still seems
present:

> uname -a
Linux whakarewarewa.nag.co.uk 3.19.4-200.fc21.x86_64 #1 SMP Mon Apr 13 21:43:26
UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

> gfortran --version
GNU Fortran (GCC) 4.9.3 20150415 (prerelease)

> cat test.f90
Program test
  Implicit None
  Type :: t1
    Integer, Allocatable :: i
  End Type
  Type :: t2
    Integer, Allocatable :: i
  End Type
  Type, Extends (t1) :: t3
    Type (t2) :: j
  End Type
  Type, Extends (t3) :: t4
    Integer, Allocatable :: k
  End Type
  Class (t1), Allocatable :: x
  Allocate (t4 :: x)
  Deallocate (x)
  Print *, 'ok'
End Program

> gfortran test.f90 && ./a.out

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x2B51E7B11417
#1  0x2B51E7B11A2E
#2  0x3265A3495F
#3  0x401392 in __final_test_T3.2353 at test.f90:?
#4  0x400D45 in __final_test_T4.2342 at test.f90:?
#5  0x400E87 in MAIN__ at test.f90:?
Segmentation fault (core dumped)

Do you see this too?

I hope that reopening this PR is acceptable. If not then just let me know and I
will happily file a new one.


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

* [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2015-04-24 12:39 ` mathewc at nag dot co.uk
@ 2015-04-25  7:49 ` dominiq at lps dot ens.fr
  2015-04-27  6:45 ` mathewc at nag dot co.uk
  11 siblings, 0 replies; 12+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-04-25  7:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> Do you see this too?

Yes, and the test runs if I remove/comment the line

  Deallocate (x)

The test gfortran.dg/class_allocate_18.f90 has the same problem: see pr64921.

> I hope that reopening this PR is acceptable. If not then just let me know
> and I will happily file a new one.

IMO it is better to file a new PR rather than reopening an old one. In the
present case, I think the problem reported in comment 9 is already tracked by
pr64921 (duplicate).


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

* [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component
       [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
                   ` (10 preceding siblings ...)
  2015-04-25  7:49 ` dominiq at lps dot ens.fr
@ 2015-04-27  6:45 ` mathewc at nag dot co.uk
  11 siblings, 0 replies; 12+ messages in thread
From: mathewc at nag dot co.uk @ 2015-04-27  6:45 UTC (permalink / raw)
  To: gcc-bugs

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

Mat Cross <mathewc at nag dot co.uk> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #11 from Mat Cross <mathewc at nag dot co.uk> ---
I've restored the closure status and I'll keep an eye on how PR64921 goes.


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

end of thread, other threads:[~2015-04-27  6:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-64230-4@http.gcc.gnu.org/bugzilla/>
2014-12-08 21:45 ` [Bug fortran/64230] [4.9/5 Regression] Segmentation fault - invalid memory reference in a compiler-generated finalizer for a complicated type hierarchy when a polymorphic variable is allocated in an external procedure Joost.VandeVondele at mat dot ethz.ch
2014-12-09 12:38 ` rguenth at gcc dot gnu.org
2014-12-15 19:12 ` janus at gcc dot gnu.org
2015-01-19 14:10 ` janus at gcc dot gnu.org
2015-01-26 15:57 ` [Bug fortran/64230] [4.9/5 Regression] Invalid memory reference in a compiler-generated finalizer for allocatable component janus at gcc dot gnu.org
2015-01-26 18:54 ` janus at gcc dot gnu.org
2015-01-26 18:55 ` janus at gcc dot gnu.org
2015-01-27 18:37 ` janus at gcc dot gnu.org
2015-01-27 19:50 ` janus at gcc dot gnu.org
2015-04-24 12:39 ` mathewc at nag dot co.uk
2015-04-25  7:49 ` dominiq at lps dot ens.fr
2015-04-27  6:45 ` mathewc at nag dot co.uk

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