This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, fortran] reduce character array parameters (PR fortran/22491)
- From: David Edelsohn <dje at watson dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org, fortran at gcc dot gnu dot org
- Date: Wed, 20 Jul 2005 22:33:06 -0400
- Subject: [PATCH, fortran] reduce character array parameters (PR fortran/22491)
While fixing PR 21730, Feng Wang pointed out that constant
character array parameters produced an error message that they could not
be reduced. For example,
character*2 a (1)
character*4 b (1)
character*6 c
parameter (a="12")
parameter (b = a)
write (c,'("#",A,"#")') b
if (c .ne. '#12 #') call abort
end
The value of the EXPR_VARIABLE is a constant and it is simplified to a
constant in expr.c:simplify_parameter_variable(). The subobject refs from
the original expression also are copied, which gives the impression that
subobjects were not elimintated during simplification, although they are
irrelevant in a constant expression.
This patch modifies the function simplify_parameter_variable so
that subobject refs are not copied if the value is a constant expression,
allowing the example to succeed.
Okay for mainline?
Thanks, David
PR fortran/22491
* expr.c (simplify_parameter_variable): Do not copy the subobject
references if the expression value is a constant.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/expr.c,v
retrieving revision 1.27
diff -c -p -r1.27 expr.c
*** expr.c 7 Jul 2005 07:54:41 -0000 1.27
--- expr.c 21 Jul 2005 01:47:32 -0000
*************** simplify_parameter_variable (gfc_expr *
*** 1068,1074 ****
try t;
e = gfc_copy_expr (p->symtree->n.sym->value);
! if (p->ref)
e->ref = copy_ref (p->ref);
t = gfc_simplify_expr (e, type);
--- 1068,1074 ----
try t;
e = gfc_copy_expr (p->symtree->n.sym->value);
! if (e->expr_type != EXPR_CONSTANT && p->ref != NULL)
e->ref = copy_ref (p->ref);
t = gfc_simplify_expr (e, type);