This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR fortran/49648 ICE with use-associated array-returning function


Hello,

this is the patch I posted yesterday on bugzilla at 
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49648#c8

The problem is a NULL pointer encountered during code generation when trying 
to get the rank from the array spec.

The array ref's array spec is normally copied in resolve_ref from the symbol's 
one. It is not the case, however, in this special case (use-associated 
function return variable whose shape involves a function call).

This patch calls gfc_resolve_array_spec on sym->result, which calls 
gfc_resolve_expr on every bound, which in turn calls resolve_ref on them.

As pointed out by Tobias in the PR audit trail, there could be some similar 
bugs with character lengths. The character length variant of the testcase 
doesn't ICE however, so I have decided to propose the patch as is, because it 
should be a step forward anyway.

Regression tested on x86_64-unknown-freebsd8.2. OK for trunk? Should I 
backport to the branches?

Mikael
2011-07-07  Mikael Morin  <mikael.morin@sfr.fr>

gcc/fortran
	PR fortran/49648
	* resolve.c (resolve_symbol): Force resolution of function result's
	array specification.

gcc/testsuite
	PR fortran/49648
	* gfortran.dg/result_in_spec_4.f90: New test.

diff --git a/resolve.c b/resolve.c
index f484a22..cbf403c 100644
--- a/resolve.c
+++ b/resolve.c
@@ -12198,6 +12198,8 @@ resolve_symbol (gfc_symbol *sym)
 	    }
 	}
     }
+  else if (mp_flag && sym->attr.flavor == FL_PROCEDURE && sym->attr.function)
+    gfc_resolve_array_spec (sym->result->as, false);
 
   /* Assumed size arrays and assumed shape arrays must be dummy
      arguments.  Array-spec's of implied-shape should have been resolved to
! { dg-do compile }
!
! PR fortran/49648
! ICE for calls to a use-associated function returning an array whose spec
! depends on a function call.

! Contributed by Tobias Burnus <burnus@net-b.de>

module m2
  COMPLEX, SAVE, ALLOCATABLE :: P(:)
contains
  FUNCTION getPhaseMatrix() RESULT(PM)
    COMPLEX:: PM(SIZE(P),3)
    PM=0.0
  END FUNCTION
end module m2

module m
  use m2
contains
   SUBROUTINE gf_generateEmbPot()
      COMPLEX :: sigma2(3,3)
      sigma2 = MATMUL(getPhaseMatrix(), sigma2)
   END SUBROUTINE
end module m

! { dg-final { cleanup-modules "m m2" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]