c-attribs.c (handle_packed_attribute): Test DECL_C_BIT_FIELD rather than DECL_INITIAL.
authorJakub Jelinek <jakub@redhat.com>
Fri, 29 Sep 2017 17:45:32 +0000 (19:45 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 29 Sep 2017 17:45:32 +0000 (19:45 +0200)
c-family/
* c-attribs.c (handle_packed_attribute): Test DECL_C_BIT_FIELD
rather than DECL_INITIAL.
(common_handle_aligned_attribute): Likewise.
c/
* c-decl.c (grokfield): Use SET_DECL_C_BIT_FIELD here if
width is non-NULL.
(finish_struct): Test DECL_C_BIT_FIELD instead of DECL_INITIAL,
don't SET_DECL_C_BIT_FIELD here.
cp/
* class.c (check_bitfield_decl): Retrieve and clear width from
DECL_BIT_FIELD_REPRESENTATIVE rather than DECL_INITIAL.
(check_field_decls): Test DECL_BIT_FIELD_REPRESENTATIVE rather than
DECL_INITIAL.
(remove_zero_width_bit_fields): Adjust comment.
* decl2.c (grokbitfield): Stash width into
DECL_BIT_FIELD_REPRESENTATIVE rather than DECL_INITIAL.
* pt.c (tsubst_decl): For DECL_C_BIT_FIELD, tsubst_expr
DECL_BIT_FIELD_REPRESENTATIVE rather than DECL_INITIAL for width.
objc/
* objc-act.c (check_ivars, gen_declaration): For OBJCPLUS look at
DECL_BIT_FIELD_REPRESENTATIVE rather than DECL_INITIAL.

From-SVN: r253301

gcc/c-family/ChangeLog
gcc/c-family/c-attribs.c
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/cp/ChangeLog
gcc/cp/class.c
gcc/cp/decl2.c
gcc/cp/pt.c
gcc/objc/ChangeLog
gcc/objc/objc-act.c

index 32f87276a0bbc295858edcfa58c1a058faa6af24..6a9137ffa4f2ad76b5911bae44cb762525cda8ea 100644 (file)
@@ -1,3 +1,9 @@
+2017-09-29  Jakub Jelinek  <jakub@redhat.com>
+
+       * c-attribs.c (handle_packed_attribute): Test DECL_C_BIT_FIELD
+       rather than DECL_INITIAL.
+       (common_handle_aligned_attribute): Likewise.
+
 2017-09-20  Alexandre Oliva <aoliva@redhat.com>
 
        * c.opt (gen-decls): Add RejectNegative.
index 0337537ecbde7cf17399b90b8a20821aab660854..1821d3e52bccde54e5d950aea13add447d61ab25 100644 (file)
@@ -426,7 +426,7 @@ handle_packed_attribute (tree *node, tree name, tree ARG_UNUSED (args),
     {
       if (TYPE_ALIGN (TREE_TYPE (*node)) <= BITS_PER_UNIT
          /* Still pack bitfields.  */
-         && ! DECL_INITIAL (*node))
+         && ! DECL_C_BIT_FIELD (*node))
        warning (OPT_Wattributes,
                 "%qE attribute ignored for field of type %qT",
                 name, TREE_TYPE (*node));
@@ -1773,7 +1773,7 @@ common_handle_aligned_attribute (tree *node, tree args, int flags,
     {
       if (warn_if_not_aligned_p)
        {
-         if (TREE_CODE (decl) == FIELD_DECL && !DECL_INITIAL (decl))
+         if (TREE_CODE (decl) == FIELD_DECL && !DECL_C_BIT_FIELD (decl))
            {
              SET_DECL_WARN_IF_NOT_ALIGN (decl, (1U << i) * BITS_PER_UNIT);
              warn_if_not_aligned_p = false;
index 496b767cb51471bd022a97a0bdb7120acad9f4c2..87d6c0aaca6df7044edb93b404544327471fc019 100644 (file)
@@ -1,5 +1,10 @@
 2017-09-29  Jakub Jelinek  <jakub@redhat.com>
 
+       * c-decl.c (grokfield): Use SET_DECL_C_BIT_FIELD here if
+       width is non-NULL.
+       (finish_struct): Test DECL_C_BIT_FIELD instead of DECL_INITIAL,
+       don't SET_DECL_C_BIT_FIELD here.
+
        PR c/82340
        * c-decl.c (build_compound_literal): Use c_apply_type_quals_to_decl
        instead of trying to set just TREE_READONLY manually.
index 080a2e9c0bd7a8918a9421a3f194326e65738814..a6b7c2041915fa90029e52bd4a618279a1e8240d 100644 (file)
@@ -7600,6 +7600,8 @@ grokfield (location_t loc,
 
   finish_decl (value, loc, NULL_TREE, NULL_TREE, NULL_TREE);
   DECL_INITIAL (value) = width;
+  if (width)
+    SET_DECL_C_BIT_FIELD (value);
 
   if (warn_cxx_compat && DECL_NAME (value) != NULL_TREE)
     {
@@ -7944,12 +7946,11 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes,
       if (C_DECL_VARIABLE_SIZE (x))
        C_TYPE_VARIABLE_SIZE (t) = 1;
 
-      if (DECL_INITIAL (x))
+      if (DECL_C_BIT_FIELD (x))
        {
          unsigned HOST_WIDE_INT width = tree_to_uhwi (DECL_INITIAL (x));
          DECL_SIZE (x) = bitsize_int (width);
          DECL_BIT_FIELD (x) = 1;
-         SET_DECL_C_BIT_FIELD (x);
        }
 
       if (TYPE_PACKED (t)
index 95110b87c3c2df68f9acf3d651e037ec7f14e89d..fe73935eea2fbcb8eb32828c450cf003ae97b144 100644 (file)
@@ -1,5 +1,15 @@
 2017-09-29  Jakub Jelinek  <jakub@redhat.com>
 
+       * class.c (check_bitfield_decl): Retrieve and clear width from
+       DECL_BIT_FIELD_REPRESENTATIVE rather than DECL_INITIAL.
+       (check_field_decls): Test DECL_BIT_FIELD_REPRESENTATIVE rather than
+       DECL_INITIAL.
+       (remove_zero_width_bit_fields): Adjust comment.
+       * decl2.c (grokbitfield): Stash width into
+       DECL_BIT_FIELD_REPRESENTATIVE rather than DECL_INITIAL.
+       * pt.c (tsubst_decl): For DECL_C_BIT_FIELD, tsubst_expr
+       DECL_BIT_FIELD_REPRESENTATIVE rather than DECL_INITIAL for width.
+
        * parser.c (cp_parser_member_declaration): Parse attributes before
        colon of a bitfield in addition to after colon.
 
index 97e29c0604e028c52b7c502c28475cfe06989656..687ddaa5c8f2f410bd1147a6028474a093448152 100644 (file)
@@ -3231,12 +3231,12 @@ check_bitfield_decl (tree field)
   tree w;
 
   /* Extract the declared width of the bitfield, which has been
-     temporarily stashed in DECL_INITIAL.  */
-  w = DECL_INITIAL (field);
+     temporarily stashed in DECL_BIT_FIELD_REPRESENTATIVE by grokbitfield.  */
+  w = DECL_BIT_FIELD_REPRESENTATIVE (field);
   gcc_assert (w != NULL_TREE);
   /* Remove the bit-field width indicator so that the rest of the
-     compiler does not treat that value as an initializer.  */
-  DECL_INITIAL (field) = NULL_TREE;
+     compiler does not treat that value as a qualifier.  */
+  DECL_BIT_FIELD_REPRESENTATIVE (field) = NULL_TREE;
 
   /* Detect invalid bit-field type.  */
   if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
@@ -3571,7 +3571,8 @@ check_field_decls (tree t, tree *access_decls,
            DECL_PACKED (x) = 1;
        }
 
-      if (DECL_C_BIT_FIELD (x) && integer_zerop (DECL_INITIAL (x)))
+      if (DECL_C_BIT_FIELD (x)
+         && integer_zerop (DECL_BIT_FIELD_REPRESENTATIVE (x)))
        /* We don't treat zero-width bitfields as making a class
           non-empty.  */
        ;
@@ -5268,9 +5269,9 @@ remove_zero_width_bit_fields (tree t)
     {
       if (TREE_CODE (*fieldsp) == FIELD_DECL
          && DECL_C_BIT_FIELD (*fieldsp)
-          /* We should not be confused by the fact that grokbitfield
+         /* We should not be confused by the fact that grokbitfield
             temporarily sets the width of the bit field into
-            DECL_INITIAL (*fieldsp).
+            DECL_BIT_FIELD_REPRESENTATIVE (*fieldsp).
             check_bitfield_decl eventually sets DECL_SIZE (*fieldsp)
             to that width.  */
          && (DECL_SIZE (*fieldsp) == NULL_TREE
index 29d6c59f549a0292ffa94f04308f065b462d132d..107ce7bc882ffdfd9a3703da5bb8a2b061bba862 100644 (file)
@@ -1047,7 +1047,10 @@ grokbitfield (const cp_declarator *declarator,
               TREE_TYPE (width));
       else
        {
-         DECL_INITIAL (value) = width;
+         /* Temporarily stash the width in DECL_BIT_FIELD_REPRESENTATIVE.
+            check_bitfield_decl picks it from there later and sets DECL_SIZE
+            accordingly.  */
+         DECL_BIT_FIELD_REPRESENTATIVE (value) = width;
          SET_DECL_C_BIT_FIELD (value);
        }
     }
index 0dae10e032b9f871b653cfb2984b483253bae069..70cfc9aac8a4523d09f63e7f71a3a8a494fe0fbd 100644 (file)
@@ -12835,11 +12835,10 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
            cp_apply_type_quals_to_decl (cp_type_quals (type), r);
 
            if (DECL_C_BIT_FIELD (r))
-             /* For bit-fields, DECL_INITIAL gives the number of bits.  For
-                non-bit-fields DECL_INITIAL is a non-static data member
-                initializer, which gets deferred instantiation.  */
-             DECL_INITIAL (r)
-               = tsubst_expr (DECL_INITIAL (t), args,
+             /* For bit-fields, DECL_BIT_FIELD_REPRESENTATIVE gives the
+                number of bits.  */
+             DECL_BIT_FIELD_REPRESENTATIVE (r)
+               = tsubst_expr (DECL_BIT_FIELD_REPRESENTATIVE (t), args,
                               complain, in_decl,
                               /*integral_constant_expression_p=*/true);
            else if (DECL_INITIAL (t))
index d5929493fe3cf4ee63f7a3e8c34c0b3599f7bbc2..ddfdb1c8c9011e46f0130ba5272fa013c6e5f8ab 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-29  Jakub Jelinek  <jakub@redhat.com>
+
+       * objc-act.c (check_ivars, gen_declaration): For OBJCPLUS look at
+       DECL_BIT_FIELD_REPRESENTATIVE rather than DECL_INITIAL.
+
 2017-08-30  Richard Sandiford  <richard.sandiford@linaro.org>
            Alan Hayward  <alan.hayward@arm.com>
            David Sherwood  <david.sherwood@arm.com>
index 5f70961e7d79c90afa44d4c0ecc6c63030e5cf18..5d81af7fbd6b8df7b34dad33d884e8aa542d337a 100644 (file)
@@ -4602,8 +4602,14 @@ check_ivars (tree inter, tree imp)
       t1 = TREE_TYPE (intdecls); t2 = TREE_TYPE (impdecls);
 
       if (!comptypes (t1, t2)
+#ifdef OBJCPLUS
+         || !tree_int_cst_equal (DECL_BIT_FIELD_REPRESENTATIVE (intdecls),
+                                 DECL_BIT_FIELD_REPRESENTATIVE (impdecls))
+#else
          || !tree_int_cst_equal (DECL_INITIAL (intdecls),
-                                 DECL_INITIAL (impdecls)))
+                                 DECL_INITIAL (impdecls))
+#endif
+        )
        {
          if (DECL_NAME (intdecls) == DECL_NAME (impdecls))
            {
@@ -8895,10 +8901,14 @@ gen_declaration (tree decl)
          strcat (errbuf, IDENTIFIER_POINTER (DECL_NAME (decl)));
        }
 
-      if (DECL_INITIAL (decl)
-         && TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST)
+#ifdef OBJCPLUS
+      tree w = DECL_BIT_FIELD_REPRESENTATIVE (decl);
+#else
+      tree w = DECL_INITIAL (decl);
+#endif
+      if (w && TREE_CODE (w) == INTEGER_CST)
        sprintf (errbuf + strlen (errbuf), ": " HOST_WIDE_INT_PRINT_DEC,
-                TREE_INT_CST_LOW (DECL_INITIAL (decl)));
+                TREE_INT_CST_LOW (w));
     }
 
   return errbuf;