diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3f158552670..f21d9d2ff35 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2005-01-26 Stuart Hastings + + * gcc/gimplify.c (shortcut_cond_expr): Re-compute side-effects. + * gcc/testsuite/gcc.c-torture/execute/20050125-1.c: New. + 2005-01-26 Richard Henderson PR middle-end/18008 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index ac9ae14a74a..0fd39436325 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1923,6 +1923,7 @@ shortcut_cond_expr (tree expr) { TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1); then_ = shortcut_cond_expr (expr); + then_se = then_ && TREE_SIDE_EFFECTS (then_); pred = TREE_OPERAND (pred, 0); expr = build (COND_EXPR, void_type_node, pred, then_, NULL_TREE); } @@ -1937,6 +1938,7 @@ shortcut_cond_expr (tree expr) { TREE_OPERAND (expr, 0) = TREE_OPERAND (pred, 1); else_ = shortcut_cond_expr (expr); + else_se = else_ && TREE_SIDE_EFFECTS (else_); pred = TREE_OPERAND (pred, 0); expr = build (COND_EXPR, void_type_node, pred, NULL_TREE, else_); } diff --git a/gcc/testsuite/gcc.c-torture/execute/20050125-1.c b/gcc/testsuite/gcc.c-torture/execute/20050125-1.c new file mode 100644 index 00000000000..3dc15b53733 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/20050125-1.c @@ -0,0 +1,35 @@ +/* Verify that the CALL sideeffect isn't optimized away. */ +/* Contributed by Greg Parker 25 Jan 2005 */ + +#include +#include + +struct parse { + char *next; + char *end; + int error; +}; + +int seterr(struct parse *p, int err) +{ + p->error = err; + return 0; +} + +void bracket_empty(struct parse *p) +{ + if (((p->next < p->end) && (*p->next++) == ']') || seterr(p, 7)) { } +} + +int main(int argc __attribute__((unused)), char **argv __attribute__((unused))) +{ + struct parse p; + p.next = p.end = (char *)0x12345; + + p.error = 0; + bracket_empty(&p); + if (p.error != 7) + abort (); + + return 0; +}