From patchwork Thu May 4 15:41:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 758688 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 3wJfQZ2jbhz9s2Q for ; Fri, 5 May 2017 01:41:39 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="FYQ1FYll"; 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=SQvJMdCmLRL1e8xmsuic/KQBLUFnJxb4pq6VstmixfkX9OmHCd UoiAoV5DqO8e+BMakUvbGFgpKHkk2QItE9ZdmnRS2s7UdTMHQFwiCHOhg6q0D5+E r42NIXrtsTVn9H/5lE8v2MP/PYtZZWrB97TsroeXLrASWxj+rAQYcfJOY= 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=Xg63SNCEy+ypKBsOtRSHscFFGR4=; b=FYQ1FYllHV3KV0+TlnmW FR7VlPAbIKsOg1MJ11W2E1u++SyU+hUkYPvBJrcHmGLDEjfNyMn2RvAbWu83qEV+ Q0h3npOpaGJBqeUNQKFdQYmSK0h+OXnMubpd4eJBZhD3FgHLQq6rLqUkEN2rAx8j FCBB+nabcIQdaPprRovejSQ= Received: (qmail 103190 invoked by alias); 4 May 2017 15:41:27 -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 103168 invoked by uid 89); 4 May 2017 15:41:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, 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-f173.google.com Received: from mail-yw0-f173.google.com (HELO mail-yw0-f173.google.com) (209.85.161.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 04 May 2017 15:41:24 +0000 Received: by mail-yw0-f173.google.com with SMTP id 203so8532532ywe.0 for ; Thu, 04 May 2017 08:41:26 -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=vZZXW1hqcOdcsd0RUtqSUhVDHIw0eIGoX1SMT305DIU=; b=INlgwsMdUnOTk7fwkHHQn5EIEqPLScs/hAHfliuI3pZG56/ADpSzIbr5x78hha5zYF u1uKUrIAXer0r3E78BxpjLYeg7jmvR9xluIkjU59QHbbdPFtttK+g3jQH3meZrH3YaZ+ HPcPUTLxFs/1FRB40NWBs8a2Fih8czqxHtk7JQyw3JqcaI6urKtdRGvhQV2hnGGOTdNA K7NAdwguy4lesmXLcWFglXxQX6+WdQKnE3eo6lChkDRV9SOzQ7Z9li+QV0LwQrV7+Dg+ yRVFB5U7v2Ghld3cyjSg0ru4bNHLCiv+WKge2ayka5Ev9xUkuqEHnYe+5KmFyBaH1Igt n7qg== X-Gm-Message-State: AN3rC/6Yq7oLN2oAk2LBGy/4MD8dCeW2S4c7XTHDd4WlPuMTaXlwZlSy /T/JECjHaWg22g== X-Received: by 10.129.109.147 with SMTP id i141mr34072974ywc.228.1493912484771; Thu, 04 May 2017 08:41:24 -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 f130sm1184484ywc.41.2017.05.04.08.41.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 04 May 2017 08:41:23 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH[ global trees Message-ID: Date: Thu, 4 May 2017 11:41:22 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.0 MIME-Version: 1.0 This patch moves more things into the cp_global_trees array. 1) a set of identifiers, in particular initializer_list is no longer checked by strcmp or multiple get_identifier calls. 2) The anonymous namespace identifier 3) The global namespace and its name. committed to trunk. nathan 2017-05-04 Nathan Sidwell More global trees. * cp-tree.h (enum cp_tree_index): Add CPTI_GLOBAL, CPTI_GLOBAL_TYPE, CPTI_GLOBAL_IDENTIFIER, CPTI_ANON_IDENTIFIER, CPTI_INIT_LIST_IDENTIFIER. (global_namespace, global_type_node, global_identifier, anon_identifier, init_list_identifier): New. * decl.c (global_type_node, global_scope_name): Delete. (initialize_predefined_identifiers): Add new identifiers. (cxx_init_decl_processing): Adjust. * name-lookup.h (global_namespace, global_type_node): Delete. * name-lookup.c (global_namespace, anonymous_namespace_name, get_anonymous_namespace_name): Delete. (namespace_scope_ht_size, begin_scope, pushtag_1, push_namespace): Adjust, * call.c (type_has_extended_temps): Use init_list_identifier. * pt.c (listify): Likewise. Index: cp/call.c =================================================================== --- cp/call.c (revision 247591) +++ cp/call.c (working copy) @@ -10543,15 +10543,15 @@ type_has_extended_temps (tree type) bool is_std_init_list (tree type) { - /* Look through typedefs. */ if (!TYPE_P (type)) return false; if (cxx_dialect == cxx98) return false; + /* Look through typedefs. */ type = TYPE_MAIN_VARIANT (type); return (CLASS_TYPE_P (type) && CP_TYPE_CONTEXT (type) == std_node - && strcmp (TYPE_NAME_STRING (type), "initializer_list") == 0); + && init_list_identifier == DECL_NAME (TYPE_NAME (type))); } /* Returns true iff DECL is a list constructor: i.e. a constructor which Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 247591) +++ cp/cp-tree.h (working copy) @@ -119,6 +119,8 @@ enum cp_tree_index CPTI_VTBL_PTR_TYPE, CPTI_STD, CPTI_ABI, + CPTI_GLOBAL, + CPTI_GLOBAL_TYPE, CPTI_CONST_TYPE_INFO_TYPE, CPTI_TYPE_INFO_PTR_TYPE, CPTI_ABORT_FNDECL, @@ -138,9 +140,12 @@ enum cp_tree_index CPTI_THIS_IDENTIFIER, CPTI_PFN_IDENTIFIER, CPTI_VPTR_IDENTIFIER, + CPTI_GLOBAL_IDENTIFIER, CPTI_STD_IDENTIFIER, + CPTI_ANON_IDENTIFIER, CPTI_AUTO_IDENTIFIER, CPTI_DECLTYPE_AUTO_IDENTIFIER, + CPTI_INIT_LIST_IDENTIFIER, CPTI_LANG_NAME_C, CPTI_LANG_NAME_CPLUSPLUS, @@ -184,6 +189,8 @@ extern GTY(()) tree cp_global_trees[CPTI #define vtbl_ptr_type_node cp_global_trees[CPTI_VTBL_PTR_TYPE] #define std_node cp_global_trees[CPTI_STD] #define abi_node cp_global_trees[CPTI_ABI] +#define global_namespace cp_global_trees[CPTI_GLOBAL] +#define global_type_node cp_global_trees[CPTI_GLOBAL_TYPE] #define const_type_info_type_node cp_global_trees[CPTI_CONST_TYPE_INFO_TYPE] #define type_info_ptr_type cp_global_trees[CPTI_TYPE_INFO_PTR_TYPE] #define abort_fndecl cp_global_trees[CPTI_ABORT_FNDECL] @@ -224,12 +231,14 @@ extern GTY(()) tree cp_global_trees[CPTI #define this_identifier cp_global_trees[CPTI_THIS_IDENTIFIER] #define pfn_identifier cp_global_trees[CPTI_PFN_IDENTIFIER] #define vptr_identifier cp_global_trees[CPTI_VPTR_IDENTIFIER] -/* The name of the std namespace. */ +/* The name of the ::, std & anon namespaces. */ +#define global_identifier cp_global_trees[CPTI_GLOBAL_IDENTIFIER] #define std_identifier cp_global_trees[CPTI_STD_IDENTIFIER] +#define anon_identifier cp_global_trees[CPTI_ANON_IDENTIFIER] /* auto and declspec(auto) identifiers. */ #define auto_identifier cp_global_trees[CPTI_AUTO_IDENTIFIER] #define decltype_auto_identifier cp_global_trees[CPTI_DECLTYPE_AUTO_IDENTIFIER] -/* The name of a C++17 deduction guide. */ +#define init_list_identifier cp_global_trees[CPTI_INIT_LIST_IDENTIFIER] #define lang_name_c cp_global_trees[CPTI_LANG_NAME_C] #define lang_name_cplusplus cp_global_trees[CPTI_LANG_NAME_CPLUSPLUS] @@ -277,6 +286,7 @@ extern GTY(()) tree cp_global_trees[CPTI access nodes in tree.h. */ #define access_default_node null_node + #include "name-lookup.h" Index: cp/decl.c =================================================================== --- cp/decl.c (revision 247591) +++ cp/decl.c (working copy) @@ -140,14 +140,6 @@ static void expand_static_init (tree, tr tree cp_global_trees[CPTI_MAX]; -/* Indicates that there is a type value in some namespace, although - that is not necessarily in scope at the moment. */ - -tree global_type_node; - -/* The node that holds the "name" of the global scope. */ -tree global_scope_name; - #define local_names cp_function_chain->x_local_names /* A list of objects which have constructors or destructors @@ -3935,7 +3927,7 @@ make_unbound_class_template (tree contex -/* Push the declarations of builtin types into the namespace. +/* Push the declarations of builtin types into the global namespace. RID_INDEX is the index of the builtin type in the array RID_POINTERS. NAME is the name used when looking up the builtin type. TYPE is the _TYPE node for the builtin type. */ @@ -4037,10 +4029,15 @@ initialize_predefined_identifiers (void) { VTABLE_PFN_NAME, &pfn_identifier, 0 }, { "_vptr", &vptr_identifier, 0 }, { "__vtt_parm", &vtt_parm_identifier, 0 }, - { "::", &global_scope_name, 0 }, + { "::", &global_identifier, 0 }, { "std", &std_identifier, 0 }, + /* The demangler expects anonymous namespaces to be called + something starting with '_GLOBAL__N_'. It no longer needs + to be unique to the TU. */ + { "_GLOBAL__N_1", &anon_identifier, 0 }, { "auto", &auto_identifier, 0 }, { "decltype(auto)", &decltype_auto_identifier, 0 }, + { "initializer_list", &init_list_identifier, 0 }, { NULL, NULL, 0 } }; @@ -4073,14 +4070,15 @@ cxx_init_decl_processing (void) current_binding_level = NULL; /* Enter the global namespace. */ gcc_assert (global_namespace == NULL_TREE); - global_namespace = build_lang_decl (NAMESPACE_DECL, global_scope_name, + global_namespace = build_lang_decl (NAMESPACE_DECL, global_identifier, void_type_node); + TREE_PUBLIC (global_namespace) = 1; DECL_CONTEXT (global_namespace) = build_translation_unit_decl (get_identifier (main_input_filename)); debug_hooks->register_main_translation_unit (DECL_CONTEXT (global_namespace)); - TREE_PUBLIC (global_namespace) = 1; begin_scope (sk_namespace, global_namespace); + current_namespace = global_namespace; if (flag_visibility_ms_compat) default_visibility = VISIBILITY_HIDDEN; Index: cp/name-lookup.c =================================================================== --- cp/name-lookup.c (revision 247592) +++ cp/name-lookup.c (working copy) @@ -61,14 +61,6 @@ static tree push_using_directive (tree); static tree lookup_extern_c_fun_in_all_ns (tree); static void diagnose_name_conflict (tree, tree); -/* The :: namespace. */ - -tree global_namespace; - -/* The name of the anonymous namespace, throughout this translation - unit. */ -static GTY(()) tree anonymous_namespace_name; - /* Add DECL to the list of things declared in B. */ static void @@ -644,23 +636,6 @@ lookup_arg_dependent (tree name, tree fn return ret; } -/* Initialize anonymous_namespace_name if necessary, and return it. */ - -static tree -get_anonymous_namespace_name (void) -{ - if (!anonymous_namespace_name) - { - /* We used to use get_file_function_name here, but that isn't - necessary now that anonymous namespace typeinfos - are !TREE_PUBLIC, and thus compared by address. */ - /* The demangler expects anonymous namespaces to be called - something starting with '_GLOBAL__N_'. */ - anonymous_namespace_name = get_identifier ("_GLOBAL__N_1"); - } - return anonymous_namespace_name; -} - /* Compute the chain index of a binding_entry given the HASH value of its name and the total COUNT of chains. COUNT is assumed to be a power of 2. */ @@ -2111,7 +2086,7 @@ namespace_scope_ht_size (tree ns) return name == std_identifier ? NAMESPACE_STD_HT_SIZE - : (name == global_scope_name + : (name == global_identifier ? GLOBAL_SCOPE_HT_SIZE : NAMESPACE_ORDINARY_HT_SIZE); } @@ -2189,7 +2164,7 @@ begin_scope (scope_kind kind, tree entit NAMESPACE_LEVEL (entity) = scope; vec_alloc (scope->static_decls, (DECL_NAME (entity) == std_identifier - || DECL_NAME (entity) == global_scope_name) ? 200 : 10); + || DECL_NAME (entity) == global_identifier) ? 200 : 10); break; default: @@ -6167,7 +6142,7 @@ pushtag_1 (tree name, tree type, tag_sco return decl; if (DECL_CONTEXT (decl) == std_node - && strcmp (TYPE_NAME_STRING (type), "initializer_list") == 0 + && init_list_identifier == DECL_NAME (TYPE_NAME (type)) && !CLASSTYPE_TEMPLATE_INFO (type)) { error ("declaration of std::initializer_list does not match " @@ -6489,11 +6464,11 @@ push_namespace (tree name) /* We should not get here if the global_namespace is not yet constructed nor if NAME designates the global namespace: The global scope is constructed elsewhere. */ - gcc_assert (global_namespace != NULL && name != global_scope_name); + gcc_assert (global_namespace != NULL && name != global_identifier); if (anon) { - name = get_anonymous_namespace_name(); + name = anon_identifier; d = IDENTIFIER_NAMESPACE_VALUE (name); if (d) /* Reopening anonymous namespace. */ Index: cp/name-lookup.h =================================================================== --- cp/name-lookup.h (revision 247591) +++ cp/name-lookup.h (working copy) @@ -278,15 +278,6 @@ struct GTY(()) cp_binding_level { #define class_binding_level scope_chain->class_bindings -/* The tree node representing the global scope. */ -extern GTY(()) tree global_namespace; -extern GTY(()) tree global_scope_name; - -/* Indicates that there is a type value in some namespace, although - that is not necessarily in scope at the moment. */ - -extern GTY(()) tree global_type_node; - /* True if SCOPE designates the global scope binding contour. */ #define global_scope_p(SCOPE) \ ((SCOPE) == NAMESPACE_LEVEL (global_namespace)) Index: cp/pt.c =================================================================== --- cp/pt.c (revision 247591) +++ cp/pt.c (working copy) @@ -24730,8 +24730,7 @@ make_constrained_auto (tree con, tree ar static tree listify (tree arg) { - tree std_init_list = namespace_binding - (get_identifier ("initializer_list"), std_node); + tree std_init_list = namespace_binding (init_list_identifier, std_node); tree argvec; if (!std_init_list || !DECL_CLASS_TEMPLATE_P (std_init_list)) {