From patchwork Fri Jun 16 15:45:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 776812 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wq4Tl0nSKz9s5L for ; Sat, 17 Jun 2017 01:46:01 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="IncrXxi/"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Ebx2oyjGgtiUkRdA5/BXAURLDPlLq2uFqKLs57+hvS5eUeT2eA ChX96JDf+Q7yTKVequX2CUoOva3FakRZa5/dt/C5S3LLiLTpZp6L2NcIilBxXvT4 oc4oo0+lLC2yWnAxMjXjf5a48DjCxY5vB34s+VMf9GVHYswh152jfpsHo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=xxr+Bgj5k3GOTYPU/UlFujXAxww=; b=IncrXxi/Y4u1c/9NbrEr cK44FAwOzdgJo03xcm7qMAAY9drxlphk206NRLsqIICM74cC7BDkUaCFQWFNvatb HGD0Bf77WbCt29E6OXMOrw6wKJMA+UxEt1XQTjapwWNEu4SWlE2QXn8HNwuG6Xsn wIYpXpz0QjUeFvzjVAu3P1c= Received: (qmail 31420 invoked by alias); 16 Jun 2017 15:45:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 31105 invoked by uid 89); 16 Jun 2017 15:45:05 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=parm X-HELO: mail-yb0-f170.google.com Received: from mail-yb0-f170.google.com (HELO mail-yb0-f170.google.com) (209.85.213.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Jun 2017 15:45:03 +0000 Received: by mail-yb0-f170.google.com with SMTP id 84so13590097ybe.0 for ; Fri, 16 Jun 2017 08:45:07 -0700 (PDT) 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=jcWu7GMjxL0RWGb5qmuZytUXvQi8zJFSTBCrWSRSZ+c=; b=SWSTFw3ph1kMTtGQzLtkKwcOgkQVoxbh/NMNa3FtbyABObkhYpbAULYl7mcWkK3ZWA 1d9lmwA0OV/q0VXPyKGey1oW0b8hzsyOwpDRX9rpyksLkDSh2tn2uk6gC0Bs+Mbez6VD 2jnNRtM8V5PgFiGoWljmxhN6sUm2Nu6JtWP2BIv0eImyYuUKvP09LUHnZgreaVdyRhID vItjCzxXeW/YISlcK3B3Xk1g3zfOyaUp8G641xULIy1MH8N35Ls3O9SC5GDDlaGYxPrs 6eRsZm23OiDUgcPiA7TdQlB336xdzNol64t9aphK1R1O9VplR1ptS4cJk7A+bnlbrokK 8jkQ== X-Gm-Message-State: AKS2vOzP9drSMJhABEQdV2K7Kqe4wcD2eEvSWwMML40wvENmS5d6TP+q pybvciBK4vJcHpvZ X-Received: by 10.37.161.6 with SMTP id z6mr9841095ybh.106.1497627906305; Fri, 16 Jun 2017 08:45:06 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::144]) by smtp.googlemail.com with ESMTPSA id k28sm1085014ywh.57.2017.06.16.08.45.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Jun 2017 08:45:05 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] PARM context Message-ID: Date: Fri, 16 Jun 2017 11:45:04 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 We weren't always setting DECL_CONTEXT for parm decls. Which caused me some issues in the modules branch. Fixed by making the callers of the parm-decl builders pass in the function decl. I suspect the places in grokdecl dealing with declaring via typedef (where I pass NULL) will need addressing later on, but this seems a useful cleanup. Applied to trunk. nathan 2017-06-16 Nathan Sidwell gcc/cp/ * cp-tree.h (build_this_parm, cp_build_parm_decl, build_artificial_parm): Add FN parm. * decl.c (start_cleanup_fn): Adjust. (build_this_parm): Add FN parm, pass it through. (grokfndecl): Adjust parm building. * decl2.c (cp_build_parm_decl): Add FN parm, set context. (build_artificial_parm): Add FN parm, pass through. (maybe_retrofit_in_chrg): Adjust parm building. (start_static_storage_duration_function): Likwise. * lambda.c (maybe_aadd_lambda_conv_op): Likewise. * method.c (implicitly_declare_fn): Likewise. * parser.c (inject_this_parameter): Likewise. libcc1/ * libcp1plugin.cc (plugin_build_decl): Adjust parm building. Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 249266) +++ gcc/cp/cp-tree.h (working copy) @@ -6078,7 +6078,7 @@ extern int cp_complete_array_type_or_err extern tree build_ptrmemfunc_type (tree); extern tree build_ptrmem_type (tree, tree); /* the grokdeclarator prototype is in decl.h */ -extern tree build_this_parm (tree, cp_cv_quals); +extern tree build_this_parm (tree, tree, cp_cv_quals); extern tree grokparms (tree, tree *); extern int copy_fn_p (const_tree); extern bool move_fn_p (const_tree); @@ -6179,7 +6179,7 @@ extern void check_default_args (tree); extern bool mark_used (tree); extern bool mark_used (tree, tsubst_flags_t); extern void finish_static_data_member_decl (tree, tree, bool, tree, int); -extern tree cp_build_parm_decl (tree, tree); +extern tree cp_build_parm_decl (tree, tree, tree); extern tree get_guard (tree); extern tree get_guard_cond (tree, bool); extern tree set_guard (tree); @@ -6188,7 +6188,7 @@ extern void mark_needed (tree); extern bool decl_needed_p (tree); extern void note_vague_linkage_fn (tree); extern void note_variable_template_instantiation (tree); -extern tree build_artificial_parm (tree, tree); +extern tree build_artificial_parm (tree, tree, tree); extern bool possibly_inlined_p (tree); extern int parm_index (tree); extern tree vtv_start_verification_constructor_init_function (void); Index: gcc/cp/decl.c =================================================================== --- gcc/cp/decl.c (revision 249264) +++ gcc/cp/decl.c (working copy) @@ -7823,10 +7823,7 @@ start_cleanup_fn (void) /* Build the parameter. */ if (use_cxa_atexit) { - tree parmdecl; - - parmdecl = cp_build_parm_decl (NULL_TREE, ptr_type_node); - DECL_CONTEXT (parmdecl) = fndecl; + tree parmdecl = cp_build_parm_decl (fndecl, NULL_TREE, ptr_type_node); TREE_USED (parmdecl) = 1; DECL_READ_P (parmdecl) = 1; DECL_ARGUMENTS (fndecl) = parmdecl; @@ -8367,12 +8364,12 @@ check_class_member_definition_namespace decl, DECL_CONTEXT (decl)); } -/* Build a PARM_DECL for the "this" parameter. TYPE is the +/* Build a PARM_DECL for the "this" parameter of FN. TYPE is the METHOD_TYPE for a non-static member function; QUALS are the cv-qualifiers that apply to the function. */ tree -build_this_parm (tree type, cp_cv_quals quals) +build_this_parm (tree fn, tree type, cp_cv_quals quals) { tree this_type; tree qual_type; @@ -8391,7 +8388,7 @@ build_this_parm (tree type, cp_cv_quals assigned to. */ this_quals = (quals & TYPE_QUAL_RESTRICT) | TYPE_QUAL_CONST; qual_type = cp_build_qualified_type (this_type, this_quals); - parm = build_artificial_parm (this_identifier, qual_type); + parm = build_artificial_parm (fn, this_identifier, qual_type); cp_apply_type_quals_to_decl (this_quals, parm); return parm; } @@ -8525,8 +8522,7 @@ grokfndecl (tree ctype, if (TREE_CODE (type) == METHOD_TYPE) { - tree parm; - parm = build_this_parm (type, quals); + tree parm = build_this_parm (decl, type, quals); DECL_CHAIN (parm) = parms; parms = parm; @@ -11625,7 +11621,8 @@ grokdeclarator (const cp_declarator *dec args && args != void_list_node; args = TREE_CHAIN (args)) { - tree decl = cp_build_parm_decl (NULL_TREE, TREE_VALUE (args)); + tree decl = cp_build_parm_decl (NULL_TREE, NULL_TREE, + TREE_VALUE (args)); DECL_CHAIN (decl) = decls; decls = decl; @@ -11794,7 +11791,7 @@ grokdeclarator (const cp_declarator *dec if (decl_context == PARM) { - decl = cp_build_parm_decl (unqualified_id, type); + decl = cp_build_parm_decl (NULL_TREE, unqualified_id, type); DECL_ARRAY_PARAMETER_P (decl) = array_parameter_p; bad_specifiers (decl, BSP_PARM, virtualp, Index: gcc/cp/decl2.c =================================================================== --- gcc/cp/decl2.c (revision 249263) +++ gcc/cp/decl2.c (working copy) @@ -192,14 +192,16 @@ change_return_type (tree new_ret, tree f return newtype; } -/* Build a PARM_DECL with NAME and TYPE, and set DECL_ARG_TYPE +/* Build a PARM_DECL of FN with NAME and TYPE, and set DECL_ARG_TYPE appropriately. */ tree -cp_build_parm_decl (tree name, tree type) +cp_build_parm_decl (tree fn, tree name, tree type) { tree parm = build_decl (input_location, PARM_DECL, name, type); + DECL_CONTEXT (parm) = fn; + /* DECL_ARG_TYPE is only used by the back end and the back end never sees templates. */ if (!processing_template_decl) @@ -208,13 +210,13 @@ cp_build_parm_decl (tree name, tree type return parm; } -/* Returns a PARM_DECL for a parameter of the indicated TYPE, with the +/* Returns a PARM_DECL of FN for a parameter of the indicated TYPE, with the indicated NAME. */ tree -build_artificial_parm (tree name, tree type) +build_artificial_parm (tree fn, tree name, tree type) { - tree parm = cp_build_parm_decl (name, type); + tree parm = cp_build_parm_decl (fn, name, type); DECL_ARTIFICIAL (parm) = 1; /* All our artificial parms are implicitly `const'; they cannot be assigned to. */ @@ -265,7 +267,7 @@ maybe_retrofit_in_chrg (tree fn) pass us a pointer to our VTT. */ if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn))) { - parm = build_artificial_parm (vtt_parm_identifier, vtt_parm_type); + parm = build_artificial_parm (fn, vtt_parm_identifier, vtt_parm_type); /* First add it to DECL_ARGUMENTS between 'this' and the real args... */ DECL_CHAIN (parm) = parms; @@ -278,7 +280,7 @@ maybe_retrofit_in_chrg (tree fn) } /* Then add the in-charge parm (before the VTT parm). */ - parm = build_artificial_parm (in_charge_identifier, integer_type_node); + parm = build_artificial_parm (fn, in_charge_identifier, integer_type_node); DECL_CHAIN (parm) = parms; parms = parm; arg_types = hash_tree_chain (integer_type_node, arg_types); @@ -3502,12 +3504,10 @@ start_static_storage_duration_function ( /* Create the argument list. */ initialize_p_decl = cp_build_parm_decl - (get_identifier (INITIALIZE_P_IDENTIFIER), integer_type_node); - DECL_CONTEXT (initialize_p_decl) = ssdf_decl; + (ssdf_decl, get_identifier (INITIALIZE_P_IDENTIFIER), integer_type_node); TREE_USED (initialize_p_decl) = 1; priority_decl = cp_build_parm_decl - (get_identifier (PRIORITY_IDENTIFIER), integer_type_node); - DECL_CONTEXT (priority_decl) = ssdf_decl; + (ssdf_decl, get_identifier (PRIORITY_IDENTIFIER), integer_type_node); TREE_USED (priority_decl) = 1; DECL_CHAIN (initialize_p_decl) = priority_decl; Index: gcc/cp/lambda.c =================================================================== --- gcc/cp/lambda.c (revision 249255) +++ gcc/cp/lambda.c (working copy) @@ -1102,7 +1102,8 @@ maybe_add_lambda_conv_op (tree type) DECL_ARTIFICIAL (fn) = 1; DECL_NOT_REALLY_EXTERN (fn) = 1; DECL_DECLARED_INLINE_P (fn) = 1; - DECL_ARGUMENTS (fn) = build_this_parm (fntype, TYPE_QUAL_CONST); + DECL_ARGUMENTS (fn) = build_this_parm (fn, fntype, TYPE_QUAL_CONST); + if (nested_def) DECL_INTERFACE_KNOWN (fn) = 1; Index: gcc/cp/method.c =================================================================== --- gcc/cp/method.c (revision 249264) +++ gcc/cp/method.c (working copy) @@ -2072,7 +2072,7 @@ implicitly_declare_fn (special_function_ /* Note that this parameter is *not* marked DECL_ARTIFICIAL; we want its type to be included in the mangled function name. */ - tree decl = cp_build_parm_decl (NULL_TREE, rhs_parm_type); + tree decl = cp_build_parm_decl (fn, NULL_TREE, rhs_parm_type); TREE_READONLY (decl) = 1; retrofit_lang_decl (decl); DECL_PARM_INDEX (decl) = DECL_PARM_LEVEL (decl) = 1; @@ -2085,11 +2085,10 @@ implicitly_declare_fn (special_function_ for (tree parm = inherited_parms; parm && parm != void_list_node; parm = TREE_CHAIN (parm)) { - *p = cp_build_parm_decl (NULL_TREE, TREE_VALUE (parm)); + *p = cp_build_parm_decl (fn, NULL_TREE, TREE_VALUE (parm)); retrofit_lang_decl (*p); DECL_PARM_LEVEL (*p) = 1; DECL_PARM_INDEX (*p) = index++; - DECL_CONTEXT (*p) = fn; p = &DECL_CHAIN (*p); } SET_DECL_INHERITED_CTOR (fn, inherited_ctor); @@ -2103,7 +2102,7 @@ implicitly_declare_fn (special_function_ constexpr_p = DECL_DECLARED_CONSTEXPR_P (inherited_ctor); } /* Add the "this" parameter. */ - this_parm = build_this_parm (fn_type, TYPE_UNQUALIFIED); + this_parm = build_this_parm (fn, fn_type, TYPE_UNQUALIFIED); DECL_CHAIN (this_parm) = DECL_ARGUMENTS (fn); DECL_ARGUMENTS (fn) = this_parm; Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 249255) +++ gcc/cp/parser.c (working copy) @@ -20451,7 +20451,7 @@ inject_this_parameter (tree ctype, cp_cv return; } - this_parm = build_this_parm (ctype, quals); + this_parm = build_this_parm (NULL_TREE, ctype, quals); /* Clear this first to avoid shortcut in cp_build_indirect_ref. */ current_class_ptr = NULL_TREE; current_class_ref Index: libcc1/libcp1plugin.cc =================================================================== --- libcc1/libcp1plugin.cc (revision 249255) +++ libcc1/libcp1plugin.cc (working copy) @@ -1366,7 +1366,7 @@ plugin_build_decl (cc1_plugin::connectio overloading. */ SET_DECL_LANGUAGE (decl, lang_cplusplus); if (TREE_CODE (sym_type) == METHOD_TYPE) - DECL_ARGUMENTS (decl) = build_this_parm (current_class_type, + DECL_ARGUMENTS (decl) = build_this_parm (decl, current_class_type, cp_type_quals (sym_type)); for (tree arg = TREE_CODE (sym_type) == METHOD_TYPE ? TREE_CHAIN (TYPE_ARG_TYPES (sym_type)) @@ -1374,7 +1374,7 @@ plugin_build_decl (cc1_plugin::connectio arg && arg != void_list_node; arg = TREE_CHAIN (arg)) { - tree parm = cp_build_parm_decl (NULL_TREE, TREE_VALUE (arg)); + tree parm = cp_build_parm_decl (decl, NULL_TREE, TREE_VALUE (arg)); DECL_CHAIN (parm) = DECL_ARGUMENTS (decl); DECL_ARGUMENTS (decl) = parm; }