]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/7209 (Faulty array dereferencing)
authorNathan Sidwell <nathan@codesourcery.com>
Tue, 22 Oct 2002 09:06:19 +0000 (09:06 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Tue, 22 Oct 2002 09:06:19 +0000 (09:06 +0000)
PR c++/7209
* fold_const.c (fold_binary_op_with_conditional_arg): Always
build compound_expr if we used save_expr.
testsuite:
* g++.dg/expr: New directory.
* g++.dg/expr/cond1.C: New test.

From-SVN: r58406

gcc/fold-const.c
gcc/testsuite/ChangeLog

index f44c482379a06bd20a904fb738f0c5975b056c09..926581c2ab470eb82b706704e66c55981e5bfbb9 100644 (file)
@@ -4869,6 +4869,7 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p)
   /* And these are the types of the expressions.  */
   tree lhs_type = type;
   tree rhs_type = type;
+  int save = 0;
 
   if (cond_first_p)
     {
@@ -4927,11 +4928,12 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p)
      if an arm is a COND_EXPR since we get exponential behavior
      in that case.  */
   
-  if (TREE_CODE (arg) != SAVE_EXPR && ! TREE_CONSTANT (arg)
-      && global_bindings_p () == 0
-      && ((TREE_CODE (arg) != VAR_DECL
-          && TREE_CODE (arg) != PARM_DECL)
-         || TREE_SIDE_EFFECTS (arg)))
+  if (TREE_CODE (arg) == SAVE_EXPR)
+    save = 1;
+  else if (! TREE_CONSTANT (arg)
+          && global_bindings_p () == 0
+          && ((TREE_CODE (arg) != VAR_DECL && TREE_CODE (arg) != PARM_DECL)
+              || TREE_SIDE_EFFECTS (arg)))
     {
       if (TREE_CODE (true_value) != COND_EXPR)
        lhs = fold (build (lhs_code, lhs_type, *true_lhs, *true_rhs));
@@ -4941,7 +4943,11 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p)
       
       if ((lhs == 0 || ! TREE_CONSTANT (lhs))
          && (rhs == 0 || !TREE_CONSTANT (rhs)))
-       arg = save_expr (arg), lhs = rhs = 0;
+       {
+         arg = save_expr (arg);
+         lhs = rhs = 0;
+         save = 1;
+       }
     }
   
   if (lhs == 0)
@@ -4951,7 +4957,7 @@ fold_binary_op_with_conditional_arg (code, type, cond, arg, cond_first_p)
   
   test = fold (build (COND_EXPR, type, test, lhs, rhs));
   
-  if (TREE_CODE (arg) == SAVE_EXPR)
+  if (save)
     return build (COMPOUND_EXPR, type,
                  convert (void_type_node, arg),
                  strip_compound_expr (test, arg));
index ac6fb869f508465648e8856ebb300020d7c548cd..eacd9c3c2c0b411e016b83793d52b6d4a71fcb77 100644 (file)
@@ -1,3 +1,9 @@
+2002-10-22  Nathan Sidwell  <nathan@codesourcery.com>
+
+       PR c++/7209
+       * g++.dg/expr: New directory.
+       * g++.dg/expr/cond1.C: New test.
+
 2002-10-21  Zack Weinberg  <zack@codesourcery.com>
 
        * gcc.dg/noncompile/920923-1.c: Prevent spurious regressions with