]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/14755 (miscompilation in bitfielded signed integers)
authorJakub Jelinek <jakub@redhat.com>
Thu, 1 Apr 2004 16:27:06 +0000 (18:27 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 1 Apr 2004 16:27:06 +0000 (18:27 +0200)
PR c++/14755
* fold-const.c (fold) <EQ_EXPR>: Properly compute newconst in
"bitfld++ == const" to "++bitfld == const + incr" transformations.

* gcc.c-torture/execute/20040331-1.c: New test.

From-SVN: r80301

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog

index 6d7b7bbebaf5835f0822a16952d03d8ed0c9274e..08cb57f20adf73636dc125b9c684ebf66d1b4a7d 100644 (file)
@@ -1,3 +1,9 @@
+2004-04-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/14755
+       * fold-const.c (fold) <EQ_EXPR>: Properly compute newconst in
+       "bitfld++ == const" to "++bitfld == const + incr" transformations.
+
 2004-04-01  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/14069
index 19384e436654dbbc408e3a011b017d099cdf8197..9be3ddfa6abfc8befd16410dccb0e3d03a2aa9a0 100644 (file)
@@ -6049,12 +6049,11 @@ fold (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)))
+             && DECL_BIT_FIELD (TREE_OPERAND (TREE_OPERAND (varop, 0), 1)))
            {
              tree fielddecl = TREE_OPERAND (TREE_OPERAND (varop, 0), 1);
              int size = TREE_INT_CST_LOW (DECL_SIZE (fielddecl));
-             tree folded_compare;
-             tree mask = 0;
+             tree folded_compare, shift;
 
              /* First check whether the comparison would come out
                 always the same.  If we don't do that we would
@@ -6066,25 +6065,12 @@ fold (expr)
                  || integer_onep (folded_compare))
                return omit_one_operand (type, folded_compare, varop);
 
-             if (size < HOST_BITS_PER_WIDE_INT)
-               {
-                 unsigned HOST_WIDE_INT lo = ((unsigned HOST_WIDE_INT) 1
-                                              << size) - 1;
-                 mask = build_int_2 (lo, 0);
-               }
-             else if (size < 2 * HOST_BITS_PER_WIDE_INT)
-               {
-                 HOST_WIDE_INT hi = ((HOST_WIDE_INT) 1
-                                     << (size - HOST_BITS_PER_WIDE_INT)) - 1;
-                 mask = build_int_2 (~0, hi);
-               }
-                  
-             if (mask)
-               {
-                 mask = convert (TREE_TYPE (varop), mask);
-                 newconst = fold (build (BIT_AND_EXPR, TREE_TYPE (varop),
-                                         newconst, mask));
-               }
+             shift = build_int_2 (TYPE_PRECISION (TREE_TYPE (varop)) - size,
+                                  0);
+             newconst = fold (build (LSHIFT_EXPR, TREE_TYPE (varop),
+                                     newconst, shift));
+             newconst = fold (build (RSHIFT_EXPR, TREE_TYPE (varop),
+                                     newconst, shift));
            }
 
          return fold (build (code, type, varop, newconst));
index f3d3cd84eb42b1690bc08a08a0ec0aa3949f2f51..794c523b2fe44f1cf0958dab9a521984435a354c 100644 (file)
@@ -1,4 +1,9 @@
-2004-03-27  Jakub Jelinek  <jakub@redhat.com>
+2004-04-01  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/14755
+       * gcc.c-torture/execute/20040331-1.c: New test.
+
+2004-04-01  Jakub Jelinek  <jakub@redhat.com>
 
        PR c/14069
        * gcc.dg/20040322-1.c: New test.