diff options
author | Richard Kenner <kenner@gcc.gnu.org> | 1996-05-16 18:53:14 -0400 |
---|---|---|
committer | Richard Kenner <kenner@gcc.gnu.org> | 1996-05-16 18:53:14 -0400 |
commit | 30eca391336b5bcf4706b8046c4c62f701e289fd (patch) | |
tree | 93581c6cecc2ee347c484cb6a7ca781b6bb00f27 /gcc/fold-const.c | |
parent | c30ac676411db2b1354229a08308a29724378e76 (diff) | |
download | gcc-30eca391336b5bcf4706b8046c4c62f701e289fd.zip gcc-30eca391336b5bcf4706b8046c4c62f701e289fd.tar.gz gcc-30eca391336b5bcf4706b8046c4c62f701e289fd.tar.bz2 |
(fold, case EQ_EXPR): When folding VAR++ = CONST, mask the new const
if VAR is a bitfield reference; also for VAR--.
From-SVN: r11976
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 84438d7..82e51c0 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -4428,6 +4428,24 @@ fold (expr) constop, TREE_OPERAND (varop, 1))); TREE_SET_CODE (varop, PREINCREMENT_EXPR); + /* If VAROP is a reference to a bitfield, we must mask + the constant by the width of the field. */ + if (TREE_CODE (TREE_OPERAND (varop, 0)) == COMPONENT_REF + && DECL_BIT_FIELD(TREE_OPERAND + (TREE_OPERAND (varop, 0), 1))) + { + int size + = TREE_INT_CST_LOW (DECL_SIZE + (TREE_OPERAND + (TREE_OPERAND (varop, 0), 1))); + + newconst = fold (build (BIT_AND_EXPR, + TREE_TYPE (varop), newconst, + convert (TREE_TYPE (varop), + build_int_2 (size, 0)))); + } + + t = build (code, type, TREE_OPERAND (t, 0), TREE_OPERAND (t, 1)); TREE_OPERAND (t, constopnum) = newconst; @@ -4444,6 +4462,23 @@ fold (expr) = fold (build (MINUS_EXPR, TREE_TYPE (varop), constop, TREE_OPERAND (varop, 1))); TREE_SET_CODE (varop, PREDECREMENT_EXPR); + + if (TREE_CODE (TREE_OPERAND (varop, 0)) == COMPONENT_REF + && DECL_BIT_FIELD(TREE_OPERAND + (TREE_OPERAND (varop, 0), 1))) + { + int size + = TREE_INT_CST_LOW (DECL_SIZE + (TREE_OPERAND + (TREE_OPERAND (varop, 0), 1))); + + newconst = fold (build (BIT_AND_EXPR, + TREE_TYPE (varop), newconst, + convert (TREE_TYPE (varop), + build_int_2 (size, 0)))); + } + + t = build (code, type, TREE_OPERAND (t, 0), TREE_OPERAND (t, 1)); TREE_OPERAND (t, constopnum) = newconst; |