From patchwork Wed Oct 4 17:52:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 821419 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-463476-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="o/B976Bd"; dkim-atps=neutral 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 3y6k5p4Y38z9sRq for ; Thu, 5 Oct 2017 04:53:11 +1100 (AEDT) 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=imSMT+MSUWY3oUh7RfT36DeEugE+wWfFBSSuHITFpfYvHqDTz2 zDrNnbRMO7V33XsAXVFxErABtAbm9yamVD1OPZYWkpkdW9s8hjRWYltuWf1CFxcc VrVKETiM4pfdbIPSHbric9Kfp8uiUsJfcUklA/GAXq0KkRrYc8yteylz4= 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=zC5RCQ6nWPVlUy1YDIni47KoctA=; b=o/B976BdjosHrQ9I6+oC lKpwOIkJb13OBZT3RNQAUNjThAx51j5q+LRt/ZfH7m4UeEaT4X9b6iDY+6fUYzOo udYv/4lYX31CuMh6/fWdEqY8+oAv7pw5bUHmWHp9o1MvpetiKXNv7Ec49Rdi9TjM wEgXpMBWsSgjcoCNVJSKpK0= Received: (qmail 120177 invoked by alias); 4 Oct 2017 17:53:00 -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 120156 invoked by uid 89); 4 Oct 2017 17:53:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-16.3 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=TYPE X-HELO: mail-qt0-f179.google.com Received: from mail-qt0-f179.google.com (HELO mail-qt0-f179.google.com) (209.85.216.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 04 Oct 2017 17:52:58 +0000 Received: by mail-qt0-f179.google.com with SMTP id i13so20749930qtc.11 for ; Wed, 04 Oct 2017 10:52:58 -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=bnneokv7sIPD0rTImSkkGp24jJgVZq7u0hIwT+vucb4=; b=AkY458X+fyZyP2A0s7LmOC3sDfI8Nh5pkASdJnuMS0qsl4C8CXzlKhkleRgYUTWkey gnyQIQLwTZ35GVuAaoSvyoYJ2FSsODm8ExXeXhxCZnq+It1q/18v7defDyjwrO4Xw9Co lLdIKwFJ4ebWWmWG4jIceKba82Y63IIRFJP8TLeHwpCJS2Q0innQLB9baMXkuG0WMGkm Bb56ODRmPTTjEk+70IBbnhOjJnB5y7CFJOnOyEYHcIG6lcNRsxaGFkwgtZvQqjCKu18q f7fZntfiF3/lLxyJn/Gj7zGB9SB8k2NVEXzCMbBBYtgezA4BADJBP4wMssMwNlRNWLl2 2OSw== X-Gm-Message-State: AHPjjUgH8A0UoAw0f1NJRP423lmEEDl/m3idu5ClcCLwkY8rigW/GI5n 2gzZSDKRTFVVzp9uUlSym+o= X-Google-Smtp-Source: AOwi7QD04f2hjCxRqehvRoT6CQWAqcAYSn8X4aWzHWrltdAQLMSx6gdGggAmaVuj5vAJQRF+tW5xjA== X-Received: by 10.129.130.134 with SMTP id s128mr18680446ywf.50.1507139576889; Wed, 04 Oct 2017 10:52:56 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:9ec1]) by smtp.googlemail.com with ESMTPSA id g204sm699826ywb.7.2017.10.04.10.52.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 10:52:55 -0700 (PDT) To: GCC Patches , Jason Merrill From: Nathan Sidwell Subject: [C++ PATCH] give builtin types consistent name Message-ID: <012eb489-2db5-1fba-6041-7ed18b4d286a@acm.org> Date: Wed, 4 Oct 2017 13:52:53 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 The builtin type machinery is one of the places were we push decls into :: under not-their-name. There's no real reason for this, and the fix is simple -- create a new TYPE_DECL if we use a name from the ridpointer table. I took the opportunity of reordering record_builtin_type, which was a series of interleaved conditionals dealing with different things. I add an assert to set_global_binding that the given name is DECL_NAME. Of course this raises the opportunity of just making set_global_binding have a single arg, like pushdecl and friends. And then the two macros IDENTIFIER_GLOBAL_VALUE and SET_IDENTIFIER_GLOBAL_VALUE could be dispensed with and we have simply tree get_global_value (tree identifier); tree set_global_value (tree decl); perhaps 's/value/decl/'? Jason, any preference? set_global_value has to do the stat_hack dance, I can't recall the case where it happens, but I recall it biting me when I tried to dispense with it. The remaining mismatched name case is the anonymous namespace. Once that's fixed we can change namespace bindings from a map to a hash, and halve its size. Applying to trunk. nathan 2017-10-04 Nathan Sidwell Give builtin types the correct name. * name-lookup.c (set_global_binding): Assert name is DECL_NAME. * decl.c (record_builtin_type): Reimplement, use new TYPE_DECL for rname. Index: decl.c =================================================================== --- decl.c (revision 253413) +++ decl.c (working copy) @@ -3895,47 +3895,47 @@ make_unbound_class_template (tree contex /* 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. */ + type. TYPE is the _TYPE node for the builtin type. + + The calls to SET_IDENTIFIER_GLOBAL_VALUE below should be + eliminated. Built-in types should not be looked up name; their + names are keywords that the parser can recognize. However, there + is code in c-common.c that uses identifier_global_value to look up + built-in types by name. */ void record_builtin_type (enum rid rid_index, const char* name, tree type) { - tree rname = NULL_TREE, tname = NULL_TREE; - tree tdecl = NULL_TREE; + tree decl = NULL_TREE; - if ((int) rid_index < (int) RID_MAX) - rname = ridpointers[(int) rid_index]; if (name) - tname = get_identifier (name); - - /* The calls to SET_IDENTIFIER_GLOBAL_VALUE below should be - eliminated. Built-in types should not be looked up name; their - names are keywords that the parser can recognize. However, there - is code in c-common.c that uses identifier_global_value to look - up built-in types by name. */ - if (tname) { - tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type); + tree tname = get_identifier (name); + tree tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, tname, type); DECL_ARTIFICIAL (tdecl) = 1; SET_IDENTIFIER_GLOBAL_VALUE (tname, tdecl); + decl = tdecl; } - if (rname) - { - if (!tdecl) + + if ((int) rid_index < (int) RID_MAX) + if (tree rname = ridpointers[(int) rid_index]) + if (!decl || DECL_NAME (decl) != rname) { - tdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type); - DECL_ARTIFICIAL (tdecl) = 1; + tree rdecl = build_decl (BUILTINS_LOCATION, TYPE_DECL, rname, type); + DECL_ARTIFICIAL (rdecl) = 1; + SET_IDENTIFIER_GLOBAL_VALUE (rname, rdecl); + if (!decl) + decl = rdecl; } - SET_IDENTIFIER_GLOBAL_VALUE (rname, tdecl); - } - - if (!TYPE_NAME (type)) - TYPE_NAME (type) = tdecl; - if (tdecl) - debug_hooks->type_decl (tdecl, 0); + if (decl) + { + if (!TYPE_NAME (type)) + TYPE_NAME (type) = decl; + debug_hooks->type_decl (decl, 0); + } } /* Push a type into the namespace so that the back ends ignore it. */ Index: name-lookup.c =================================================================== --- name-lookup.c (revision 253421) +++ name-lookup.c (working copy) @@ -4847,6 +4847,7 @@ set_global_binding (tree name, tree val) { bool subtime = timevar_cond_start (TV_NAME_LOOKUP); + gcc_checking_assert (name == DECL_NAME (val)); tree *slot = find_namespace_slot (global_namespace, name, true); tree old = MAYBE_STAT_DECL (*slot);