This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[Patch, fortran] PR25597 and PR27096 - automatic character, pointer array results.
- From: Paul Thomas <paulthomas2 at wanadoo dot fr>
- To: patch <gcc-patches at gcc dot gnu dot org>, "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>
- Date: Mon, 10 Apr 2006 18:45:18 +0200
- Subject: [Patch, fortran] PR25597 and PR27096 - automatic character, pointer array results.
:ADDPATCH fortran:
This patch fixes another bug (PR27096) that prevents compilation of
tonto-2.2 and follows on yesterdays patch
http://gcc.gnu.org/ml/gcc-patches/2006-04/msg00322.html
The attached test case reproduces the error, which occurs on
vec{str}.F90, line 408 of tonto. In the course of investigating this
bug, I fixed another, related bug (PR25597).
Unfortunately, the next bug looks rather bad at this time of the day:
UNKNOWN-gfortran-on-LINUX/f95files/atom.F90:2133: fatal error: gfc_todo:
Not Implemented: complex character array constructors
compilation terminated. I am beginning to wish that I had started with
tonto-1.0!
PR27096 causes an ICE when explicit, automatic character length,
pointer array results are translated.
test2.f90:1: internal compiler error: in gfc_trans_deferred_array, at
fortran/trans-array.c:4394
This comes about because the descriptor that is being checked for is
pointed to by the backend declaration. The patch branches on the
declaration not being a descriptor, dereferences and then tests that the
type is a descriptor.
PR25597 now causes a runtime failure because the character length is not
processed in the case of implicit function results. This comes about
because arrays and automatic character results are treated separately in
a series of if else's. The simplest approach to fixing this is to
reproduce the character treatment, within the array block.
Regtested on FC3/Athlon1700. OK for trunk and 4.1?
Paul
2006-04-10 Paul Thomas <pault@gcc.gnu.org>
PR fortran/27096
* trans-array.c (gfc_trans_deferred_array): If the backend_decl
is not a descriptor, dereference and then test and use the type.
PR fortran/25597
* trans-decl.c (gfc_trans_deferred_vars): Check if an array
result, is also automatic character length. If so, process
the character length.
2006-04-10 Paul Thomas <pault@gcc.gnu.org>
PR fortran/27096
PR fortran/25597
* gfortran.dg/auto_pointer_array_result_1.f90: New test.
! { dg-do run }
! Tests the fixes for PR25597 and PR27096.
!
! This test combines the PR testcases.
!
character(10), dimension (2) :: implicit_result
character(10), dimension (2) :: explicit_result
character(10), dimension (2) :: source
source = "abcdefghij"
explicit_result = join_1(source)
if (any (explicit_result .ne. source)) call abort ()
implicit_result = reallocate_hnv (source, size(source, 1), LEN (source))
if (any (implicit_result .ne. source)) call abort ()
contains
! This function would cause an ICE in gfc_trans_deferred_array.
function join_1(self) result(res)
character(len=*), dimension(:) :: self
character(len=len(self)), dimension(:), pointer :: res
allocate (res(2))
res = self
end function
! This function originally ICEd and latterly caused a runtime error.
FUNCTION reallocate_hnv(p, n, LEN)
CHARACTER(LEN=LEN), DIMENSION(:), POINTER :: reallocate_hnv
character(*), dimension(:) :: p
ALLOCATE (reallocate_hnv(n))
reallocate_hnv = p
END FUNCTION reallocate_hnv
end
Index: gcc/fortran/trans-array.c
===================================================================
*** gcc/fortran/trans-array.c (revision 112712)
--- gcc/fortran/trans-array.c (working copy)
*************** gfc_trans_deferred_array (gfc_symbol * s
*** 4391,4397 ****
/* Get the descriptor type. */
type = TREE_TYPE (sym->backend_decl);
! gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
/* NULLIFY the data pointer. */
gfc_conv_descriptor_data_set (&fnblock, descriptor, null_pointer_node);
--- 4391,4404 ----
/* Get the descriptor type. */
type = TREE_TYPE (sym->backend_decl);
! if (!GFC_DESCRIPTOR_TYPE_P (type))
! {
! /* If the backend_decl is not a descriptor, we must have a pointer
! to one. */
! descriptor = build_fold_indirect_ref (sym->backend_decl);
! type = TREE_TYPE (descriptor);
! gcc_assert (GFC_DESCRIPTOR_TYPE_P (type));
! }
/* NULLIFY the data pointer. */
gfc_conv_descriptor_data_set (&fnblock, descriptor, null_pointer_node);
Index: gcc/fortran/trans-decl.c
===================================================================
*** gcc/fortran/trans-decl.c (revision 112712)
--- gcc/fortran/trans-decl.c (working copy)
*************** gfc_trans_deferred_vars (gfc_symbol * pr
*** 2536,2541 ****
--- 2536,2547 ----
{
tree result = TREE_VALUE (current_fake_result_decl);
fnbody = gfc_trans_dummy_array_bias (proc_sym, result, fnbody);
+
+ /* An automatic character length, pointer array result. */
+ if (proc_sym->ts.type == BT_CHARACTER
+ && TREE_CODE (proc_sym->ts.cl->backend_decl) == VAR_DECL)
+ fnbody = gfc_trans_dummy_character (proc_sym, proc_sym->ts.cl,
+ fnbody);
}
else if (proc_sym->ts.type == BT_CHARACTER)
{