From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29590 invoked by alias); 26 Jun 2015 10:10:27 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 29576 invoked by uid 89); 26 Jun 2015 10:10:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 26 Jun 2015 10:10:25 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id F07DD389DAD for ; Fri, 26 Jun 2015 10:10:23 +0000 (UTC) Received: from redhat.com (ovpn-204-67.brq.redhat.com [10.40.204.67]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5QAAJZW019637 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO); Fri, 26 Jun 2015 06:10:22 -0400 Date: Fri, 26 Jun 2015 10:10:00 -0000 From: Marek Polacek To: GCC Patches , Jason Merrill Subject: C++ PATCH to use VAR_P Message-ID: <20150626101019.GH10139@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-SW-Source: 2015-06/txt/msg01922.txt.bz2 Since Gaby's cleanup in 2013 many uses of TREE_CODE (decl) == VAR_DECL have crept back in. This is another cleanup in this area. Bootstrapped/regtested on x86_64-linux, ok for trunk? 2015-06-26 Marek Polacek * call.c (set_up_extended_ref_temp): Use VAR_P. * class.c: Use VAR_P throughout. * constexpr.c (cxx_eval_constant_expression): Use VAR_P. * cp-array-notation.c (make_triplet_val_inv): Likewise. * decl.c: Use VAR_OR_FUNCTION_DECL_P or VAR_P throughout. * decl2.c: Likewise. * error.c (dump_decl): Use VAR_P. * mangle.c (decl_implicit_alias_p): Likewise. * parser.c: Use VAR_P throughout. * pt.c: Likewise. * semantics.c: Likewise. * vtable-class-hierarchy.c: Likewise. * tree.c (handle_abi_tag_attribute): Use VAR_OR_FUNCTION_DECL_P. diff --git gcc/cp/call.c gcc/cp/call.c index 0e8840b..e5ed53b 100644 --- gcc/cp/call.c +++ gcc/cp/call.c @@ -9697,7 +9697,7 @@ set_up_extended_ref_temp (tree decl, tree expr, vec **cleanups, } /* Avoid -Wunused-variable warning (c++/38958). */ if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type) - && TREE_CODE (decl) == VAR_DECL) + && VAR_P (decl)) TREE_USED (decl) = DECL_READ_P (decl) = true; *initp = init; diff --git gcc/cp/class.c gcc/cp/class.c index f4e4f85..6c7fa99 100644 --- gcc/cp/class.c +++ gcc/cp/class.c @@ -1399,7 +1399,7 @@ check_tag (tree tag, tree id, tree *tp, abi_tag_data *p) p->t, tag, *tp)) inform (location_of (*tp), "%qT declared here", *tp); } - else if (TREE_CODE (p->t) == VAR_DECL) + else if (VAR_P (p->t)) { if (warning (OPT_Wabi_tag, "%qD inherits the %E ABI tag " "that %qT (used in its type) has", p->t, tag, *tp)) @@ -1588,7 +1588,7 @@ check_abi_tags (tree t, tree subob) void check_abi_tags (tree decl) { - if (TREE_CODE (decl) == VAR_DECL) + if (VAR_P (decl)) check_abi_tags (decl, TREE_TYPE (decl)); else if (TREE_CODE (decl) == FUNCTION_DECL && !mangle_return_type_p (decl)) @@ -3040,7 +3040,7 @@ finish_struct_anon_r (tree field, bool complain) { /* We already complained about static data members in finish_static_data_member_decl. */ - if (complain && TREE_CODE (elt) != VAR_DECL) + if (complain && !VAR_P (elt)) { if (is_union) permerror (input_location, diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c index 9cb45ea..4fce5e0 100644 --- gcc/cp/constexpr.c +++ gcc/cp/constexpr.c @@ -3033,7 +3033,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t, if (TREE_CODE (r) == TARGET_EXPR && TREE_CODE (TARGET_EXPR_INITIAL (r)) == CONSTRUCTOR) r = TARGET_EXPR_INITIAL (r); - if (TREE_CODE (r) == VAR_DECL) + if (VAR_P (r)) if (tree *p = ctx->values->get (r)) r = *p; if (DECL_P (r)) diff --git gcc/cp/cp-array-notation.c gcc/cp/cp-array-notation.c index 3b8610f..4daa57c 100644 --- gcc/cp/cp-array-notation.c +++ gcc/cp/cp-array-notation.c @@ -87,7 +87,7 @@ make_triplet_val_inv (tree *value) { if (TREE_CODE (*value) != INTEGER_CST && TREE_CODE (*value) != PARM_DECL - && TREE_CODE (*value) != VAR_DECL) + && !VAR_P (*value)) *value = get_temp_regvar (ptrdiff_type_node, *value); } diff --git gcc/cp/decl.c gcc/cp/decl.c index 1fa28b2..9594223 100644 --- gcc/cp/decl.c +++ gcc/cp/decl.c @@ -2476,14 +2476,15 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) { struct symtab_node *snode = NULL; - if (TREE_CODE (newdecl) == VAR_DECL - && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl) || DECL_EXTERNAL (olddecl))) + if (VAR_P (newdecl) + && (TREE_STATIC (olddecl) || TREE_PUBLIC (olddecl) + || DECL_EXTERNAL (olddecl))) snode = symtab_node::get (olddecl); memcpy ((char *) olddecl + sizeof (struct tree_decl_common), (char *) newdecl + sizeof (struct tree_decl_common), size - sizeof (struct tree_decl_common) + TREE_CODE_LENGTH (TREE_CODE (newdecl)) * sizeof (char *)); - if (TREE_CODE (newdecl) == VAR_DECL) + if (VAR_P (newdecl)) olddecl->decl_with_vis.symtab_node = snode; } break; @@ -2496,8 +2497,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) } } - if (TREE_CODE (newdecl) == FUNCTION_DECL - || TREE_CODE (newdecl) == VAR_DECL) + if (VAR_OR_FUNCTION_DECL_P (newdecl)) { if (DECL_EXTERNAL (olddecl) || TREE_PUBLIC (olddecl) @@ -2522,7 +2522,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) } } - if (TREE_CODE (newdecl) == VAR_DECL + if (VAR_P (newdecl) && DECL_THREAD_LOCAL_P (newdecl)) set_decl_tls_model (olddecl, DECL_TLS_MODEL (newdecl)); } @@ -2559,8 +2559,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool newdecl_is_friend) structure is shared in between newdecl and oldecl. */ if (TREE_CODE (newdecl) == FUNCTION_DECL) DECL_STRUCT_FUNCTION (newdecl) = NULL; - if (TREE_CODE (newdecl) == FUNCTION_DECL - || TREE_CODE (newdecl) == VAR_DECL) + if (VAR_OR_FUNCTION_DECL_P (newdecl)) { struct symtab_node *snode = symtab_node::get (newdecl); if (snode) @@ -4828,7 +4827,7 @@ start_decl (const cp_declarator *declarator, /* Enter this declaration into the symbol table. Don't push the plain VAR_DECL for a variable template. */ if (!template_parm_scope_p () - || TREE_CODE (decl) != VAR_DECL) + || !VAR_P (decl)) decl = maybe_push_decl (decl); if (processing_template_decl) diff --git gcc/cp/decl2.c gcc/cp/decl2.c index f045253..da531fa 100644 --- gcc/cp/decl2.c +++ gcc/cp/decl2.c @@ -1005,7 +1005,7 @@ grokfield (const cp_declarator *declarator, return value; /* Need to set this before push_template_decl. */ - if (TREE_CODE (value) == VAR_DECL) + if (VAR_P (value)) DECL_CONTEXT (value) = current_class_type; if (processing_template_decl && VAR_OR_FUNCTION_DECL_P (value)) @@ -1417,7 +1417,7 @@ cp_omp_mappable_type (tree type) { tree field; for (field = TYPE_FIELDS (type); field; field = DECL_CHAIN (field)) - if (TREE_CODE (field) == VAR_DECL) + if (VAR_P (field)) return false; /* All fields must have mappable types. */ else if (TREE_CODE (field) == FIELD_DECL @@ -1438,21 +1438,21 @@ cplus_decl_attributes (tree *decl, tree attributes, int flags) /* Add implicit "omp declare target" attribute if requested. */ if (scope_chain->omp_declare_target_attribute - && ((TREE_CODE (*decl) == VAR_DECL + && ((VAR_P (*decl) && (TREE_STATIC (*decl) || DECL_EXTERNAL (*decl))) || TREE_CODE (*decl) == FUNCTION_DECL)) { - if (TREE_CODE (*decl) == VAR_DECL + if (VAR_P (*decl) && DECL_CLASS_SCOPE_P (*decl)) error ("%q+D static data member inside of declare target directive", *decl); - else if (TREE_CODE (*decl) == VAR_DECL + else if (VAR_P (*decl) && (DECL_FUNCTION_SCOPE_P (*decl) || (current_function_decl && !DECL_EXTERNAL (*decl)))) error ("%q+D in block scope inside of declare target directive", *decl); else if (!processing_template_decl - && TREE_CODE (*decl) == VAR_DECL + && VAR_P (*decl) && !cp_omp_mappable_type (TREE_TYPE (*decl))) error ("%q+D in declare target directive does not have mappable type", *decl); @@ -1980,7 +1980,7 @@ mark_needed (tree decl) FOR_EACH_CLONE (clone, decl) mark_needed (clone); } - else if (TREE_CODE (decl) == VAR_DECL) + else if (VAR_P (decl)) { varpool_node *node = varpool_node::get_create (decl); /* C++ frontend use mark_decl_references to force COMDAT variables @@ -2179,8 +2179,7 @@ constrain_visibility (tree decl, int visibility, bool tmpl) DECL_WEAK (decl) = 0; DECL_COMMON (decl) = 0; DECL_COMDAT (decl) = false; - if (TREE_CODE (decl) == FUNCTION_DECL - || TREE_CODE (decl) == VAR_DECL) + if (VAR_OR_FUNCTION_DECL_P (decl)) { struct symtab_node *snode = symtab_node::get (decl); @@ -2643,7 +2642,7 @@ reset_type_linkage_2 (tree type) reset_decl_linkage (ti); } for (tree m = TYPE_FIELDS (type); m; m = DECL_CHAIN (m)) - if (TREE_CODE (m) == VAR_DECL) + if (VAR_P (m)) reset_decl_linkage (m); for (tree m = TYPE_METHODS (type); m; m = DECL_CHAIN (m)) { @@ -2701,7 +2700,7 @@ tentative_decl_linkage (tree decl) DECL_INTERFACE_KNOWN (decl) = 1; } } - else if (TREE_CODE (decl) == VAR_DECL) + else if (VAR_P (decl)) maybe_commonize_var (decl); } } @@ -4208,7 +4207,7 @@ no_linkage_error (tree decl) "anonymous type, is used but never defined", decl); else if (DECL_EXTERN_C_P (decl)) /* Allow this; it's pretty common in C. */; - else if (TREE_CODE (decl) == VAR_DECL) + else if (VAR_P (decl)) /* DRs 132, 319 and 389 seem to indicate types with no linkage can only be used to declare extern "C" entities. Since it's not always an error in the @@ -4227,12 +4226,12 @@ no_linkage_error (tree decl) } else if (cxx_dialect >= cxx11) { - if (TREE_CODE (decl) == VAR_DECL || !DECL_PURE_VIRTUAL_P (decl)) + if (VAR_P (decl) || !DECL_PURE_VIRTUAL_P (decl)) permerror (DECL_SOURCE_LOCATION (decl), "%q#D, declared using local type " "%qT, is used but never defined", decl, t); } - else if (TREE_CODE (decl) == VAR_DECL) + else if (VAR_P (decl)) warning_at (DECL_SOURCE_LOCATION (decl), 0, "type %qT with no linkage " "used to declare variable %q#D with linkage", t, decl); else diff --git gcc/cp/error.c gcc/cp/error.c index 96fa94d..3710046 100644 --- gcc/cp/error.c +++ gcc/cp/error.c @@ -1065,7 +1065,7 @@ dump_decl (cxx_pretty_printer *pp, tree t, int flags) dump_simple_decl (pp, t, TREE_TYPE (t), flags); /* Handle variable template specializations. */ - if (TREE_CODE (t) == VAR_DECL + if (VAR_P (t) && DECL_LANG_SPECIFIC (t) && DECL_TEMPLATE_INFO (t) && PRIMARY_TEMPLATE_P (DECL_TI_TEMPLATE (t))) diff --git gcc/cp/mangle.c gcc/cp/mangle.c index c1a81fc..625e3e6 100644 --- gcc/cp/mangle.c +++ gcc/cp/mangle.c @@ -3529,8 +3529,7 @@ decl_implicit_alias_p (tree decl) if (DECL_P (decl) && DECL_ARTIFICIAL (decl) && DECL_IGNORED_P (decl) && (TREE_CODE (decl) == FUNCTION_DECL - || (TREE_CODE (decl) == VAR_DECL - && TREE_STATIC (decl)))) + || (VAR_P (decl) && TREE_STATIC (decl)))) { symtab_node *n = symtab_node::get (decl); if (n && n->cpp_implicit_alias) diff --git gcc/cp/parser.c gcc/cp/parser.c index 6dc79ac..acf147c 100644 --- gcc/cp/parser.c +++ gcc/cp/parser.c @@ -10571,7 +10571,7 @@ cp_convert_range_for (tree statement, tree range_decl, tree range_expr, { tree range_temp; - if (TREE_CODE (range_expr) == VAR_DECL + if (VAR_P (range_expr) && array_of_runtime_bound_p (TREE_TYPE (range_expr))) /* Can't bind a reference to an array of runtime bound. */ range_temp = range_expr; @@ -28091,7 +28091,7 @@ cp_parser_oacc_data_clause_deviceptr (cp_parser *parser, tree list) c_parser_omp_var_list_parens should construct a list of locations to go along with the var list. */ - if (TREE_CODE (v) != VAR_DECL) + if (!VAR_P (v)) error_at (loc, "%qD is not a variable", v); else if (TREE_TYPE (v) == error_mark_node) ; diff --git gcc/cp/pt.c gcc/cp/pt.c index fe5fc14..4884c36 100644 --- gcc/cp/pt.c +++ gcc/cp/pt.c @@ -2432,7 +2432,7 @@ check_explicit_specialization (tree declarator, switch (tsk) { case tsk_none: - if (processing_specialization && TREE_CODE (decl) != VAR_DECL) + if (processing_specialization && !VAR_P (decl)) { specialization = 1; SET_DECL_TEMPLATE_SPECIALIZATION (decl); @@ -2865,7 +2865,7 @@ check_explicit_specialization (tree declarator, /* A specialization is not necessarily COMDAT. */ DECL_COMDAT (decl) = (TREE_PUBLIC (decl) && DECL_DECLARED_INLINE_P (decl)); - else if (TREE_CODE (decl) == VAR_DECL) + else if (VAR_P (decl)) DECL_COMDAT (decl) = false; /* Register this specialization so that we can find it @@ -4748,7 +4748,7 @@ push_template_decl_real (tree decl, bool is_friend) is_partial = ((DECL_IMPLICIT_TYPEDEF_P (decl) && TREE_CODE (TREE_TYPE (decl)) != ENUMERAL_TYPE && CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl))) - || (TREE_CODE (decl) == VAR_DECL + || (VAR_P (decl) && DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_SPECIALIZATION (decl) && TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (decl)))); @@ -10769,7 +10769,7 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain) if (PRIMARY_TEMPLATE_P (t)) DECL_PRIMARY_TEMPLATE (r) = r; - if (TREE_CODE (decl) != TYPE_DECL && TREE_CODE (decl) != VAR_DECL) + if (TREE_CODE (decl) != TYPE_DECL && !VAR_P (decl)) /* Record this non-type partial instantiation. */ register_specialization (r, t, DECL_TI_ARGS (DECL_TEMPLATE_RESULT (r)), diff --git gcc/cp/semantics.c gcc/cp/semantics.c index 2f3303a..6a74648 100644 --- gcc/cp/semantics.c +++ gcc/cp/semantics.c @@ -3161,7 +3161,7 @@ process_outer_var_ref (tree decl, tsubst_flags_t complain) = decl_function_context (containing_function); } - if (lambda_expr && TREE_CODE (decl) == VAR_DECL + if (lambda_expr && VAR_P (decl) && DECL_ANON_UNION_VAR_P (decl)) { if (complain & tf_error) @@ -4281,7 +4281,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, return error_mark_node; if (type_dependent_expression_p (t)) return NULL_TREE; - if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) + if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) { if (processing_template_decl) return NULL_TREE; @@ -4296,7 +4296,7 @@ handle_omp_array_sections_1 (tree c, tree t, vec &types, return error_mark_node; } else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND - && TREE_CODE (t) == VAR_DECL && DECL_THREAD_LOCAL_P (t)) + && VAR_P (t) && DECL_THREAD_LOCAL_P (t)) { error_at (OMP_CLAUSE_LOCATION (c), "%qD is threadprivate variable in %qs clause", t, @@ -5662,7 +5662,7 @@ finish_omp_clauses (tree clauses) case OMP_CLAUSE_ALIGNED: t = OMP_CLAUSE_DECL (c); - if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) + if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) { if (processing_template_decl) break; @@ -5732,7 +5732,7 @@ finish_omp_clauses (tree clauses) } if (t == error_mark_node) remove = true; - else if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) + else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) { if (processing_template_decl) break; @@ -5774,7 +5774,7 @@ finish_omp_clauses (tree clauses) } if (t == error_mark_node) remove = true; - else if (TREE_CODE (t) != VAR_DECL && TREE_CODE (t) != PARM_DECL) + else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL) { if (processing_template_decl) break; @@ -5789,7 +5789,7 @@ finish_omp_clauses (tree clauses) omp_clause_code_name[OMP_CLAUSE_CODE (c)]); remove = true; } - else if (TREE_CODE (t) == VAR_DECL && DECL_THREAD_LOCAL_P (t)) + else if (VAR_P (t) && DECL_THREAD_LOCAL_P (t)) { error ("%qD is threadprivate variable in %qs clause", t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]); diff --git gcc/cp/tree.c gcc/cp/tree.c index 9ee203f..272fb2c 100644 --- gcc/cp/tree.c +++ gcc/cp/tree.c @@ -3683,8 +3683,7 @@ handle_abi_tag_attribute (tree* node, tree name, tree args, } else { - if (TREE_CODE (*node) != FUNCTION_DECL - && TREE_CODE (*node) != VAR_DECL) + if (!VAR_OR_FUNCTION_DECL_P (*node)) { error ("%qE attribute applied to non-function, non-variable %qD", name, *node); diff --git gcc/cp/vtable-class-hierarchy.c gcc/cp/vtable-class-hierarchy.c index a1582e7..2c59f14 100644 --- gcc/cp/vtable-class-hierarchy.c +++ gcc/cp/vtable-class-hierarchy.c @@ -557,11 +557,11 @@ register_construction_vtables (tree base_class, tree record_type, if (TREE_OPERAND (value, 0)) val_vtbl_decl = TREE_OPERAND (value, 0); - while (TREE_CODE (val_vtbl_decl) != VAR_DECL + while (!VAR_P (val_vtbl_decl) && TREE_OPERAND (val_vtbl_decl, 0)) val_vtbl_decl = TREE_OPERAND (val_vtbl_decl, 0); - gcc_assert (TREE_CODE (val_vtbl_decl) == VAR_DECL); + gcc_assert (VAR_P (val_vtbl_decl)); /* Check to see if we already have this vtable pointer in our valid set for this base class. */ @@ -876,7 +876,7 @@ output_set_info (tree record_type, vec vtbl_ptr_array) if (TREE_CODE (arg0) == ADDR_EXPR) arg0 = TREE_OPERAND (arg0, 0); - if (TREE_CODE (arg0) == VAR_DECL) + if (VAR_P (arg0)) vptr_name = IDENTIFIER_POINTER (DECL_NAME (arg0)); if (TREE_CODE (arg1) == INTEGER_CST) Marek