OSDN Git Service

(fold, case EQ_EXPR): When folding VAR++ = CONST, mask the new const
authorkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 May 1996 22:53:14 +0000 (22:53 +0000)
committerkenner <kenner@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 16 May 1996 22:53:14 +0000 (22:53 +0000)
if VAR is a bitfield reference; also for VAR--.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@11976 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/fold-const.c

index 84438d7..82e51c0 100644 (file)
@@ -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;