OSDN Git Service

PR c/29154
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 2 Oct 2006 06:11:49 +0000 (06:11 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 2 Oct 2006 06:11:49 +0000 (06:11 +0000)
* gimplify.c (gimplify_self_mod_expr): Run inner expression's post
side effects after the outer expression's post side effects.

* gcc.c-torture/execute/20060929-1.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117366 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/gimplify.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20060929-1.c [new file with mode: 0644]

index 14e3af7..8c10757 100644 (file)
@@ -1,3 +1,9 @@
+2006-10-02  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/29154
+       * gimplify.c (gimplify_self_mod_expr): Run inner expression's post
+       side effects after the outer expression's post side effects.
+
 2006-10-01  Sandra Loosemore  <sandra@codesourcery.com>
 
        * tree.h (DECL_FIELD_OFFSET, DECL_FIELD_BIT_OFFSET):  Fix
index 9db673a..84c7219 100644 (file)
@@ -1896,7 +1896,7 @@ gimplify_self_mod_expr (tree *expr_p, tree *pre_p, tree *post_p,
                        bool want_value)
 {
   enum tree_code code;
-  tree lhs, lvalue, rhs, t1;
+  tree lhs, lvalue, rhs, t1, post = NULL, *orig_post_p = post_p;
   bool postfix;
   enum tree_code arith_code;
   enum gimplify_status ret;
@@ -1913,6 +1913,11 @@ gimplify_self_mod_expr (tree *expr_p, tree *pre_p, tree *post_p,
   else
     postfix = false;
 
+  /* For postfix, make sure the inner expression's post side effects
+     are executed after side effects from this expression.  */
+  if (postfix)
+    post_p = &post;
+
   /* Add or subtract?  */
   if (code == PREINCREMENT_EXPR || code == POSTINCREMENT_EXPR)
     arith_code = PLUS_EXPR;
@@ -1943,7 +1948,8 @@ gimplify_self_mod_expr (tree *expr_p, tree *pre_p, tree *post_p,
 
   if (postfix)
     {
-      gimplify_and_add (t1, post_p);
+      gimplify_and_add (t1, orig_post_p);
+      append_to_statement_list (post, orig_post_p);
       *expr_p = lhs;
       return GS_ALL_DONE;
     }
index 696d0ab..c3efeac 100644 (file)
@@ -1,3 +1,8 @@
+2006-10-02  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/29154
+       * gcc.c-torture/execute/20060929-1.c: New test.
+
 2006-10-01  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/29105
diff --git a/gcc/testsuite/gcc.c-torture/execute/20060929-1.c b/gcc/testsuite/gcc.c-torture/execute/20060929-1.c
new file mode 100644 (file)
index 0000000..76c447f
--- /dev/null
@@ -0,0 +1,44 @@
+/* PR c/29154 */
+
+extern void abort (void);
+
+void
+foo (int **p, int *q)
+{
+  *(*p++)++ = *q++;
+}
+
+void
+bar (int **p, int *q)
+{
+  **p = *q++;
+  *(*p++)++;
+}
+
+void
+baz (int **p, int *q)
+{
+  **p = *q++;
+  (*p++)++;
+}
+
+int
+main (void)
+{
+  int i = 42, j = 0;
+  int *p = &i;
+  foo (&p, &j);
+  if (p - 1 != &i || j != 0 || i != 0)
+    abort ();
+  i = 43;
+  p = &i;
+  bar (&p, &j);
+  if (p - 1 != &i || j != 0 || i != 0)
+    abort ();
+  i = 44;
+  p = &i;
+  baz (&p, &j);
+  if (p - 1 != &i || j != 0 || i != 0)
+    abort ();
+  return 0;
+}