OSDN Git Service

PR middle-end/19858
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Feb 2005 21:08:44 +0000 (21:08 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 11 Feb 2005 21:08:44 +0000 (21:08 +0000)
* fold-const.c (make_bit_field_ref): If bitpos == 0 and bitsize
is number of inner's bits, avoid creating a BIT_FIELD_REF.

* gcc.c-torture/compile/20050210-1.c: New test.

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

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20050210-1.c [new file with mode: 0644]

index b88ef12..a853517 100644 (file)
@@ -1,5 +1,9 @@
 2005-02-11  Jakub Jelinek  <jakub@redhat.com>
 
+       PR middle-end/19858
+       * fold-const.c (make_bit_field_ref): If bitpos == 0 and bitsize
+       is number of inner's bits, avoid creating a BIT_FIELD_REF.
+
        * config/rs6000/sysv4.h (ENDFILE_LINUX_SPEC): Use crtendS.o instead of
        crtend.o if -pie.  Use %{x:a;:b} spec syntax.
 
index de54258..0d73273 100644 (file)
@@ -3076,8 +3076,20 @@ static tree
 make_bit_field_ref (tree inner, tree type, int bitsize, int bitpos,
                    int unsignedp)
 {
-  tree result = build3 (BIT_FIELD_REF, type, inner,
-                       size_int (bitsize), bitsize_int (bitpos));
+  tree result;
+
+  if (bitpos == 0)
+    {
+      tree size = TYPE_SIZE (TREE_TYPE (inner));
+      if ((INTEGRAL_TYPE_P (TREE_TYPE (inner))
+          || POINTER_TYPE_P (TREE_TYPE (inner)))
+         && host_integerp (size, 0) 
+         && tree_low_cst (size, 0) == bitsize)
+       return fold_convert (type, inner);
+    }
+
+  result = build3 (BIT_FIELD_REF, type, inner,
+                  size_int (bitsize), bitsize_int (bitpos));
 
   BIT_FIELD_REF_UNSIGNED (result) = unsignedp;
 
index 1064f44..97a1b12 100644 (file)
@@ -1,3 +1,8 @@
+2005-02-11  Jakub Jelinek  <jakub@redhat.com>
+
+       PR middle-end/19858
+       * gcc.c-torture/compile/20050210-1.c: New test.
+
 2005-02-11  Mark Mitchell  <mark@codesourcery.com>
 
        PR c++/19755
diff --git a/gcc/testsuite/gcc.c-torture/compile/20050210-1.c b/gcc/testsuite/gcc.c-torture/compile/20050210-1.c
new file mode 100644 (file)
index 0000000..c9e3326
--- /dev/null
@@ -0,0 +1,8 @@
+/* PR middle-end/19858 */
+
+typedef __SIZE_TYPE__ size_t;
+union U { int c; } foo;
+int bar (void)
+{
+  return !(((size_t) &foo & 3) == 0 && !((size_t) &foo & 1));
+}