This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
[patch, fortran] PR41807 [4.5/4.4 Regression] data statement with nested type constructors
- From: Jerry DeLisle <jvdelisle at verizon dot net>
- To: gfortran <fortran at gcc dot gnu dot org>
- Cc: gcc patches <gcc-patches at gcc dot gnu dot org>
- Date: Sat, 21 Nov 2009 17:47:06 -0800
- Subject: [patch, fortran] PR41807 [4.5/4.4 Regression] data statement with nested type constructors
Hi,
This patch fixes this bug by removing an error check in resolve.c that uses
gfc_is_constant_expr. This function performs an expansion of the constructors,
evidently too soon, causing the regression by modifying the expressions.
Obviously, these constructors do get properly expanded later. Perhaps it should
be renamed a bit to reflect this, maybe gfc_expand_is_constant_expr.
Regardless, after removing this function from next_data_value and running the
testsuite I observed that the only failure was in data_value_1.f90. The failure
is an assert in trans-const.c (gfc_convert_const). This seemed like the natural
place to verify that each array element is actually a constant.
Thus I replaced the assert with the check for BT_CONSTANT, rewording the error
message to be more general. The test case data_value_1.f90 is revised to reflect
the new error message. A new test case, originally from Steve Kargl is also
attached.
Regression tested on x86-64-gnu-linux.
OK for trunk?
Regards,
Jerry
2009-11-21 Jerry DeLisle <jvdelisle@gcc.gnu.org>
* trans-const.c (gfc_conv_const): Fix typo in comment. Replace assert
with error message if not constant.
* resolve.c (next_data_value): Delete check for constant.
Index: testsuite/gfortran.dg/data_value_1.f90
===================================================================
--- testsuite/gfortran.dg/data_value_1.f90 (revision 154170)
+++ testsuite/gfortran.dg/data_value_1.f90 (working copy)
@@ -3,12 +3,14 @@
! is not a constant and so the DATA statement did not have
! a constant value expression.
!
+! Modified dg-error for PR41807
+!
! Contributed by Philippe Marguinaud <philippe.marguinaud@meteo.fr>
!
TYPE POINT
REAL :: X
ENDTYPE
TYPE(POINT) :: P
- DATA P / POINT(1.+X) / ! { dg-error "non-constant DATA value" }
+ DATA P / POINT(1.+X) / ! { dg-error "non-constant initialization" }
print *, p
END
Index: fortran/trans-const.c
===================================================================
--- fortran/trans-const.c (revision 154411)
+++ fortran/trans-const.c (working copy)
@@ -340,7 +340,7 @@ void
gfc_conv_constant (gfc_se * se, gfc_expr * expr)
{
/* We may be receiving an expression for C_NULL_PTR or C_NULL_FUNPTR. If
- so, they expr_type will not yet be an EXPR_CONSTANT. We need to make
+ so, the expr_type will not yet be an EXPR_CONSTANT. We need to make
it so here. */
if (expr->ts.type == BT_DERIVED && expr->ts.u.derived
&& expr->ts.u.derived->attr.is_iso_c)
@@ -353,7 +353,11 @@ gfc_conv_constant (gfc_se * se, gfc_expr * expr)
}
}
- gcc_assert (expr->expr_type == EXPR_CONSTANT);
+ if (expr->expr_type != EXPR_CONSTANT)
+ {
+ gfc_error ("non-constant initialization expression at %L", &expr->where);
+ return;
+ }
if (se->ss != NULL)
{
Index: fortran/resolve.c
===================================================================
--- fortran/resolve.c (revision 154411)
+++ fortran/resolve.c (working copy)
@@ -11083,9 +11083,6 @@ next_data_value (void)
{
while (mpz_cmp_ui (values.left, 0) == 0)
{
- if (!gfc_is_constant_expr (values.vnode->expr))
- gfc_error ("non-constant DATA value at %L",
- &values.vnode->expr->where);
if (values.vnode->next == NULL)
return FAILURE;
! { dg-do run }
! PR41807 data statement with nested type constructors
! Test case provided by Steve Kargl
implicit none
type :: a
real :: x(3)
end type a
integer, parameter :: n = 3
type(a) :: b(n)
real, parameter :: d1(3) = (/1., 2., 3./)
real, parameter :: d2(3) = (/4., 5., 6./)
real, parameter :: d3(3) = (/7., 8., 9./)
integer :: i, z(n)
data (b(i), i = 1, n) /a(d1), a(d2), a(d3)/
data (z(i), i = 1, n) / 1, 2, 3/
if (any(z.ne.[1, 2, 3])) call abort
if (any(b(1)%x.ne.[1, 2, 3]) .or. &
any(b(2)%x.ne.[4, 5, 6]) .or. &
any(b(3)%x.ne.[7, 8, 9])) call abort
end