I am reviving this patch from 2013 which properly handles
DECL_BIT_FIELD_REPRESENTATIVE appearing as FIELD_DECL operand in
a COMPONENT_REF (as I am currently reviving a patch to lower
bitfield accesses now that BIT_INSERT_EXPR is on trunk).

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2016-06-28  Richard Biener  <rguent...@suse.de>

        * tree-ssa-alias.c (nonoverlapping_component_refs_of_decl_p):
        Properly handle DECL_BIT_FIELD_REPRESENTATIVE occuring as
        COMPONENT_REF operand.
        (nonoverlapping_component_refs_p): Likewise.
        * stor-layout.c (start_bitfield_representative): Mark
        DECL_BIT_FIELD_REPRESENTATIVE as DECL_NONADDRESSABLE_P.

Index: gcc/tree-ssa-alias.c
===================================================================
*** gcc/tree-ssa-alias.c.orig   2016-06-28 10:32:02.563911183 +0200
--- gcc/tree-ssa-alias.c        2016-06-28 10:35:45.350388588 +0200
*************** nonoverlapping_component_refs_of_decl_p
*** 929,941 ****
        if (type1 != type2 || TREE_CODE (type1) != RECORD_TYPE)
         goto may_overlap;
  
-       /* Different fields of the same record type cannot overlap.
-        ??? Bitfields can overlap at RTL level so punt on them.  */
        if (field1 != field2)
        {
          component_refs1.release ();
          component_refs2.release ();
!         return !(DECL_BIT_FIELD (field1) && DECL_BIT_FIELD (field2));
        }
      }
  
--- 929,948 ----
        if (type1 != type2 || TREE_CODE (type1) != RECORD_TYPE)
         goto may_overlap;
  
        if (field1 != field2)
        {
          component_refs1.release ();
          component_refs2.release ();
!         /* A field and its representative need to be considered the
!            same.  */
!         if (DECL_BIT_FIELD_REPRESENTATIVE (field1) == field2
!             || DECL_BIT_FIELD_REPRESENTATIVE (field2) == field1)
!           return false;
!         /* Different fields of the same record type cannot overlap.
!            ??? Bitfields can overlap at RTL level so punt on them.  */
!         if (DECL_BIT_FIELD (field1) && DECL_BIT_FIELD (field2))
!           return false;
!         return true;
        }
      }
  
*************** nonoverlapping_component_refs_p (const_t
*** 1031,1039 ****
        if (typex == typey)
        {
          /* We're left with accessing different fields of a structure,
!            no possible overlap, unless they are both bitfields.  */
          if (fieldx != fieldy)
!           return !(DECL_BIT_FIELD (fieldx) && DECL_BIT_FIELD (fieldy));
        }
        if (TYPE_UID (typex) < TYPE_UID (typey))
        {
--- 1038,1057 ----
        if (typex == typey)
        {
          /* We're left with accessing different fields of a structure,
!            no possible overlap.  */
          if (fieldx != fieldy)
!           {
!             /* A field and its representative need to be considered the
!                same.  */
!             if (DECL_BIT_FIELD_REPRESENTATIVE (fieldx) == fieldy
!                 || DECL_BIT_FIELD_REPRESENTATIVE (fieldy) == fieldx)
!               return false;
!             /* Different fields of the same record type cannot overlap.
!                ??? Bitfields can overlap at RTL level so punt on them.  */
!             if (DECL_BIT_FIELD (fieldx) && DECL_BIT_FIELD (fieldy))
!               return false;
!             return true;
!           }
        }
        if (TYPE_UID (typex) < TYPE_UID (typey))
        {
Index: gcc/stor-layout.c
===================================================================
*** gcc/stor-layout.c.orig      2016-06-28 10:32:02.563911183 +0200
--- gcc/stor-layout.c   2016-06-28 10:32:05.747946562 +0200
*************** start_bitfield_representative (tree fiel
*** 1808,1813 ****
--- 1808,1818 ----
    DECL_SIZE_UNIT (repr) = DECL_SIZE_UNIT (field);
    DECL_PACKED (repr) = DECL_PACKED (field);
    DECL_CONTEXT (repr) = DECL_CONTEXT (field);
+   /* There are no indirect accesses to this field.  If we introduce
+      some then they have to use the record alias set.  This makes
+      sure to properly conflict with [indirect] accesses to addressable
+      fields of the bitfield group.  */
+   DECL_NONADDRESSABLE_P (repr) = 1;
    return repr;
  }
  

Reply via email to