+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
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;
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;
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;
}
--- /dev/null
+/* 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;
+}