From 3e636daf67f5bc544fa620a8d2b460207ec37536 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Sat, 14 Nov 2015 12:31:45 +0000 Subject: [PATCH] c-decl.c: Use RECORD_OR_UNION_TYPE_P throughout. * c-decl.c: Use RECORD_OR_UNION_TYPE_P throughout. * c-typeck.c: Likewise. From-SVN: r230375 --- gcc/c/ChangeLog | 5 +++ gcc/c/c-decl.c | 38 ++++++++--------------- gcc/c/c-typeck.c | 81 ++++++++++++++++-------------------------------- 3 files changed, 45 insertions(+), 79 deletions(-) diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 810f2c6c575..04fe64da277 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2015-11-14 Marek Polacek + + * c-decl.c: Use RECORD_OR_UNION_TYPE_P throughout. + * c-typeck.c: Likewise. + 2015-11-13 David Malcolm * c-decl.c (warn_defaults_to): Pass line_table to diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 9a222d8f511..7b9ab8ae646 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -3048,8 +3048,7 @@ pushdecl (tree x) element = TREE_TYPE (element); element = TYPE_MAIN_VARIANT (element); - if ((TREE_CODE (element) == RECORD_TYPE - || TREE_CODE (element) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (element) && (TREE_CODE (x) != TYPE_DECL || TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE) && !COMPLETE_TYPE_P (element)) @@ -4643,8 +4642,7 @@ diagnose_uninitialized_cst_member (tree decl, tree type) inform (DECL_SOURCE_LOCATION (field), "%qD should be initialized", field); } - if (TREE_CODE (field_type) == RECORD_TYPE - || TREE_CODE (field_type) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (field_type)) diagnose_uninitialized_cst_member (decl, field_type); } } @@ -4966,8 +4964,7 @@ finish_decl (tree decl, location_t init_loc, tree init, if (TREE_READONLY (decl)) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, "uninitialized const %qD is invalid in C++", decl); - else if ((TREE_CODE (type) == RECORD_TYPE - || TREE_CODE (type) == UNION_TYPE) + else if (RECORD_OR_UNION_TYPE_P (type) && C_TYPE_FIELDS_READONLY (type)) diagnose_uninitialized_cst_member (decl, type); } @@ -6726,8 +6723,7 @@ grokdeclarator (const struct c_declarator *declarator, && VAR_P (decl) && TREE_PUBLIC (decl) && TREE_STATIC (decl) - && (TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE + && (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)) || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE) && TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE) warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wc___compat, @@ -7282,8 +7278,7 @@ grokfield (location_t loc, that took root before someone noticed the bug... */ tree type = declspecs->type; - bool type_ok = (TREE_CODE (type) == RECORD_TYPE - || TREE_CODE (type) == UNION_TYPE); + bool type_ok = RECORD_OR_UNION_TYPE_P (type); bool ok = false; if (type_ok @@ -7359,7 +7354,7 @@ is_duplicate_field (tree x, tree y) xt = TREE_TYPE (x); if (DECL_NAME (x) != NULL_TREE) xn = DECL_NAME (x); - else if ((TREE_CODE (xt) == RECORD_TYPE || TREE_CODE (xt) == UNION_TYPE) + else if (RECORD_OR_UNION_TYPE_P (xt) && TYPE_NAME (xt) != NULL_TREE && TREE_CODE (TYPE_NAME (xt)) == TYPE_DECL) xn = DECL_NAME (TYPE_NAME (xt)); @@ -7369,7 +7364,7 @@ is_duplicate_field (tree x, tree y) yt = TREE_TYPE (y); if (DECL_NAME (y) != NULL_TREE) yn = DECL_NAME (y); - else if ((TREE_CODE (yt) == RECORD_TYPE || TREE_CODE (yt) == UNION_TYPE) + else if (RECORD_OR_UNION_TYPE_P (yt) && TYPE_NAME (yt) != NULL_TREE && TREE_CODE (TYPE_NAME (yt)) == TYPE_DECL) yn = DECL_NAME (TYPE_NAME (yt)); @@ -7404,8 +7399,7 @@ detect_field_duplicates_hash (tree fieldlist, } *slot = y; } - else if (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE) + else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))) { detect_field_duplicates_hash (TYPE_FIELDS (TREE_TYPE (x)), htab); @@ -7456,8 +7450,7 @@ detect_field_duplicates (tree fieldlist) do { timeout--; if (DECL_NAME (x) == NULL_TREE - && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)) + && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))) timeout = 0; x = DECL_CHAIN (x); } while (timeout > 0 && x); @@ -7473,8 +7466,7 @@ detect_field_duplicates (tree fieldlist) if (DECL_NAME (x) || (flag_plan9_extensions && DECL_NAME (x) == NULL_TREE - && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE) + && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x)) && TYPE_NAME (TREE_TYPE (x)) != NULL_TREE && TREE_CODE (TYPE_NAME (TREE_TYPE (x))) == TYPE_DECL)) { @@ -7587,9 +7579,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, { if (DECL_NAME (x) != 0) break; - if (flag_isoc11 - && (TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE)) + if (flag_isoc11 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))) break; } @@ -7634,8 +7624,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, { /* A field that is pseudo-const makes the structure likewise. */ tree t1 = strip_array_types (TREE_TYPE (x)); - if ((TREE_CODE (t1) == RECORD_TYPE || TREE_CODE (t1) == UNION_TYPE) - && C_TYPE_FIELDS_READONLY (t1)) + if (RECORD_OR_UNION_TYPE_P (t1) && C_TYPE_FIELDS_READONLY (t1)) C_TYPE_FIELDS_READONLY (t) = 1; } @@ -7693,8 +7682,7 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, "invalid use of structure with flexible array member"); if (DECL_NAME (x) - || TREE_CODE (TREE_TYPE (x)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (x)) == UNION_TYPE) + || RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))) saw_named_field = 1; } diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index 4db9bbf1c3c..0215edac3c5 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -2166,8 +2166,7 @@ lookup_field (tree type, tree component) while (DECL_NAME (field_array[bot]) == NULL_TREE) { field = field_array[bot++]; - if (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))) { tree anon = lookup_field (TREE_TYPE (field), component); @@ -2213,8 +2212,7 @@ lookup_field (tree type, tree component) for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { if (DECL_NAME (field) == NULL_TREE - && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)) + && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))) { tree anon = lookup_field (TREE_TYPE (field), component); @@ -2253,13 +2251,9 @@ lookup_field_fuzzy_find_candidates (tree type, tree component, for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) { if (DECL_NAME (field) == NULL_TREE - && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)) - { - lookup_field_fuzzy_find_candidates (TREE_TYPE (field), - component, - candidates); - } + && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))) + lookup_field_fuzzy_find_candidates (TREE_TYPE (field), component, + candidates); if (DECL_NAME (field)) candidates->safe_push (DECL_NAME (field)); @@ -5131,8 +5125,7 @@ build_c_cast (location_t loc, tree type, tree expr) if (type == TYPE_MAIN_VARIANT (TREE_TYPE (value))) { - if (TREE_CODE (type) == RECORD_TYPE - || TREE_CODE (type) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (type)) pedwarn (loc, OPT_Wpedantic, "ISO C forbids casting nonscalar to the same type"); @@ -5224,8 +5217,7 @@ build_c_cast (location_t loc, tree type, tree expr) && TREE_CODE (TREE_TYPE (otype)) != FUNCTION_TYPE /* Don't warn about opaque types, where the actual alignment restriction is unknown. */ - && !((TREE_CODE (TREE_TYPE (otype)) == UNION_TYPE - || TREE_CODE (TREE_TYPE (otype)) == RECORD_TYPE) + && !(RECORD_OR_UNION_TYPE_P (TREE_TYPE (otype)) && TYPE_MODE (TREE_TYPE (otype)) == VOIDmode) && TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (otype))) warning_at (loc, OPT_Wcast_align, @@ -5484,8 +5476,7 @@ build_modify_expr (location_t location, tree lhs, tree lhs_origtype, /* Give an error for storing in something that is 'const'. */ if (TYPE_READONLY (lhstype) - || ((TREE_CODE (lhstype) == RECORD_TYPE - || TREE_CODE (lhstype) == UNION_TYPE) + || (RECORD_OR_UNION_TYPE_P (lhstype) && C_TYPE_FIELDS_READONLY (lhstype))) { readonly_error (location, lhs, lv_assign); @@ -5611,8 +5602,7 @@ find_anonymous_field_with_type (tree struct_type, tree type) tree field; bool found; - gcc_assert (TREE_CODE (struct_type) == RECORD_TYPE - || TREE_CODE (struct_type) == UNION_TYPE); + gcc_assert (RECORD_OR_UNION_TYPE_P (struct_type)); found = false; for (field = TYPE_FIELDS (struct_type); field != NULL_TREE; @@ -5630,8 +5620,7 @@ find_anonymous_field_with_type (tree struct_type, tree type) found = true; } else if (DECL_NAME (field) == NULL - && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE) + && RECORD_OR_UNION_TYPE_P (TREE_TYPE (field)) && find_anonymous_field_with_type (TREE_TYPE (field), type)) { if (found) @@ -5657,8 +5646,7 @@ convert_to_anonymous_field (location_t location, tree type, tree rhs) gcc_assert (POINTER_TYPE_P (TREE_TYPE (rhs))); rhs_struct_type = TREE_TYPE (TREE_TYPE (rhs)); - gcc_assert (TREE_CODE (rhs_struct_type) == RECORD_TYPE - || TREE_CODE (rhs_struct_type) == UNION_TYPE); + gcc_assert (RECORD_OR_UNION_TYPE_P (rhs_struct_type)); gcc_assert (POINTER_TYPE_P (type)); lhs_main_type = (TYPE_ATOMIC (TREE_TYPE (type)) @@ -5673,8 +5661,7 @@ convert_to_anonymous_field (location_t location, tree type, tree rhs) field = TREE_CHAIN (field)) { if (DECL_NAME (field) != NULL_TREE - || (TREE_CODE (TREE_TYPE (field)) != RECORD_TYPE - && TREE_CODE (TREE_TYPE (field)) != UNION_TYPE)) + || !RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))) continue; tree fieldtype = (TYPE_ATOMIC (TREE_TYPE (field)) ? c_build_qualified_type (TREE_TYPE (field), @@ -6211,8 +6198,8 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, automatically converted into a pointer to an anonymous field within the struct. */ if (flag_plan9_extensions - && (TREE_CODE (mvl) == RECORD_TYPE || TREE_CODE(mvl) == UNION_TYPE) - && (TREE_CODE (mvr) == RECORD_TYPE || TREE_CODE(mvr) == UNION_TYPE) + && RECORD_OR_UNION_TYPE_P (mvl) + && RECORD_OR_UNION_TYPE_P (mvr) && mvl != mvr) { tree new_rhs = convert_to_anonymous_field (location, type, rhs); @@ -7367,8 +7354,7 @@ really_start_incremental_init (tree type) designator_depth = 0; designator_erroneous = 0; - if (TREE_CODE (constructor_type) == RECORD_TYPE - || TREE_CODE (constructor_type) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (constructor_type)) { constructor_fields = TYPE_FIELDS (constructor_type); /* Skip any nameless bit fields at the beginning. */ @@ -7448,8 +7434,7 @@ push_init_level (location_t loc, int implicit, { while (constructor_stack->implicit) { - if ((TREE_CODE (constructor_type) == RECORD_TYPE - || TREE_CODE (constructor_type) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields == 0) process_init_element (input_location, pop_init_level (loc, 1, braced_init_obstack), @@ -7470,9 +7455,7 @@ push_init_level (location_t loc, int implicit, content if any. */ if (implicit) { - if ((TREE_CODE (constructor_type) == RECORD_TYPE - || TREE_CODE (constructor_type) == UNION_TYPE) - && constructor_fields) + if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields) value = find_init_member (constructor_fields, braced_init_obstack); else if (TREE_CODE (constructor_type) == ARRAY_TYPE) value = find_init_member (constructor_index, braced_init_obstack); @@ -7525,8 +7508,7 @@ push_init_level (location_t loc, int implicit, in the containing level. */ if (constructor_type == 0) ; - else if (TREE_CODE (constructor_type) == RECORD_TYPE - || TREE_CODE (constructor_type) == UNION_TYPE) + else if (RECORD_OR_UNION_TYPE_P (constructor_type)) { /* Don't die if there are extra init elts at the end. */ if (constructor_fields == 0) @@ -7571,8 +7553,7 @@ push_init_level (location_t loc, int implicit, if (implicit == 1) found_missing_braces = 1; - if (TREE_CODE (constructor_type) == RECORD_TYPE - || TREE_CODE (constructor_type) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (constructor_type)) { constructor_fields = TYPE_FIELDS (constructor_type); /* Skip any nameless bit fields at the beginning. */ @@ -7760,8 +7741,7 @@ pop_init_level (location_t loc, int implicit, ret = p->replacement_value; else if (constructor_type == 0) ; - else if (TREE_CODE (constructor_type) != RECORD_TYPE - && TREE_CODE (constructor_type) != UNION_TYPE + else if (!RECORD_OR_UNION_TYPE_P (constructor_type) && TREE_CODE (constructor_type) != ARRAY_TYPE && !VECTOR_TYPE_P (constructor_type)) { @@ -8028,8 +8008,7 @@ set_init_label (location_t loc, tree fieldname, designator_erroneous = 1; - if (TREE_CODE (constructor_type) != RECORD_TYPE - && TREE_CODE (constructor_type) != UNION_TYPE) + if (!RECORD_OR_UNION_TYPE_P (constructor_type)) { error_init (loc, "field name not in record or union initializer"); return; @@ -8544,8 +8523,7 @@ output_init_element (location_t loc, tree value, tree origtype, AGGREGATE_TYPE_P (constructor_type) && TYPE_REVERSE_STORAGE_ORDER (constructor_type)) - || ((TREE_CODE (constructor_type) == RECORD_TYPE - || TREE_CODE (constructor_type) == UNION_TYPE) + || (RECORD_OR_UNION_TYPE_P (constructor_type) && DECL_C_BIT_FIELD (field) && TREE_CODE (value) != INTEGER_CST)) constructor_simple = 0; @@ -8766,8 +8744,7 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack) } } } - else if (TREE_CODE (constructor_type) == RECORD_TYPE - || TREE_CODE (constructor_type) == UNION_TYPE) + else if (RECORD_OR_UNION_TYPE_P (constructor_type)) { tree ctor_unfilled_bitpos, elt_bitpos; @@ -8831,8 +8808,7 @@ output_pending_init_elements (int all, struct obstack * braced_init_obstack) /* If it's not incremental, just skip over the gap, so that after jumping to retry we will output the next successive element. */ - if (TREE_CODE (constructor_type) == RECORD_TYPE - || TREE_CODE (constructor_type) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (constructor_type)) constructor_unfilled_fields = next; else if (TREE_CODE (constructor_type) == ARRAY_TYPE) constructor_unfilled_index = next; @@ -8909,8 +8885,7 @@ process_init_element (location_t loc, struct c_expr value, bool implicit, pop them now. */ while (constructor_stack->implicit) { - if ((TREE_CODE (constructor_type) == RECORD_TYPE - || TREE_CODE (constructor_type) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (constructor_type) && constructor_fields == 0) process_init_element (loc, pop_init_level (loc, 1, braced_init_obstack), @@ -9357,8 +9332,7 @@ build_asm_expr (location_t loc, tree string, tree outputs, tree inputs, if (output != error_mark_node && (TREE_READONLY (output) || TYPE_READONLY (TREE_TYPE (output)) - || ((TREE_CODE (TREE_TYPE (output)) == RECORD_TYPE - || TREE_CODE (TREE_TYPE (output)) == UNION_TYPE) + || (RECORD_OR_UNION_TYPE_P (TREE_TYPE (output)) && C_TYPE_FIELDS_READONLY (TREE_TYPE (output))))) readonly_error (loc, output, lv_asm); @@ -13376,8 +13350,7 @@ c_build_qualified_type (tree type, int type_quals) tree var_type = build_qualified_type (type, type_quals); /* A variant type does not inherit the list of incomplete vars from the type main variant. */ - if (TREE_CODE (var_type) == RECORD_TYPE - || TREE_CODE (var_type) == UNION_TYPE) + if (RECORD_OR_UNION_TYPE_P (var_type)) C_TYPE_INCOMPLETE_VARS (var_type) = 0; return var_type; } -- 2.30.2