Hi, I just committed the attached patch as obvious and simple. The problem was that clobbering of intent(out) clobbered the whole variable, instead of only the element that was actually clobbered.
There is still some optimization work that can be done here, but I will defer that to a later date - see PR 41453. Regards Thomas 2018-12-16 Thomas Koenig <tkoe...@gcc.gnu.org> PF fortran/88364 * trans-expr.c (gfc_conv_expr_reference): Do not add clobber if the expression contains a reference. 2018-12-16 Thomas Koenig <tkoe...@gcc.gnu.org> PR fortran/88364 * intent_out_13.f90: New test. Added: trunk/gcc/testsuite/gfortran.dg/intent_out_13.f90 Modified: trunk/gcc/fortran/ChangeLog trunk/gcc/fortran/trans-expr.c trunk/gcc/testsuite/ChangeLog
Index: trans-expr.c =================================================================== --- trans-expr.c (Revision 267172) +++ trans-expr.c (Arbeitskopie) @@ -8152,7 +8152,7 @@ gfc_conv_expr_reference (gfc_se * se, gfc_expr * e gfc_add_block_to_block (&se->pre, &se->post); se->expr = var; } - else if (add_clobber) + else if (add_clobber && expr->ref == NULL) { tree clobber; tree var;
! { dg-do run } ! PR 88364 -- too much was clobbered on call. module pr88364 implicit none type t integer :: b = -1 integer :: c = 2 end type t contains subroutine f1 (x) integer, intent(out) :: x x = 5 end subroutine f1 subroutine f2 () type(t) :: x call f1 (x%b) if (x%b .ne. 5 .or. x%c .ne. 2) stop 1 end subroutine f2 end module pr88364 use pr88364 call f2 end