[PATCH] Fix PR fortran/19926
Steve Kargl
sgk@troutmask.apl.washington.edu
Mon Jun 13 01:47:00 GMT 2005
The attached patch fixes PR fortran/19926. The problem
is easiest to explain by looking at the snippet of code
from the PR.
subroutine string_comp(i)
integer, parameter :: map(0:50) = 3
integer :: i
i = map(42)
end subroutine string_comp
The problem lies in primary.c:gfc_match_rvalue() where we are
parsing/resolving a PARAMETER expression. The above parameter
sets sym->value->expr_type = EXPR_CONSTANT, so a branch of an
if statement that test (sym->value->expr_type != EXPR_ARRAY)
because expr_type cannot simultaneous be EXPR_CONSTANT and
EXPR_ARRAY. To get to the else portion of the test we
can check if sym->as is non-NULL, which indicates that we have
an array with constant content.
Hopefully, the above makes sense, and the patch does the
right thing.
Bootstrapped and regression tested on i386-*-freebsd.
There are no new regressions with this patch.
Erik found the location of bug and provided the initial
patch. I've changed the patch to the current stated.
2005-06-12 Erik Edelman <eedelman@acclab.helsinki.fi>
Steven G. Kargl <kargls@comast.net>
PR fortran/19926
* primary.c (gfc_match_rvalue): expr_type can be EXPR_CONSTANT
for an array; check that sym->as is NULL.
--
Steve
-------------- next part --------------
Index: primary.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/primary.c,v
retrieving revision 1.25
diff -c -p -r1.25 primary.c
*** primary.c 25 Apr 2005 00:08:59 -0000 1.25
--- primary.c 13 Jun 2005 01:28:30 -0000
*************** gfc_match_rvalue (gfc_expr ** result)
*** 1802,1809 ****
break;
case FL_PARAMETER:
! if (sym->value
! && sym->value->expr_type != EXPR_ARRAY)
e = gfc_copy_expr (sym->value);
else
{
--- 1802,1812 ----
break;
case FL_PARAMETER:
! /* A statement of the form "REAL, parameter :: a(0:10) = 1" will
! end up here. Unfortunately, sym->value->expr_type is set to
! EXPR_CONSTANT, and so the if () branch would be followed without
! the !sym->as check. */
! if (sym->value && sym->value->expr_type != EXPR_ARRAY && !sym->as)
e = gfc_copy_expr (sym->value);
else
{
-------------- next part --------------
! { dg-do run }
module b
type cat
integer :: i = 0
end type cat
end module b
program a
use b
type(cat) z
integer :: i = 0, j(4,3,2) = 0
call string_comp(i)
if (i /= 3) call abort
call string_comp(z%i)
if (z%i /= 3) call abort
call string_comp(j(1,2,1))
if (j(1,2,1) /= 3) call abort
end program a
subroutine string_comp(i)
integer, parameter :: map(0:50) = 3
integer :: i
i = map(42)
end subroutine string_comp
More information about the Fortran
mailing list