This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix tree-opt/29788, plain CONST_DECL leaking through
On Tue, 2006-11-14 at 10:36 -0800, Andrew Pinski wrote:
> On Tue, 2006-11-14 at 10:14 -0800, Ian Lance Taylor wrote:
> > Andrew Pinski <pinskia@gmail.com> writes:
> >
> > > * tree-inline.c (copy_body_r): Call fold after folding indirect
> > > reference.
> > >
> > > * gfortran.fortran-torture/compile/inline_1.f90: New test.
> >
> > > + *tp = fold (*tp);
> >
> > I don't understand why this call to fold is needed if
> > fold_indirect_ref_1 returned a non-NULL value. In that case, it seems
> > to me that we will have already folded the value.
>
> The reason issue is fold_indirect_ref_1 does not fold a CONST_DECL after
> folding *&CONST_DECL. I have a better fix which was recommended by
> Roger.
Here is the patch which fixes the problem but moves the folding of
*&CONST_DECL -> DECL_INITIAL (CONST_DECL) to fold_indirect_ref.
OK ? Bootstrapped and tested on i686-linux-gnu with no regressions.
Thanks,
Andrew Pinski
ChangeLog:
* fold-const.c (fold_indirect_ref_1): Fold *&CONST_DECL down
to what is the const decl is a place holder for.
* gfortran.fortran-torture/compile/inline_1.f90: New testcase.
Index: fold-const.c
===================================================================
--- fold-const.c (revision 118718)
+++ fold-const.c (working copy)
@@ -12977,6 +12977,9 @@ fold_indirect_ref_1 (tree type, tree op0
{
tree op = TREE_OPERAND (sub, 0);
tree optype = TREE_TYPE (op);
+ /* *&CONST_DECL -> to the value of the const decl. */
+ if (TREE_CODE (op) == CONST_DECL)
+ return DECL_INITIAL (op);
/* *&p => p; make sure to handle *&"str"[cst] here. */
if (type == optype)
{
Index: testsuite/gfortran.fortran-torture/compile/inline_1.f90
===================================================================
--- testsuite/gfortran.fortran-torture/compile/inline_1.f90 (revision 0)
+++ testsuite/gfortran.fortran-torture/compile/inline_1.f90 (revision 0)
@@ -0,0 +1,17 @@
+program gfcbug43
+ call try_fit (1)
+ call try_fit (1)
+contains
+ subroutine try_fit (k)
+ call fit (1, debug=.true.)
+ end subroutine try_fit
+ subroutine fit (k, debug)
+ logical, intent(in), optional :: debug
+ do j = 1, 2
+ maxerr1 = funk (r ,x1 , x1)
+ end do
+ if (debug) then
+ print "help"
+ end if
+ end subroutine fit
+end program gfcbug43