From patchwork Fri Jun 30 18:48:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 782949 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 3wzltY5Ff2z9s7f for ; Sat, 1 Jul 2017 04:49:08 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="JE7B2Hl7"; 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=A3lwSLK9c6nKFIM78XRMGhJZSL2VImCezZVyFmBFW8CY+AtORW QILLPEqU+AylxMFKgeCNMQV+ULb8N7j/iCvUUxTFQJ54N1Pgrf/fTpgQbRsOIJ8b tPHdzNO0uSP88/+6CPCyEwW+W0VJ2hlPfKPnRf16DmlHLxi+C770idjWc= 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=DR9+jBDNvU4vDME4nOMdsP0ygfc=; b=JE7B2Hl7y8Poey/lozgK zOEVl+zL3fsZ4tCS2Q5m1qQJRB8B1c1OCxF0n7Px8WlHfANSVMzG9NbnSQWsZyUP lRJP1E5UENrYow1ANyKzPDmwoU7xjO15qeN5VF0VkcuCBabHtMLmKfIYQYmuMZuM IxKwxuKcB/49GllUFK90IxY= Received: (qmail 27783 invoked by alias); 30 Jun 2017 18:48:50 -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 27577 invoked by uid 89); 30 Jun 2017 18:48:37 -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=Hang X-HELO: mail-yw0-f170.google.com Received: from mail-yw0-f170.google.com (HELO mail-yw0-f170.google.com) (209.85.161.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 30 Jun 2017 18:48:19 +0000 Received: by mail-yw0-f170.google.com with SMTP id j11so52627992ywa.2 for ; Fri, 30 Jun 2017 11:48:04 -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=OoPUVWxCqCTjNoY6O0YxeJrvsOJGn6g2l7uTZA5CXCA=; b=Qbn2aXbTR9DNwl6ZweKBm3J6oWXMDTRlPlXc4QquHUcDI3lH4iO64QKOiFA5VSyhQy A6waIKCeZ7ldPspaVdU3CEKGmbHG2hQbslc60UO8jwcpEyVdaPoN8hOfX9xH+1+kZbrp v/7yvGz/l4L0VpjndgCMiW8o8F3FEtZXtvpAEGFcFM3CDamoUrGhEyoHRHr9oyVxAM98 SIXvFGr2gnDHAxM/J1Es2DyM2p17eZUpThDu8D3sGgvu0s/5Wnea8ZsO9UUGJRfojznu 2vPs0yA9oYtBCG+3P7H/Ji7FeZ6PnQ3uNTc8ICwAEwiT9v2degjqRpSqm4RSeXn1xZ7v V+zQ== X-Gm-Message-State: AKS2vOxYdYT5vrVqXC4JDq1Xye3GqdD0NueKFig2FJNZe1ZblaN7Og5a +4NHL246WsiV/w== X-Received: by 10.13.223.16 with SMTP id i16mr17734197ywe.250.1498848483343; Fri, 30 Jun 2017 11:48:03 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::1:9018]) by smtp.googlemail.com with ESMTPSA id i128sm3612990ywe.8.2017.06.30.11.48.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Jun 2017 11:48:02 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] conversion operator names Message-ID: Date: Fri, 30 Jun 2017 14:48:01 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 We used to give conversion operatos type-specific mangled names. Now we just number them 'operator $N' for N in [1,...]. As such mangle_convop_name_for_type is misnamed and has no place in mangle.c This patch moves that machinery to lex.c, which is a better place (best place?). Other than renaming to make_conv_op_name, nothing else changes. For. The. Moment. nathan 2017-06-30 Nathan Sidwell * config-lang.in (gtfiles): Add cp/lex.c. * cp-tree.h (mangle_convop_name_for_type): Rename ... (make_conv_op_name): ... here. Move to lex. * lambda.c (maybe_add_lambda_conv_op): Update. * parser.c (cp_parser_conversion_function_id): Update. * pt.c (tsubst_decl, tsubst_baselink, tsubst_copy, tsubst_copy_and_build): Update. * semantics.c (apply_deduced_return_type): Update. * mangle.c (conv_type_hasher, conv_type_names, mangle_conv_op_name_for_type): Move to ... * lex.c (conv_type_hasher, conv_type_names, make_convop_name): ... here. Rename. * libcp1plugin.cc (plugin_build_decl): Use make_conv_op_name. (plugin_build_dependent_expr): Likewise. Index: gcc/cp/config-lang.in =================================================================== --- gcc/cp/config-lang.in (revision 249835) +++ gcc/cp/config-lang.in (working copy) @@ -45,7 +45,7 @@ gtfiles="\ \$(srcdir)/cp/except.c \ \$(srcdir)/cp/friend.c \ \$(srcdir)/cp/init.c \ -\$(srcdir)/cp/lambda.c \ +\$(srcdir)/cp/lambda.c \$(srcdir)/cp/lex.c \ \$(srcdir)/cp/mangle.c \$(srcdir)/cp/method.c \ \$(srcdir)/cp/name-lookup.c \ \$(srcdir)/cp/parser.c \$(srcdir)/cp/pt.c \ Index: gcc/cp/cp-tree.h =================================================================== --- gcc/cp/cp-tree.h (revision 249843) +++ gcc/cp/cp-tree.h (working copy) @@ -6326,6 +6326,7 @@ extern void yyungetc (int, int); extern tree unqualified_name_lookup_error (tree, location_t = UNKNOWN_LOCATION); extern tree unqualified_fn_lookup_error (cp_expr); +extern tree make_conv_op_name (tree); extern tree build_lang_decl (enum tree_code, tree, tree); extern tree build_lang_decl_loc (location_t, enum tree_code, tree, tree); extern void retrofit_lang_decl (tree); @@ -7180,7 +7181,6 @@ extern tree mangle_vtbl_for_type (tree) extern tree mangle_vtt_for_type (tree); extern tree mangle_ctor_vtbl_for_type (tree, tree); extern tree mangle_thunk (tree, int, tree, tree, tree); -extern tree mangle_conv_op_name_for_type (tree); extern tree mangle_guard_variable (tree); extern tree mangle_tls_init_fn (tree); extern tree mangle_tls_wrapper_fn (tree); Index: gcc/cp/lambda.c =================================================================== --- gcc/cp/lambda.c (revision 249835) +++ gcc/cp/lambda.c (working copy) @@ -1088,7 +1088,7 @@ maybe_add_lambda_conv_op (tree type) /* First build up the conversion op. */ tree rettype = build_pointer_type (stattype); - tree name = mangle_conv_op_name_for_type (rettype); + tree name = make_conv_op_name (rettype); tree thistype = cp_build_qualified_type (type, TYPE_QUAL_CONST); tree fntype = build_method_type_directly (thistype, rettype, void_list_node); tree convfn = build_lang_decl (FUNCTION_DECL, name, fntype); Index: gcc/cp/lex.c =================================================================== --- gcc/cp/lex.c (revision 249835) +++ gcc/cp/lex.c (working copy) @@ -531,6 +531,74 @@ unqualified_fn_lookup_error (cp_expr nam return unqualified_name_lookup_error (name, loc); } +struct conv_type_hasher : ggc_ptr_hash +{ + static hashval_t hash (tree); + static bool equal (tree, tree); +}; + +/* This hash table maps TYPEs to the IDENTIFIER for a conversion + operator to TYPE. The nodes are IDENTIFIERs whose TREE_TYPE is the + TYPE. */ + +static GTY (()) hash_table *conv_type_names; + +/* Hash a node (VAL1) in the table. */ + +hashval_t +conv_type_hasher::hash (tree val) +{ + return (hashval_t) TYPE_UID (TREE_TYPE (val)); +} + +/* Compare VAL1 (a node in the table) with VAL2 (a TYPE). */ + +bool +conv_type_hasher::equal (tree val1, tree val2) +{ + return TREE_TYPE (val1) == val2; +} + +/* Return an identifier for a conversion operator to TYPE. We can + get from the returned identifier to the type. */ + +tree +make_conv_op_name (tree type) +{ + tree *slot; + tree identifier; + + if (type == error_mark_node) + return error_mark_node; + + if (conv_type_names == NULL) + conv_type_names = hash_table::create_ggc (31); + + slot = conv_type_names->find_slot_with_hash (type, + (hashval_t) TYPE_UID (type), + INSERT); + identifier = *slot; + if (!identifier) + { + char buffer[64]; + + /* Create a unique name corresponding to TYPE. */ + sprintf (buffer, "operator %lu", + (unsigned long) conv_type_names->elements ()); + identifier = get_identifier (buffer); + *slot = identifier; + + /* Hang TYPE off the identifier so it can be found easily later + when performing conversions. */ + TREE_TYPE (identifier) = type; + + /* Set the identifier kind so we know later it's a conversion. */ + set_identifier_kind (identifier, cik_conv_op); + } + + return identifier; +} + /* Wrapper around build_lang_decl_loc(). Should gradually move to build_lang_decl_loc() and then rename build_lang_decl_loc() back to build_lang_decl(). */ @@ -799,3 +867,5 @@ in_main_input_context (void) else return filename_cmp (main_input_filename, LOCATION_FILE (input_location)) == 0; } + +#include "gt-cp-lex.h" Index: gcc/cp/mangle.c =================================================================== --- gcc/cp/mangle.c (revision 249835) +++ gcc/cp/mangle.c (working copy) @@ -4176,75 +4176,6 @@ mangle_thunk (tree fn_decl, const int th return result; } -struct conv_type_hasher : ggc_ptr_hash -{ - static hashval_t hash (tree); - static bool equal (tree, tree); -}; - -/* This hash table maps TYPEs to the IDENTIFIER for a conversion - operator to TYPE. The nodes are IDENTIFIERs whose TREE_TYPE is the - TYPE. */ - -static GTY (()) hash_table *conv_type_names; - -/* Hash a node (VAL1) in the table. */ - -hashval_t -conv_type_hasher::hash (tree val) -{ - return (hashval_t) TYPE_UID (TREE_TYPE (val)); -} - -/* Compare VAL1 (a node in the table) with VAL2 (a TYPE). */ - -bool -conv_type_hasher::equal (tree val1, tree val2) -{ - return TREE_TYPE (val1) == val2; -} - -/* Return an identifier for the mangled unqualified name for a - conversion operator to TYPE. This mangling is not specified by the - ABI spec; it is only used internally. */ - -tree -mangle_conv_op_name_for_type (const tree type) -{ - tree *slot; - tree identifier; - - if (type == error_mark_node) - return error_mark_node; - - if (conv_type_names == NULL) - conv_type_names = hash_table::create_ggc (31); - - slot = conv_type_names->find_slot_with_hash (type, - (hashval_t) TYPE_UID (type), - INSERT); - identifier = *slot; - if (!identifier) - { - char buffer[64]; - - /* Create a unique name corresponding to TYPE. */ - sprintf (buffer, "operator %lu", - (unsigned long) conv_type_names->elements ()); - identifier = get_identifier (buffer); - *slot = identifier; - - /* Hang TYPE off the identifier so it can be found easily later - when performing conversions. */ - TREE_TYPE (identifier) = type; - - /* Set the identifier kind so we know later it's a conversion. */ - set_identifier_kind (identifier, cik_conv_op); - } - - return identifier; -} - /* Handle ABI backwards compatibility for past bugs where we didn't call check_abi_tags in places where it's needed: call check_abi_tags and warn if it makes a difference. If FOR_DECL is non-null, it's the declaration Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 249835) +++ gcc/cp/parser.c (working copy) @@ -14067,7 +14067,7 @@ cp_parser_conversion_function_id (cp_par /* If the TYPE is invalid, indicate failure. */ if (type == error_mark_node) return error_mark_node; - return mangle_conv_op_name_for_type (type); + return make_conv_op_name (type); } /* Parse a conversion-type-id: Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 249843) +++ gcc/cp/pt.c (working copy) @@ -12385,7 +12385,7 @@ tsubst_decl (tree t, tree args, tsubst_f if (member && DECL_CONV_FN_P (r)) /* Type-conversion operator. Reconstruct the name, in case it's the name of one of the template's parameters. */ - DECL_NAME (r) = mangle_conv_op_name_for_type (TREE_TYPE (type)); + DECL_NAME (r) = make_conv_op_name (TREE_TYPE (type)); DECL_ARGUMENTS (r) = tsubst (DECL_ARGUMENTS (t), args, complain, t); @@ -14242,7 +14242,7 @@ tsubst_baselink (tree baselink, tree obj tree name = OVL_NAME (fns); if (IDENTIFIER_CONV_OP_P (name)) - name = mangle_conv_op_name_for_type (optype); + name = make_conv_op_name (optype); baselink = lookup_fnfields (qualifying_scope, name, /*protect=*/1); if (!baselink) @@ -15032,7 +15032,7 @@ tsubst_copy (tree t, tree args, tsubst_f if (IDENTIFIER_CONV_OP_P (t)) { tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl); - return mangle_conv_op_name_for_type (new_type); + return make_conv_op_name (new_type); } else return t; @@ -16665,7 +16665,7 @@ tsubst_copy_and_build (tree t, if (IDENTIFIER_CONV_OP_P (t)) { tree new_type = tsubst (TREE_TYPE (t), args, complain, in_decl); - t = mangle_conv_op_name_for_type (new_type); + t = make_conv_op_name (new_type); } /* Look up the name. */ Index: gcc/cp/semantics.c =================================================================== --- gcc/cp/semantics.c (revision 249843) +++ gcc/cp/semantics.c (working copy) @@ -9399,7 +9399,7 @@ apply_deduced_return_type (tree fco, tre } if (DECL_CONV_FN_P (fco)) - DECL_NAME (fco) = mangle_conv_op_name_for_type (return_type); + DECL_NAME (fco) = make_conv_op_name (return_type); TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco)); Index: libcc1/libcp1plugin.cc =================================================================== --- libcc1/libcp1plugin.cc (revision 249835) +++ libcc1/libcp1plugin.cc (working copy) @@ -1321,7 +1321,7 @@ plugin_build_decl (cc1_plugin::connectio opcode = ARRAY_REF; break; case CHARS2 ('c', 'v'): // operator (conversion operator) - identifier = mangle_conv_op_name_for_type (TREE_TYPE (sym_type)); + identifier = make_conv_op_name (TREE_TYPE (sym_type)); break; // C++11-only: case CHARS2 ('l', 'i'): // operator "" @@ -2622,7 +2622,7 @@ plugin_build_dependent_expr (cc1_plugin: break; case CHARS2 ('c', 'v'): // operator (conversion operator) convop = true; - identifier = mangle_conv_op_name_for_type (conv_type); + identifier = make_conv_op_name (conv_type); break; // C++11-only: case CHARS2 ('l', 'i'): // operator ""