From: Jakub Jelinek Date: Fri, 29 Sep 2017 17:45:32 +0000 (+0200) Subject: c-attribs.c (handle_packed_attribute): Test DECL_C_BIT_FIELD rather than DECL_INITIAL. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7d386d45085cbe472089a8df4a2f033d9d5999a5;p=gcc.git c-attribs.c (handle_packed_attribute): Test DECL_C_BIT_FIELD rather than DECL_INITIAL. 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 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 32f87276a0b..6a9137ffa4f 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,9 @@ +2017-09-29 Jakub Jelinek + + * 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 * c.opt (gen-decls): Add RejectNegative. diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index 0337537ecbd..1821d3e52bc 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -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; diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 496b767cb51..87d6c0aaca6 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,5 +1,10 @@ 2017-09-29 Jakub Jelinek + * 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. diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 080a2e9c0bd..a6b7c204191 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -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) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 95110b87c3c..fe73935eea2 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,15 @@ 2017-09-29 Jakub Jelinek + * 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. diff --git a/gcc/cp/class.c b/gcc/cp/class.c index 97e29c0604e..687ddaa5c8f 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -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 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 29d6c59f549..107ce7bc882 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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); } } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0dae10e032b..70cfc9aac8a 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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)) diff --git a/gcc/objc/ChangeLog b/gcc/objc/ChangeLog index d5929493fe3..ddfdb1c8c90 100644 --- a/gcc/objc/ChangeLog +++ b/gcc/objc/ChangeLog @@ -1,3 +1,8 @@ +2017-09-29 Jakub Jelinek + + * objc-act.c (check_ivars, gen_declaration): For OBJCPLUS look at + DECL_BIT_FIELD_REPRESENTATIVE rather than DECL_INITIAL. + 2017-08-30 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/objc/objc-act.c b/gcc/objc/objc-act.c index 5f70961e7d7..5d81af7fbd6 100644 --- a/gcc/objc/objc-act.c +++ b/gcc/objc/objc-act.c @@ -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;