* [Patch, Fortran] PR fortran/49648 ICE with use-associated array-returning function
@ 2011-07-07 10:44 Mikael Morin
2011-07-07 12:28 ` Tobias Burnus
0 siblings, 1 reply; 2+ messages in thread
From: Mikael Morin @ 2011-07-07 10:44 UTC (permalink / raw)
To: fortran; +Cc: gcc-patches
[-- Attachment #1: Type: text/plain, Size: 963 bytes --]
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
[-- Attachment #2: pr49648.diff --]
[-- Type: text/x-patch, Size: 701 bytes --]
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
[-- Attachment #3: result_in_spec_4.f90 --]
[-- Type: text/x-fortran, Size: 573 bytes --]
! { 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" } }
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Patch, Fortran] PR fortran/49648 ICE with use-associated array-returning function
2011-07-07 10:44 [Patch, Fortran] PR fortran/49648 ICE with use-associated array-returning function Mikael Morin
@ 2011-07-07 12:28 ` Tobias Burnus
0 siblings, 0 replies; 2+ messages in thread
From: Tobias Burnus @ 2011-07-07 12:28 UTC (permalink / raw)
To: Mikael Morin; +Cc: fortran, gcc-patches
Dear Mikael,
On 07/07/2011 12:42 PM, Mikael Morin wrote:
> this is the patch I posted yesterday on bugzilla at
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49648#c8
>
> 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.
My impression is that the type-spec - contrary to the array spec - is
shared between the function symbol and the result symbol. That's also
what I get for the example you posted, when looking at the expressions
in the debugger. Thus, it seems as the array spec is the only case where
one needs to do something.
> Regression tested on x86_64-unknown-freebsd8.2. OK for trunk? Should I
> backport to the branches?
OK. Regarding backporting: I don't know; I don't have a strong opinion.
It's not a regression - but it is also a simple fix. Thus, backporting
to 4.6 should be OK, but I wouldn't port it to older versions.
Thanks a lot for the patch and going though resolve.c!
Tobias
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-07-07 12:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-07 10:44 [Patch, Fortran] PR fortran/49648 ICE with use-associated array-returning function Mikael Morin
2011-07-07 12:28 ` Tobias Burnus
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).