diff options
author | Michael Meissner <meissner@redhat.com> | 2000-07-15 14:58:53 +0000 |
---|---|---|
committer | Michael Meissner <meissner@gcc.gnu.org> | 2000-07-15 14:58:53 +0000 |
commit | 4d06bcc527aca789f9282167528aa02f77cdd6ca (patch) | |
tree | cc186924767d7116187ea8c5addebe72555b7ae8 /gcc/fold-const.c | |
parent | bbed132f325e85bb0ee7cdfeac9c4504278e99d6 (diff) | |
download | gcc-4d06bcc527aca789f9282167528aa02f77cdd6ca.zip gcc-4d06bcc527aca789f9282167528aa02f77cdd6ca.tar.gz gcc-4d06bcc527aca789f9282167528aa02f77cdd6ca.tar.bz2 |
Fix (<cond> ? FOO++ : BAR++) == 2 from misoptimizing FOO++ into ++FOO without bumping up the comparison value
From-SVN: r35046
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 26ac5d2..f259115 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6136,7 +6136,15 @@ fold (expr) tree newconst = fold (build (PLUS_EXPR, TREE_TYPE (varop), constop, TREE_OPERAND (varop, 1))); - TREE_SET_CODE (varop, PREINCREMENT_EXPR); + + /* Do not overwrite the current varop to be a preincrement, + create a new node so that we won't confuse our caller who + might create trees and throw them away, reusing the + arguments that they passed to build. This shows up in + the THEN or ELSE parts of ?: being postincrements. */ + varop = build (PREINCREMENT_EXPR, TREE_TYPE (varop), + TREE_OPERAND (varop, 0), + TREE_OPERAND (varop, 1)); /* If VAROP is a reference to a bitfield, we must mask the constant by the width of the field. */ @@ -6180,9 +6188,9 @@ fold (expr) } - t = build (code, type, TREE_OPERAND (t, 0), - TREE_OPERAND (t, 1)); - TREE_OPERAND (t, constopnum) = newconst; + t = build (code, type, + (constopnum == 0) ? newconst : varop, + (constopnum == 1) ? newconst : varop); return t; } } @@ -6195,7 +6203,15 @@ fold (expr) tree newconst = fold (build (MINUS_EXPR, TREE_TYPE (varop), constop, TREE_OPERAND (varop, 1))); - TREE_SET_CODE (varop, PREDECREMENT_EXPR); + + /* Do not overwrite the current varop to be a predecrement, + create a new node so that we won't confuse our caller who + might create trees and throw them away, reusing the + arguments that they passed to build. This shows up in + the THEN or ELSE parts of ?: being postdecrements. */ + varop = build (PREDECREMENT_EXPR, TREE_TYPE (varop), + TREE_OPERAND (varop, 0), + TREE_OPERAND (varop, 1)); if (TREE_CODE (TREE_OPERAND (varop, 0)) == COMPONENT_REF && DECL_BIT_FIELD(TREE_OPERAND @@ -6234,9 +6250,9 @@ fold (expr) } - t = build (code, type, TREE_OPERAND (t, 0), - TREE_OPERAND (t, 1)); - TREE_OPERAND (t, constopnum) = newconst; + t = build (code, type, + (constopnum == 0) ? newconst : varop, + (constopnum == 1) ? newconst : varop); return t; } } |