From: Fritz Reese Date: Sat, 14 May 2016 15:29:13 +0000 (+0000) Subject: re PR fortran/71047 (Allocatable component of INTENT(OUT) dummy not set correctly) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e75eb64fdf7296fa333f49f0186f1e219fed16ad;p=gcc.git re PR fortran/71047 (Allocatable component of INTENT(OUT) dummy not set correctly) 2016-05-14 Fritz Reese PR fortran/71047 * expr.c (gfc_default_initializer): Avoid extra component refs in constructors for derived types and classes. 2016-05-14 Fritz Reese PR fortran/71047 * gfortran.dg/pr71047.f08: New test. From-SVN: r236241 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 3d79fcaec21..a0256e13adb 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2016-05-14 Fritz Reese + + PR fortran/71047 + * expr.c (gfc_default_initializer): Avoid extra component refs in + constructors for derived types and classes. + 2016-05-11 Jakub Jelinek PR fortran/70855 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 6ebe08b7538..d1258cdf380 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -3975,7 +3975,10 @@ gfc_default_initializer (gfc_typespec *ts) if (comp->initializer) { - ctor->n.component = comp; + /* Save the component ref for STRUCTUREs and UNIONs. */ + if (ts->u.derived->attr.flavor == FL_STRUCT + || ts->u.derived->attr.flavor == FL_UNION) + ctor->n.component = comp; ctor->expr = gfc_copy_expr (comp->initializer); if ((comp->ts.type != comp->initializer->ts.type || comp->ts.kind != comp->initializer->ts.kind) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3916695f6f7..9ca19ae6c00 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-14 Fritz Reese + + PR fortran/71047 + * gfortran.dg/pr71047.f08: New test. + 2016-05-13 Joseph Myers * gcc.dg/qual-return-5.c, gcc.dg/qual-return-6.c: New tests. diff --git a/gcc/testsuite/gfortran.dg/pr71047.f08 b/gcc/testsuite/gfortran.dg/pr71047.f08 new file mode 100644 index 00000000000..61a0ad4dc31 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr71047.f08 @@ -0,0 +1,48 @@ +! { dg-do compile } +! { dg-options "-fdump-tree-original" } +! +! Fortran/PR71047 +! + +module m + implicit none + + type, abstract :: c_abstr + integer :: i = 0 + end type c_abstr + + type, extends(c_abstr) :: t_a + class(c_abstr), allocatable :: f + end type t_a + + type, extends(c_abstr) :: t_b + end type t_b + +contains + + subroutine set(y,x) + class(c_abstr), intent(in) :: x + type(t_a), intent(out) :: y + allocate( y%f , source=x ) + end subroutine set + +end module m + + +program p + use m + implicit none + + type(t_a) :: res + type(t_b) :: var + + call set( res , var ) + write(*,*) res%i + +end program p + +! +! Check to ensure the vtable is actually initialized. +! +! { dg-final { scan-tree-dump "t_a\\.\\d+\\.f\\._vptr =" "original" } } +!