c-fold.c (c_fully_fold_internal): Save the c_fully_fold_internal result for SAVE_EXPR...
authorJakub Jelinek <jakub@redhat.com>
Mon, 22 May 2017 18:55:29 +0000 (20:55 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 22 May 2017 18:55:29 +0000 (20:55 +0200)
* c-fold.c (c_fully_fold_internal): Save the c_fully_fold_internal
result for SAVE_EXPR operand and set SAVE_EXPR_FOLDED_P even if
it returned invariant.  Call tree_invariant_p unconditionally
afterwards to decide whether to return expr or op0.

From-SVN: r248347

gcc/c/ChangeLog
gcc/c/c-fold.c

index 0318bcf043b5fd0295dca3a5174d334abc2b644b..292762ac9c2635498214de8383668c104ccdc9e3 100644 (file)
@@ -1,3 +1,10 @@
+2017-05-22  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-fold.c (c_fully_fold_internal): Save the c_fully_fold_internal
+       result for SAVE_EXPR operand and set SAVE_EXPR_FOLDED_P even if
+       it returned invariant.  Call tree_invariant_p unconditionally
+       afterwards to decide whether to return expr or op0.
+
 2017-05-22  Nathan Sidwell  <nathan@acm.org>
 
        * c-decl.c (c_parse_final_cleanups): Drop TDI_tu handling.
index 1baee446d3e31eee800659117ced65ea3083eaee..2601224c84717ee6971a4c980b37b8c53800f989 100644 (file)
@@ -566,21 +566,17 @@ c_fully_fold_internal (tree expr, bool in_init, bool *maybe_const_operands,
 
     case SAVE_EXPR:
       /* Make sure to fold the contents of a SAVE_EXPR exactly once.  */
+      op0 = TREE_OPERAND (expr, 0);
       if (!SAVE_EXPR_FOLDED_P (expr))
        {
-         op0 = TREE_OPERAND (expr, 0);
          op0 = c_fully_fold_internal (op0, in_init, maybe_const_operands,
                                       maybe_const_itself, for_int_const);
-         /* Don't wrap the folded tree in a SAVE_EXPR if we don't
-            have to.  */
-         if (tree_invariant_p (op0))
-           ret = op0;
-         else
-           {
-             TREE_OPERAND (expr, 0) = op0;
-             SAVE_EXPR_FOLDED_P (expr) = true;
-           }
+         TREE_OPERAND (expr, 0) = op0;
+         SAVE_EXPR_FOLDED_P (expr) = true;
        }
+      /* Return the SAVE_EXPR operand if it is invariant.  */
+      if (tree_invariant_p (op0))
+       ret = op0;
       goto out;
 
     default: