This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix PR middle-end/17703 and the C++ part of 17657
On Oct 6, 2004, at 2:32 PM, Jason Merrill wrote:
It would be simpler just to check TREE_SIDE_EFFECTS, though you might
as
well keep the DECL_P check so that we don't build a useless
CLEANUP_POINT_EXPR for a use of a volatile variable.
Adding back the DECL_P check will be for another patch, this patch was
mainly to fix some regressions.
I did simplify it by adding TREE_SIDE_EFFECTS and added a check for
CLEANUP_POINT_EXPR to just have one next to each other.
OK?
Thanks,
Andrew Pinski
ChangeLog:
* fold-const.c (fold_build_cleanup_point_expr): New.
* tree.h (fold_build_cleanup_point_expr): Declare.
cp/ChangeLog:
* semantics.c (maybe_cleanup_point_expr): Use
fold_build_cleanup_point_expr.
* typeck.c (condition_conversion): Likewise.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.466
diff -u -p -r1.466 fold-const.c
--- fold-const.c 3 Oct 2004 15:31:50 -0000 1.466
+++ fold-const.c 7 Oct 2004 14:52:21 -0000
@@ -10462,6 +10462,26 @@ fold_relational_const (enum tree_code co
return constant_boolean_node (result, type);
}
+/* Build an expression for the a clean point containing EXPR with type
TYPE.
+ Don't build a cleanup point expression for EXPR which don't have
side
+ effects. */
+
+tree
+fold_build_cleanup_point_expr (tree type, tree expr)
+{
+ /* If the expression does not have side effects then the expression
does not
+ need to be wrapped with a cleanup point expression. */
+ if (!TREE_SIDE_EFFECTS (expr))
+ return expr;
+
+ /* If we already have a cleanup pont expression build a new one with
+ the inner expression. */
+ if (TREE_CODE (expr) == CLEANUP_POINT_EXPR)
+ return build1 (CLEANUP_POINT_EXPR, type, TREE_OPERAND (expr, 0));
+
+ return build1 (CLEANUP_POINT_EXPR, type, expr);
+}
+
/* Build an expression for the address of T. Folds away INDIRECT_REF
to
avoid confusing the gimplify process. */
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.635
diff -u -p -r1.635 tree.h
--- tree.h 1 Oct 2004 07:42:49 -0000 1.635
+++ tree.h 6 Oct 2004 13:15:14 -0000
@@ -3539,6 +3539,7 @@ extern tree nondestructive_fold_binary_t
extern tree fold_read_from_constant_string (tree);
extern tree int_const_binop (enum tree_code, tree, tree, int);
extern tree build_fold_addr_expr (tree);
+tree fold_build_cleanup_point_expr (tree type, tree expr);
extern tree build_fold_addr_expr_with_type (tree, tree);
extern tree build_fold_indirect_ref (tree);
extern tree constant_boolean_node (int, tree);
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.441
diff -u -p -r1.441 semantics.c
--- cp/semantics.c 1 Oct 2004 15:11:21 -0000 1.441
+++ cp/semantics.c 6 Oct 2004 13:15:14 -0000
@@ -358,7 +358,7 @@ static tree
maybe_cleanup_point_expr (tree expr)
{
if (!processing_template_decl && stmts_are_full_exprs_p ())
- expr = build1 (CLEANUP_POINT_EXPR, TREE_TYPE (expr), expr);
+ expr = fold_build_cleanup_point_expr (type, expr);
return expr;
}
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/typeck.c,v
retrieving revision 1.580
diff -u -p -r1.580 typeck.c
--- cp/typeck.c 3 Oct 2004 18:07:56 -0000 1.580
+++ cp/typeck.c 6 Oct 2004 13:15:14 -0000
@@ -3677,7 +3677,7 @@ condition_conversion (tree expr)
if (processing_template_decl)
return expr;
t = perform_implicit_conversion (boolean_type_node, expr);
- t = build1 (CLEANUP_POINT_EXPR, boolean_type_node, t);
+ t = fold_build_cleanup_point_expr (boolean_type_node, t);
return t;
}