This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix PR middle-end/17703 and the C++ part of 17657


Even though it is usually bad to remove the cleanup expression, we
should at least do it for a small number of tree types like constants,
decls and push it through a NOP_EXPR as we can cause the gimplifier
to create unnecessary temporaries which can cause warnings to happen
at -O0 which should not happen at all.

This patch adds a function fold_build_cleanup_point_expr which
does the folding, also unlike the old method, we don't create
trees which would be gotten rid of anyways.

OK? Bootstrapped and tested on powerpc-darwin with no regressions.

Thanks,
Andrew Pinski

Testcases:
// { dg-do compile }
int foo(int first) {
  while (true) {
    return first;
  }
} // { dg-bogus "control reaches" }

------
// { dg-do compile }
// { dg-options "-O2" }

extern int foo (int);

void
bar (void)
{
  char tmp = foo (0);
  switch (tmp)
    {
    case 1: foo (1); break;
    case 2: foo (2); break;
    case 3: foo (3); break;
    case 4: foo (4); break;
    case 5: foo (5); break;
    case 6: foo (6); break;
    case 7: foo (7); break;
    case 255: foo (8); break;
    default: break;
    }
}


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	6 Oct 2004 13:15:14 -0000
@@ -10462,6 +10462,27 @@ fold_relational_const (enum tree_code co
   return constant_boolean_node (result, type);
 }

+/* Build an expression for the a clean point containing T with type TYPE.
+ Don't build a cleanup point expression for constants, or decls and also
+ for NOP_EXPR build the cleanup point inside the NOP_EXPR. */
+
+tree
+fold_build_cleanup_point_expr (tree type, tree expr)
+{
+ if (CONSTANT_CLASS_P (expr))
+ return expr;
+ if (DECL_P (expr))
+ return expr;
+ if (TREE_CODE (expr) == NOP_EXPR)
+ {
+ tree t;
+ t = TREE_OPERAND (expr, 0);
+ return build1 (NOP_EXPR, type,
+ fold_build_cleanup_point_expr (TREE_TYPE (t), t));
+ }
+ 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;
 }
 		


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]