From patchwork Wed May 13 20:04:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1289692 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=viCq/7UL; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49MlyV40Gdz9sRK for ; Thu, 14 May 2020 06:05:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6B141388B00F; Wed, 13 May 2020 20:05:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by sourceware.org (Postfix) with ESMTPS id 520703851C0E for ; Wed, 13 May 2020 20:04:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 520703851C0E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x733.google.com with SMTP id i5so615898qkl.12 for ; Wed, 13 May 2020 13:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=E7taktoUsVOWHb7dJCjy4u7+0IGMHUfxp7IXt8zcB0Q=; b=viCq/7ULN8HUAcTfMhyQFocUZI/i+LSkLjOoP0izsttqNDgnv5ePE4of8YaXuxP1Nt hQXtsTMts0L3E7SpVPx825pZJtltT+3TL4uUrGvevPuEHo0VSEnqJXQlEey2LOq+zGDD EdMyFEofNCaxnv+uVBVUwT/MXmncPoXq2bC2qt16GsFeTZQNpdZiSR6ivY9YHSqNpTt2 40h5Cn+XLUA5OefxIPVQqRSdK8rrC7a2j5xTqrJbHK7ERYwAYRKcjEo8xw5VabnBW5f2 Gop0ou6v0ZFk+mP3yG5VNd0RrT+KYiRprS67+Y78K2F0VWDLKYvUmxiXQPz+fOwKBnNO rzPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=E7taktoUsVOWHb7dJCjy4u7+0IGMHUfxp7IXt8zcB0Q=; b=N+Tst+rBJk5XBnkHSXBsQxSaDCKqsY6LJSzg2DDmnXw6BFazEOsKDR47eoDcn1Ou7V 7m4tqEpNxNJSeygRRcbDpDdBptgrtQVm/R8HtgxQdzuNmOsgqgoAmDOJ6UfKffjTonuQ iKxJEjcUw4WwPtXdnsZGXHiIP05Uxr7bEPT8ZdjcUFBFXUrBNJjsLFauZNOZhj0O54+u xseBmTRkq+nViw6R97PHtFEQZNUWhoYFJarli+ypppn0Dnb+uucNnP45Qjg+5sEmyjf7 5hdzLdh0u3ZDSi56cyNFUEjLghtFttZa0gwZyJhCa9QhdLb8Hsmj/J8Dve9yAkAEpdAb TTPw== X-Gm-Message-State: AOAM530pCvVc+qeg6Qh3kBmMOVBI4WzcKytsp3F4bPtHedvoDfSdxr4p tsQLpp287o7yQUIOD23DE90= X-Google-Smtp-Source: ABdhPJxQi9HuhVqhX6dVXTuvDRjIXuXlikRCVoKsR5M6a8d/cAu7fv7toMRALXedlkmNmPBbqpAWVQ== X-Received: by 2002:a37:8d85:: with SMTP id p127mr1513793qkd.44.1589400298562; Wed, 13 May 2020 13:04:58 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:b09d:d9a:a398:471a? ([2620:10d:c091:480::1:2e4f]) by smtp.googlemail.com with ESMTPSA id 28sm746151qkr.96.2020.05.13.13.04.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 May 2020 13:04:56 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++] some cleanup patches Message-ID: <561d382b-868e-ba16-9325-5aeab26f0824@acm.org> Date: Wed, 13 May 2020 16:04:55 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" I've committed this set of minor cleanups from the modules branch. nathan 2020-05-13 Nathan Sidwell Formatting fixups & some simplifications. * pt.c (spec_hash_table): New typedef. (decl_specializations, type_specializations): Use it. (retrieve_specialization): Likewise. (register_specialization): Remove unnecessary casts. (push_template_decl_real): Reformat. (instantiate_class_template_1): Use more RAII. (make_argument_pack): Simplify. (instantiate_template_1): Use gcc_checking_assert for expensive asserts. (instantiate_decl): Likewise. (resolve_typename_type): Reformat comment. * semantics.c (struct deferred_access): Remove unnecessary GTY on member. (begin_class_definition): Fix formatting. diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index 7911293571e..ff15a926db9 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -48,9 +48,9 @@ along with GCC; see the file COPYING3. If not see returning an int. */ typedef int (*tree_fn_t) (tree, void*); -/* The PENDING_TEMPLATES is a TREE_LIST of templates whose - instantiations have been deferred, either because their definitions - were not yet available, or because we were putting off doing the work. */ +/* The PENDING_TEMPLATES is a list of templates whose instantiations + have been deferred, either because their definitions were not yet + available, or because we were putting off doing the work. */ struct GTY ((chain_next ("%h.next"))) pending_template { struct pending_template *next; @@ -116,9 +116,10 @@ struct spec_hasher : ggc_ptr_hash static bool equal (spec_entry *, spec_entry *); }; -static GTY (()) hash_table *decl_specializations; - -static GTY (()) hash_table *type_specializations; +/* The general template is not in these tables. */ +typedef hash_table spec_hash_table; +static GTY (()) spec_hash_table *decl_specializations; +static GTY (()) spec_hash_table *type_specializations; /* Contains canonical template parameter types. The vector is indexed by the TEMPLATE_TYPE_IDX of the template parameter. Each element is a @@ -1278,7 +1279,7 @@ retrieve_specialization (tree tmpl, tree args, hashval_t hash) { spec_entry *found; spec_entry elt; - hash_table *specializations; + spec_hash_table *specializations; elt.tmpl = tmpl; elt.args = args; @@ -1573,10 +1574,9 @@ register_specialization (tree spec, tree tmpl, tree args, bool is_friend, if (hash == 0) hash = spec_hasher::hash (&elt); - slot = - decl_specializations->find_slot_with_hash (&elt, hash, INSERT); + slot = decl_specializations->find_slot_with_hash (&elt, hash, INSERT); if (*slot) - fn = ((spec_entry *) *slot)->spec; + fn = (*slot)->spec; else fn = NULL_TREE; } @@ -4474,7 +4466,7 @@ reduce_template_parm_level (tree index, tree type, int levels, tree args, TEMPLATE_PARM_PARAMETER_PACK (tpi) = TEMPLATE_PARM_PARAMETER_PACK (index); - /* Template template parameters need this. */ + /* Template template parameters need this. */ tree inner = decl; if (TREE_CODE (decl) == TEMPLATE_DECL) { @@ -5705,8 +5697,7 @@ push_template_decl_real (tree decl, bool is_friend) template friend void A::f(); is not primary. */ is_primary = false; - else if (TREE_CODE (decl) == TYPE_DECL - && LAMBDA_TYPE_P (TREE_TYPE (decl))) + else if (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (TREE_TYPE (decl))) is_primary = false; else is_primary = template_parm_scope_p (); @@ -5845,8 +5836,7 @@ push_template_decl_real (tree decl, bool is_friend) if (!ctx || TREE_CODE (ctx) == FUNCTION_DECL || (CLASS_TYPE_P (ctx) && TYPE_BEING_DEFINED (ctx)) - || (TREE_CODE (decl) == TYPE_DECL - && LAMBDA_TYPE_P (TREE_TYPE (decl))) + || (TREE_CODE (decl) == TYPE_DECL && LAMBDA_TYPE_P (TREE_TYPE (decl))) || (is_friend && !DECL_TEMPLATE_INFO (decl))) { if (DECL_LANG_SPECIFIC (decl) @@ -11752,13 +11743,10 @@ instantiate_class_template_1 (tree type) continue; /* Build new CLASSTYPE_NESTED_UTDS. */ + bool class_template_p = (TREE_CODE (t) != ENUMERAL_TYPE + && TYPE_LANG_SPECIFIC (t) + && CLASSTYPE_IS_TEMPLATE (t)); - tree newtag; - bool class_template_p; - - class_template_p = (TREE_CODE (t) != ENUMERAL_TYPE - && TYPE_LANG_SPECIFIC (t) - && CLASSTYPE_IS_TEMPLATE (t)); /* If the member is a class template, then -- even after substitution -- there may be dependent types in the template argument list for the class. We increment @@ -11767,7 +11755,7 @@ instantiate_class_template_1 (tree type) when outside of a template. */ if (class_template_p) ++processing_template_decl; - newtag = tsubst (t, args, tf_error, NULL_TREE); + tree newtag = tsubst (t, args, tf_error, NULL_TREE); if (class_template_p) --processing_template_decl; if (newtag == error_mark_node) @@ -11834,6 +11822,7 @@ instantiate_class_template_1 (tree type) tree vec = NULL_TREE; int len = 1; + gcc_checking_assert (TREE_CODE (t) != CONST_DECL); /* The file and line for this declaration, to assist in error message reporting. Since we called push_tinst_level above, we don't need to @@ -13067,8 +13056,8 @@ static tree make_argument_pack (tree vec) { tree pack; - tree elt = TREE_VEC_ELT (vec, 0); - if (TYPE_P (elt)) + + if (TYPE_P (TREE_VEC_ELT (vec, 0))) pack = cxx_make_type (TYPE_ARGUMENT_PACK); else { @@ -20714,10 +20703,11 @@ instantiate_template_1 (tree tmpl, tree orig_args, tsubst_flags_t complain) but it doesn't seem to be on the hot path. */ spec = retrieve_specialization (gen_tmpl, targ_ptr, 0); - gcc_assert (tmpl == gen_tmpl - || ((fndecl = retrieve_specialization (tmpl, orig_args, 0)) - == spec) - || fndecl == NULL_TREE); + gcc_checking_assert (tmpl == gen_tmpl + || ((fndecl + = retrieve_specialization (tmpl, orig_args, 0)) + == spec) + || fndecl == NULL_TREE); if (spec != NULL_TREE) { @@ -22794,7 +22784,7 @@ unify_pack_expansion (tree tparms, tree targs, tree packed_parms, TREE_CONSTANT (result) = 1; } else - result = cxx_make_type (TYPE_ARGUMENT_PACK); + result = cxx_make_type (TYPE_ARGUMENT_PACK); SET_ARGUMENT_PACK_ARGS (result, new_args); @@ -25422,13 +25412,14 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p) gen_tmpl = most_general_template (tmpl); gen_args = DECL_TI_ARGS (d); - if (tmpl != gen_tmpl) - /* We should already have the extra args. */ - gcc_assert (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (gen_tmpl)) - == TMPL_ARGS_DEPTH (gen_args)); + /* We should already have the extra args. */ + gcc_checking_assert (tmpl == gen_tmpl + || (TMPL_PARMS_DEPTH (DECL_TEMPLATE_PARMS (gen_tmpl)) + == TMPL_ARGS_DEPTH (gen_args))); /* And what's in the hash table should match D. */ - gcc_assert ((spec = retrieve_specialization (gen_tmpl, gen_args, 0)) == d - || spec == NULL_TREE); + gcc_checking_assert ((spec = retrieve_specialization (gen_tmpl, gen_args, 0)) + == d + || spec == NULL_TREE); /* This needs to happen before any tsubsting. */ if (! push_tinst_level (d)) @@ -27462,12 +27453,12 @@ resolve_typename_type (tree type, bool only_current_p) gcc_checking_assert (uses_template_parms (scope)); /* Usually the non-qualified identifier of a TYPENAME_TYPE is - TYPE_IDENTIFIER (type). But when 'type' is a typedef variant of - a TYPENAME_TYPE node, then TYPE_NAME (type) is set to the TYPE_DECL representing - the typedef. In that case TYPE_IDENTIFIER (type) is not the non-qualified - identifier of the TYPENAME_TYPE anymore. - So by getting the TYPE_IDENTIFIER of the _main declaration_ of the - TYPENAME_TYPE instead, we avoid messing up with a possible + TYPE_IDENTIFIER (type). But when 'type' is a typedef variant of a + TYPENAME_TYPE node, then TYPE_NAME (type) is set to the TYPE_DECL + representing the typedef. In that case TYPE_IDENTIFIER (type) is + not the non-qualified identifier of the TYPENAME_TYPE anymore. + So by getting the TYPE_IDENTIFIER of the _main declaration_ of + the TYPENAME_TYPE instead, we avoid messing up with a possible typedef variant case. */ name = TYPE_IDENTIFIER (TYPE_MAIN_VARIANT (type)); @@ -27816,7 +27807,7 @@ finish_concept_definition (cp_expr id, tree init) return error_mark_node; } - /* Initially build the concept declaration; it's type is bool. */ + /* Initially build the concept declaration; its type is bool. */ tree decl = build_lang_decl_loc (loc, CONCEPT_DECL, *id, boolean_type_node); DECL_CONTEXT (decl) = current_scope (); DECL_INITIAL (decl) = init; diff --git i/gcc/cp/semantics.c w/gcc/cp/semantics.c index 4d1592ab0d2..d90816eabc9 100644 --- i/gcc/cp/semantics.c +++ w/gcc/cp/semantics.c @@ -127,11 +127,10 @@ struct GTY(()) deferred_access { A::B* A::f() { return 0; } is valid, even though `A::B' is not generally accessible. */ - vec * GTY(()) deferred_access_checks; + vec *deferred_access_checks; /* The current mode of access checks. */ enum deferring_kind deferring_access_checks_kind; - }; /* Data for deferred access checking. */ @@ -3216,7 +3215,7 @@ begin_class_definition (tree t) SET_CLASSTYPE_INTERFACE_UNKNOWN_X (t, finfo->interface_unknown); } - reset_specialization(); + reset_specialization (); /* Make a declaration for this class in its own scope. */ build_self_reference ();