This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Fortran, Patch] PR31188 - Allow array dummy as range for constant arrays
- From: Tobias Burnus <burnus at net-b dot de>
- To: "'fortran at gcc dot gnu dot org'" <fortran at gcc dot gnu dot org>, gcc-patches <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 15 Mar 2007 21:50:17 +0100
- Subject: [Fortran, Patch] PR31188 - Allow array dummy as range for constant arrays
:ADDPATCH fortran:
Using "letters(ivec)" where ivec is an array and dummy argument and
letters is a constant array.
Assume for a second that ivec is not an array.
When simplify_const_ref is called, one ends up in the branch:
case AR_ELEMENT:
if (find_array_element (p->value.constructor, &p->ref->u.ar,
&cons) == FAILURE)
return FAILURE;
if (!cons)
return SUCCESS;
where find_array_element contains:
if (e->expr_type != EXPR_CONSTANT)
{
cons = NULL;
goto depart;
}
Back to our case: ivec is an array. Now one ends up in:
case AR_SECTION:
if (find_array_section (p, p->ref) == FAILURE)
return FAILURE;
where find_array_section contains:
gcc_assert (begin->expr_type != EXPR_ARRAY)
which causes the ICE.
Solution: Well, I simply did the analogous thing.
Build and check-gfortran'ed on x86_64-unknown-linux-gnu.
Ok for the trunk - and when the branch is open - for 4.2?
Tobias
2007-03-15 Tobias Burnus <burnus@net-b.de>
PR fortran/31188
* expr.c (gfc_simplify_expr,find_array_section): Support
non-expression-constant variables.
2007-03-15 Tobias Burnus <burnus@net-b.de>
PR fortran/31188
* gfortran.dg/parameter_array_dummy.f90: New test.
Index: gcc/fortran/expr.c
===================================================================
*** gcc/fortran/expr.c (Revision 122956)
--- gcc/fortran/expr.c (Arbeitskopie)
*************** remove_subobject_ref (gfc_expr *p, gfc_c
*** 995,1001 ****
/* Pull an array section out of an array constructor. */
static try
! find_array_section (gfc_expr *expr, gfc_ref *ref)
{
int idx;
int rank;
--- 995,1001 ----
/* Pull an array section out of an array constructor. */
static try
! find_array_section (gfc_expr *expr, gfc_ref *ref, int *expr_const)
{
int idx;
int rank;
*************** find_array_section (gfc_expr *expr, gfc_
*** 1024,1029 ****
--- 1024,1030 ----
try t;
t = SUCCESS;
+ *expr_const = 1;
base = expr->value.constructor;
expr->value.constructor = NULL;
*************** find_array_section (gfc_expr *expr, gfc_
*** 1063,1069 ****
if (ref->u.ar.dimen_type[d] == DIMEN_VECTOR) /* Vector subscript. */
{
gcc_assert (begin);
! gcc_assert (begin->expr_type == EXPR_ARRAY);
gcc_assert (begin->rank == 1);
gcc_assert (begin->shape);
--- 1064,1075 ----
if (ref->u.ar.dimen_type[d] == DIMEN_VECTOR) /* Vector subscript. */
{
gcc_assert (begin);
! if (begin->expr_type != EXPR_ARRAY)
! {
! *expr_const = 0;
! t = SUCCESS;
! goto cleanup;
! }
gcc_assert (begin->rank == 1);
gcc_assert (begin->shape);
*************** simplify_const_ref (gfc_expr *p)
*** 1278,1283 ****
--- 1284,1290 ----
{
gfc_constructor *cons;
gfc_expr *newp;
+ int expr_const;
while (p->ref)
{
*************** simplify_const_ref (gfc_expr *p)
*** 1298,1305 ****
break;
case AR_SECTION:
! if (find_array_section (p, p->ref) == FAILURE)
return FAILURE;
p->ref->u.ar.type = AR_FULL;
/* FALLTHROUGH */
--- 1305,1314 ----
break;
case AR_SECTION:
! if (find_array_section (p, p->ref, &expr_const) == FAILURE)
return FAILURE;
+ if (!expr_const)
+ return SUCCESS;
p->ref->u.ar.type = AR_FULL;
/* FALLTHROUGH */
Index: gcc/testsuite/gfortran.dg/parameter_array_dummy.f90
===================================================================
*** gcc/testsuite/gfortran.dg/parameter_array_dummy.f90 (Revision 0)
--- gcc/testsuite/gfortran.dg/parameter_array_dummy.f90 (Revision 0)
***************
*** 0 ****
--- 1,21 ----
+ ! { dg-do run}
+ ! PR fortran/31188
+ program foo_mod
+ implicit none
+ character (len=1), parameter :: letters(2) = (/"a","b"/)
+ call concat(1, [1])
+ call concat(2, [2])
+ call concat(3, [1,2])
+ call concat(4, [2,1])
+ call concat(5, [2,2,2])
+ contains
+ subroutine concat(i, ivec)
+ integer, intent(in) :: i, ivec(:)
+ write (*,*) i, "a" // letters(ivec)
+ end subroutine concat
+ end program foo_mod
+ ! { dg-output "1 aa" }
+ ! { dg-output "2 ab" }
+ ! { dg-output "3 aaab" }
+ ! { dg-output "4 abaa" }
+ ! { dg-output "5 ababab" }