From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73442 invoked by alias); 8 May 2017 17:57:11 -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 73398 invoked by uid 89); 8 May 2017 17:57:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-yw0-f171.google.com Received: from mail-yw0-f171.google.com (HELO mail-yw0-f171.google.com) (209.85.161.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 08 May 2017 17:57:09 +0000 Received: by mail-yw0-f171.google.com with SMTP id 203so33237734ywe.0 for ; Mon, 08 May 2017 10:57:11 -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=Ht6GsG4JzrRh5NEesbNhLLBs5TCD0XJVda1p2yp4G6M=; b=ALZgDL0xViqQ23ctX3JGW0T2J1Zpq+ndYJhC9crEatJ+GIsT/F/v/c4nSQOdt7XRxp nRZ5DQZLdZakq8N/5BNuO+K9dbLYWqzeLrOrAv/CIYqsbBB7x6eOlDS7sprWYfS7UAlq CtfAMOsJ37hzB9S2QtJwbOqvRkTa02RU/yECSh/F4vOHJvYRpVxTCM/yen/BcFU0zT5l HF6m2T9Sgs7JJ8MEtu2GiQIHcBaGJD5VtECVP7s3XCtipkxL8PqiaLZv1E7wEh67Oid2 3GHc1pNJGn7/2J5HAG35/YSyGYgf5bLdmKjRYEk29pLT1IYyzpVDXz1hD/1gr7lrJqVy 3fdw== X-Gm-Message-State: AODbwcBk+jgiQ2NjbaJor215aHOLgs79VIFYgznq2/Hr3s9Nwq9lJlY/ z20IJ9VVKRv3Hg== X-Received: by 10.13.202.87 with SMTP id m84mr8861409ywd.282.1494266230197; Mon, 08 May 2017 10:57:10 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::2:16e0]) by smtp.googlemail.com with ESMTPSA id u70sm586664ywe.60.2017.05.08.10.57.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 May 2017 10:57:09 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] pushdecl Message-ID: <7dfbb0e2-965e-738c-9b51-9101de018094@acm.org> Date: Mon, 08 May 2017 18:02:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------7BC1DD9D488EDC15B2D1CC9D" X-SW-Source: 2017-05/txt/msg00579.txt.bz2 This is a multi-part message in MIME format. --------------7BC1DD9D488EDC15B2D1CC9D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 366 This small patch replaces pushdecl_with_scope with a more-specific pushdecl_outermost_localscope. It's used in 2 places to inject an artifical decl into the outermost block scope of a function (__FUNCTION__ var and lambda capture proxies). This moves some binding-level handling into name-lookup, where it belongs. Applied to trunk. nathan -- Nathan Sidwell --------------7BC1DD9D488EDC15B2D1CC9D Content-Type: text/x-patch; name="scpe.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="scpe.diff" Content-length: 4626 2017-05-08 Nathan Sidwell * name-lookup.h (pushdecl_with_scope): Replace with ... (pushdecl_outermost_localscope): ... this. * name-lookup.c (pushdecl_with_scope): Replace with ... (pushdecl_outermost_localscope): ... this. (pushdecl_namespace_level): Adjust. * decl.c (cp_make_fname_decl): Use pushdecl_outermost_localscope. * lambda.c (insert_capture_proxy): Likewise. Index: decl.c =================================================================== --- decl.c (revision 247751) +++ decl.c (working copy) @@ -4335,9 +4335,6 @@ cp_make_fname_decl (location_t loc, tree if (name) free (CONST_CAST (char *, name)); - /* As we're using pushdecl_with_scope, we must set the context. */ - DECL_CONTEXT (decl) = current_function_decl; - TREE_STATIC (decl) = 1; TREE_READONLY (decl) = 1; DECL_ARTIFICIAL (decl) = 1; @@ -4346,12 +4343,8 @@ cp_make_fname_decl (location_t loc, tree if (current_function_decl) { - cp_binding_level *b = current_binding_level; - if (b->kind == sk_function_parms) - return error_mark_node; - while (b->level_chain->kind != sk_function_parms) - b = b->level_chain; - pushdecl_with_scope (decl, b, /*is_friend=*/false); + DECL_CONTEXT (decl) = current_function_decl; + decl = pushdecl_outermost_localscope (decl); cp_finish_decl (decl, init, /*init_const_expr_p=*/false, NULL_TREE, LOOKUP_ONLYCONVERTING); } Index: lambda.c =================================================================== --- lambda.c (revision 247751) +++ lambda.c (working copy) @@ -295,24 +295,13 @@ is_normal_capture_proxy (tree decl) void insert_capture_proxy (tree var) { - cp_binding_level *b; - tree stmt_list; - /* Put the capture proxy in the extra body block so that it won't clash with a later local variable. */ - b = current_binding_level; - for (;;) - { - cp_binding_level *n = b->level_chain; - if (n->kind == sk_function_parms) - break; - b = n; - } - pushdecl_with_scope (var, b, false); + pushdecl_outermost_localscope (var); /* And put a DECL_EXPR in the STATEMENT_LIST for the same block. */ var = build_stmt (DECL_SOURCE_LOCATION (var), DECL_EXPR, var); - stmt_list = (*stmt_list_stack)[1]; + tree stmt_list = (*stmt_list_stack)[1]; gcc_assert (stmt_list); append_to_statement_list_force (var, &stmt_list); } Index: name-lookup.c =================================================================== --- name-lookup.c (revision 247751) +++ name-lookup.c (working copy) @@ -2870,14 +2870,23 @@ pushdecl_with_scope_1 (tree x, cp_bindin return x; } -/* Wrapper for pushdecl_with_scope_1. */ +/* Inject X into the local scope just before the function parms. */ tree -pushdecl_with_scope (tree x, cp_binding_level *level, bool is_friend) +pushdecl_outermost_localscope (tree x) { - tree ret; bool subtime = timevar_cond_start (TV_NAME_LOOKUP); - ret = pushdecl_with_scope_1 (x, level, is_friend); + cp_binding_level *b = NULL, *n = current_binding_level; + + if (n->kind == sk_function_parms) + return error_mark_node; + do + { + b = n; + n = b->level_chain; + } + while (n->kind != sk_function_parms); + tree ret = pushdecl_with_scope_1 (x, b, false); timevar_cond_stop (TV_NAME_LOOKUP, subtime); return ret; } @@ -4350,7 +4359,8 @@ pushdecl_namespace_level (tree x, bool i tree t; bool subtime = timevar_cond_start (TV_NAME_LOOKUP); - t = pushdecl_with_scope (x, NAMESPACE_LEVEL (current_namespace), is_friend); + t = pushdecl_with_scope_1 + (x, NAMESPACE_LEVEL (current_namespace), is_friend); /* Now, the type_shadowed stack may screw us. Munge it so it does what we want. */ Index: name-lookup.h =================================================================== --- name-lookup.h (revision 247751) +++ name-lookup.h (working copy) @@ -300,6 +300,7 @@ extern tree push_inner_scope (tree); extern void pop_inner_scope (tree, tree); extern void push_binding_level (cp_binding_level *); +extern tree pushdecl_outermost_localscope (tree); extern bool push_namespace (tree); extern void pop_namespace (void); extern void push_nested_namespace (tree); @@ -307,7 +308,6 @@ extern void pop_nested_namespace (tree); extern bool handle_namespace_attrs (tree, tree); extern void pushlevel_class (void); extern void poplevel_class (void); -extern tree pushdecl_with_scope (tree, cp_binding_level *, bool); extern tree lookup_name_prefer_type (tree, int); extern tree lookup_name_real (tree, int, int, bool, int, int); extern tree lookup_type_scope (tree, tag_scope); --------------7BC1DD9D488EDC15B2D1CC9D--