[Bug fortran/88393] New: [7/8/9 Regression] [OOP] Segfault with type-bound assignment

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] New: [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

            Bug ID: 88393
           Summary: [7/8/9 Regression] [OOP] Segfault with type-bound
                    assignment
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janus at gcc dot gnu.org
  Target Milestone: ---

Simple test case:


module m
   implicit none
   type :: t
      character(len=:), allocatable :: cs
   contains
      procedure :: ass
      generic :: assignment(=) => ass
   end type
contains
   subroutine ass(a, b)
      class(t), intent(inout) :: a
      class(t), intent(in)    :: b
      print *, "ass"
   end subroutine
end module

program p
   use m
   implicit none
   type :: t2
      type(t) :: c
   end type
   type(t2), dimension(1:2) :: arr
   arr(2)%c = arr(1)%c
   print *, "done"
end


While this runs flawlessly with gfortran 6.4.0, it segfaults at runtime with
7.3.0 and above.
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P4
      Known to work|                            |6.4.0
   Target Milestone|---                         |7.5
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-12-09
     Ever confirmed|0                           |1
      Known to fail|                            |7.3.0, 8.2.0, 9.0

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
The test compiled with r241883 + patches (2016-11-06) gives the expected
result, compiled with r241924 + patches (2016-11-07) gives a segfault at run
time.
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

--- Comment #2 from janus at gcc dot gnu.org ---
(In reply to Dominique d'Humieres from comment #1)
> The test compiled with r241883 + patches (2016-11-06) gives the expected
> result, compiled with r241924 + patches (2016-11-07) gives a segfault at run
> time.

Thanks for the information. Looking at this range of commits, I suspect that
r241885 is the culprit.
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

janus at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |vehre at gcc dot gnu.org

--- Comment #3 from janus at gcc dot gnu.org ---
(In reply to janus from comment #2)
> Looking at this range of commits, I suspect that r241885 is the culprit.


Using -fdump-tree-original to compare the dumps of versions 6 and 7 shows that
the assignment subroutine itself is identical in both, but the dump from v7
contains additional code after the call to 'ass' that is not present in v6.

With v6, the call is translated as follows:

  {
    struct __class_m_T_t class.7;
    struct __class_m_T_t class.8;

    class.7._vptr = (struct __vtype_m_T * {ref-all}) &__vtab_m_T;
    class.7._data = &arr[1].c;
    class.8._vptr = (struct __vtype_m_T * {ref-all}) &__vtab_m_T;
    class.8._data = &arr[0].c;
    ass (&class.7, &class.8);
  }


With v7, it looks much bulkier:

  {
    struct __class_m_T_t class.7;
    struct __class_m_T_t class.8;
    struct t D.3602;
    struct __class_m_T_t * D.3603;
    struct __class_m_T_t D.3604;
    void * restrict D.3605;

    class.7._vptr = (struct __vtype_m_T * {ref-all}) &__vtab_m_T;
    class.7._data = &arr[1].c;
    class.8._vptr = (struct __vtype_m_T * {ref-all}) &__vtab_m_T;
    D.3602 = arr[0].c;
    class.8._data = &D.3602;
    D.3603 = &class.8;
    D.3604 = *D.3603;
    ass (&class.7, D.3603);
    D.3603->_cs_length = D.3604._cs_length;
    if ((void *) D.3604.cs != 0B)
      {
        D.3605 = (void * restrict) __builtin_malloc (MAX_EXPR <(unsigned long)
D.3603->_cs_length, 1>);
        D.3603->cs = (character(kind=1)[1:0] *) D.3605;
        __builtin_memcpy (D.3603->cs, D.3604.cs, (unsigned long)
D.3603->_cs_length);
      }
    else
      {
        D.3603->cs = 0B;
      }
    if (D.3603->_data->cs != 0B)
      {
        __builtin_free ((void *) D.3603->_data->cs);
        D.3603->_data->cs = 0B;
      }
  }

Looks like there is some copying and deallocation of the allocatable components
here. Not sure why that would be necessary ...?!?
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

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 #4 from Paul Thomas <pault at gcc dot gnu.org> ---
I am just about to post a patch.

Paul
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

--- Comment #5 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Sat Feb  2 09:23:30 2019
New Revision: 268474

URL: https://gcc.gnu.org/viewcvs?rev=268474&root=gcc&view=rev
Log:
2019-02-02  Paul Thomas  <[hidden email]>

        PR fortran/88393
        * trans-expr.c (gfc_conv_procedure_call): For derived entities,
        passed in parentheses to class formals, invert the order of
        copying allocatable components to taking the _data of the
        class expression.

2019-02-02  Paul Thomas  <[hidden email]>

        PR fortran/88393
        * gfortran.dg/alloc_comp_assign_16.f03 : New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_assign_16.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-expr.c
    trunk/gcc/testsuite/ChangeLog
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Sun Feb  3 14:50:07 2019
New Revision: 268489

URL: https://gcc.gnu.org/viewcvs?rev=268489&root=gcc&view=rev
Log:
2019-02-03  Paul Thomas  <[hidden email]>

        Backport from trunk
        PR fortran/88393
        * trans-expr.c (gfc_conv_procedure_call): For derived entities,
        passed in parentheses to class formals, invert the order of
        copying allocatable components to taking the _data of the
        class expression.

2019-02-03  Paul Thomas  <[hidden email]>

        Backport from trunk
        PR fortran/88393
        * gfortran.dg/alloc_comp_assign_16.f03 : New test.


Added:
    branches/gcc-8-branch/gcc/testsuite/gfortran.dg/alloc_comp_assign_16.f03
Modified:
    branches/gcc-8-branch/gcc/fortran/ChangeLog
    branches/gcc-8-branch/gcc/fortran/trans-expr.c
    branches/gcc-8-branch/gcc/testsuite/ChangeLog
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

--- Comment #7 from Paul Thomas <pault at gcc dot gnu.org> ---
Author: pault
Date: Sun Feb  3 18:23:25 2019
New Revision: 268501

URL: https://gcc.gnu.org/viewcvs?rev=268501&root=gcc&view=rev
Log:
2019-02-03  Paul Thomas  <[hidden email]>

        Backport from trunk
        PR fortran/88393
        * trans-expr.c (gfc_conv_procedure_call): For derived entities,
        passed in parentheses to class formals, invert the order of
        copying allocatable components to taking the _data of the
        class expression.

2019-02-03  Paul Thomas  <[hidden email]>

        Backport from trunk
        PR fortran/88393
        * gfortran.dg/alloc_comp_assign_16.f03 : New test.


Added:
    branches/gcc-7-branch/gcc/testsuite/gfortran.dg/alloc_comp_assign_16.f03
Modified:
    branches/gcc-7-branch/gcc/fortran/ChangeLog
    branches/gcc-7-branch/gcc/fortran/trans-expr.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Reply | Threaded
Open this post in threaded view
|

[Bug fortran/88393] [7/8/9 Regression] [OOP] Segfault with type-bound assignment

mpolacek at gcc dot gnu.org
In reply to this post by mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88393

Paul Thomas <pault at gcc dot gnu.org> changed:

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

--- Comment #8 from Paul Thomas <pault at gcc dot gnu.org> ---
Fixed on all affected branches.

Thanks for the report

Paul