This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: Fix PR2938
- To: gcc-patches at gcc dot gnu dot org
- Subject: PATCH: Fix PR2938
- From: Mark Mitchell <mark at codesourcery dot com>
- Date: Sat, 09 Jun 2001 16:11:36 -0700
- Organization: CodeSourcery, LLC
PR2938 refers to the extremely long time it takes to optimize a
relatively simple C++ program. However, the optimization time was
really caused by a correctness issue in language-independent code that
we never observed before due to the fact that the C++ front-end didn't
generate ARRAY_REFs.
For an example of the kind of code we would get wrong, consider:
double& f ();
double m () {
const double a[1] = { f () };
return a[0];
}
This would result in two calls to `f', which is totally wrong.
Tested on i686-pc-linux-gnu, installed on the mainline and on the
branch.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
2001-06-09 Mark Mitchell <mark@codesourcery.com>
* expr.c (expand_expr, case ARRAY_REF): Do not replace
an array element with the known initializing value if it has
side-effects.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.295.2.13
diff -c -p -r1.295.2.13 expr.c
*** expr.c 2001/05/27 10:31:44 1.295.2.13
--- expr.c 2001/06/09 21:25:33
*************** expand_expr (exp, target, tmode, modifie
*** 6768,6774 ****
elem = TREE_CHAIN (elem))
;
! if (elem)
return expand_expr (fold (TREE_VALUE (elem)), target,
tmode, ro_modifier);
}
--- 6768,6774 ----
elem = TREE_CHAIN (elem))
;
! if (elem && !TREE_SIDE_EFFECTS (elem))
return expand_expr (fold (TREE_VALUE (elem)), target,
tmode, ro_modifier);
}