re PR c/29154 (*(* ppointer++)++ = *pointer++ generates bad code)

PR c/29154
	* 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.

From-SVN: r117366
This commit is contained in:
Jakub Jelinek 2006-10-02 08:11:49 +02:00 committed by Jakub Jelinek
parent 51a203d95e
commit 82181741c1
4 changed files with 63 additions and 2 deletions

View 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

View 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;
}

View 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

View File

@ -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;
}