From patchwork Wed Nov 1 18:29:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 833082 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-465688-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="vskR+P/8"; 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 3yRxbP4KMGz9t2V for ; Thu, 2 Nov 2017 05:30:08 +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 :subject:from:to:references:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=fOfvJ1UlcPMaQcnhS 4laIDuLKlM4jbwwzA5M01bKlE2+1VO4U3ObnTGFb+uAneHqydtRJoTWH0VQCNbNO qpK8wCtMaFRq3cCLGvCtdhjBtJgA6+wJKFyLUeYikkfxGOnDndppL9DOMq36ZFf3 AgzcnM60BKjiT9wyUJPh6hpZd8= 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 :subject:from:to:references:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=YsOWo/dko6foQGYHCmqKUcv 4IYM=; b=vskR+P/83Alely4vG2EclrZQdUjm1rQNhdnRbHVI+gL9lKb+kVTDbQL +9+12yicbvKB5v1MrNdhtYInXY8Ylf2W8jaS+P+5/SMINd75PsfebnGFumvh6ZXx iUeziwQ8SgspdcDDjvmtdsEYwscAHtFoLoRZcUA6FWROT95eoq/c= Received: (qmail 45858 invoked by alias); 1 Nov 2017 18:29:59 -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 45248 invoked by uid 89); 1 Nov 2017 18:29:59 -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=reserves X-HELO: mail-yw0-f181.google.com Received: from mail-yw0-f181.google.com (HELO mail-yw0-f181.google.com) (209.85.161.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 01 Nov 2017 18:29:57 +0000 Received: by mail-yw0-f181.google.com with SMTP id k11so2637211ywh.1 for ; Wed, 01 Nov 2017 11:29:56 -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:subject:from:to:references:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=K3zWA1bXidLjZDj1OiIpD7izT2iaKiLeud3BX28MhOU=; b=AqAsg1tBklsAr1Ur0kuALnjz8Wd+TKg0iTVz1hUlXprrxo/g+os5ac4bRlyCEFy7lW Af6/djk3Rdk1kk2eKrdaCKrRAcIGIbXLnzx0N7JrV3OZoMEfSYfuJSLf6h8jKlUNoZiy 2ZNAK19jeDlGVpKuMnVVxP6niK5OAi/AE8yxqb/XN267at21csKn84V3ycyKK4KqyU+G qMQPbMLUQPA8S6Jj2ANobGd8CagIsFNsHYmdlbDe5CKfWcQAWXtlABiwQA85Oiy1KNPy GXBpVwkOn+Z7yQ5MS79XNsO5aPW1d3MrBeTifhrD06C5B0sB+/AHLevjf9PXtM8e/HXJ deWA== X-Gm-Message-State: AMCzsaWmkC1xGCtQQw7pJbbNh4z0KG/VADT7vsCGFSX+DpXseAibZKRT C0MmtOlPp4xoucJ1nXS4fHU= X-Google-Smtp-Source: ABhQp+Rdp8+VMLpNGCu+dugrId70klYn9JaRKa2o4GjTFLPMq1f3QB4fJLQ37q1hp6/qTI7hQJm/Fw== X-Received: by 10.13.237.2 with SMTP id w2mr538437ywe.414.1509560995227; Wed, 01 Nov 2017 11:29:55 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a1:1102:495f:7267:5ff:a250? ([2620:10d:c091:180::1:84ed]) by smtp.googlemail.com with ESMTPSA id m2sm531013ywe.14.2017.11.01.11.29.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Nov 2017 11:29:54 -0700 (PDT) Subject: [C++ PATCH] overloaded operator fns [8/N] From: Nathan Sidwell To: GCC Patches References: <40b48778-5335-2398-3dd5-e59f68b8f052@acm.org> <006c8467-dde6-1605-243c-f8d033ab4e49@acm.org> <85d3718d-17f4-42f4-db0b-7c2b3632aa6e@acm.org> Message-ID: Date: Wed, 1 Nov 2017 14:29:52 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <85d3718d-17f4-42f4-db0b-7c2b3632aa6e@acm.org> This is the last of the overloaded operator reworking. Now we can cheaply go from identifier->overload info, there's no need to specially mark identifiers as new or delete operators themselves. Thus we can reorder the cp_identifier_kind enumeration and leave space in it for udlit operators. This patch does that renumbering, and reserves a value for udlit operators. Those are currently detected by string compare, which isn't the most satisfactory way to do it. But it's a change for another day. nathan 2017-11-01 Nathan Sidwell * cp-tree.h (enum cp_identifier_kind): Delete cik_newdel_op. Renumber and reserve udlit value. (IDENTIFIER_NEWDEL_OP): Delete. (IDENTIFIER_OVL_OP): New. (IDENTIFIER_ASSIGN_OP): Adjust. (IDENTIFIER_CONV_OP): Adjust. (IDENTIFIER_OVL_OP_INFO): Adjust. (IDENTIFIER_OVL_OP_FLAGS): New. * decl.c (grokdeclarator): Use IDENTIFIER_OVL_OP_FLAGS. * lex.c (get_identifier_kind_name): Adjust. (init_operators): Don't special case new/delete ops. * mangle.c (write_unqualified_id): Use IDENTIFIER_OVL_OP. * pt.c (push_template_decl_real): Use IDENTIFIER_OVL_OP_FLAGS. * typeck.c (check_return_expr): Likewise. Index: cp-tree.h =================================================================== --- cp-tree.h (revision 254314) +++ cp-tree.h (working copy) @@ -996,9 +996,9 @@ enum cp_identifier_kind { cik_dtor = 3, /* Destructor (in-chg, deleting, complete or base). */ cik_simple_op = 4, /* Non-assignment operator name. */ - cik_newdel_op = 5, /* New or delete operator name. */ - cik_assign_op = 6, /* An assignment operator name. */ - cik_conv_op = 7, /* Conversion operator name. */ + cik_assign_op = 5, /* An assignment operator name. */ + cik_conv_op = 6, /* Conversion operator name. */ + cik_reserved_for_udlit = 7, /* Not yet in use */ cik_max }; @@ -1053,24 +1053,22 @@ enum cp_identifier_kind { #define IDENTIFIER_ANY_OP_P(NODE) \ (IDENTIFIER_KIND_BIT_2 (NODE)) -/* True if this identifier is for new or delete operator. Value 5. */ -#define IDENTIFIER_NEWDEL_OP_P(NODE) \ - (IDENTIFIER_KIND_BIT_2 (NODE) \ - & (!IDENTIFIER_KIND_BIT_1 (NODE)) \ - & IDENTIFIER_KIND_BIT_0 (NODE)) +/* True if this identifier is for an overloaded operator. Values 4, 5. */ +#define IDENTIFIER_OVL_OP_P(NODE) \ + (IDENTIFIER_ANY_OP_P (NODE) \ + & (!IDENTIFIER_KIND_BIT_1 (NODE))) -/* True if this identifier is for any assignment. Values 6. */ +/* True if this identifier is for any assignment. Values 5. */ #define IDENTIFIER_ASSIGN_OP_P(NODE) \ - (IDENTIFIER_KIND_BIT_2 (NODE) \ - & IDENTIFIER_KIND_BIT_1 (NODE) \ - & (!IDENTIFIER_KIND_BIT_0 (NODE))) + (IDENTIFIER_OVL_OP_P (NODE) \ + & IDENTIFIER_KIND_BIT_0 (NODE)) /* True if this identifier is the name of a type-conversion operator. Value 7. */ #define IDENTIFIER_CONV_OP_P(NODE) \ - (IDENTIFIER_KIND_BIT_2 (NODE) \ + (IDENTIFIER_ANY_OP_P (NODE) \ & IDENTIFIER_KIND_BIT_1 (NODE) \ - & IDENTIFIER_KIND_BIT_0 (NODE)) + & (!IDENTIFIER_KIND_BIT_0 (NODE))) /* Access a C++-specific index for identifier NODE. Used to optimize operator mappings etc. */ @@ -5529,9 +5527,11 @@ extern GTY(()) unsigned char ovl_op_alte #define OVL_OP_INFO(IS_ASS_P, TREE_CODE) \ (&ovl_op_info[(IS_ASS_P) != 0][ovl_op_mapping[(TREE_CODE)]]) /* Overloaded operator info for an identifier for which - IDENTIFIER_ANY_OP_P is true. */ + IDENTIFIER_OVL_OP_P is true. */ #define IDENTIFIER_OVL_OP_INFO(NODE) \ - (&ovl_op_info[IDENTIFIER_ASSIGN_OP_P (NODE)][IDENTIFIER_CP_INDEX (NODE)]) + (&ovl_op_info[IDENTIFIER_KIND_BIT_0 (NODE)][IDENTIFIER_CP_INDEX (NODE)]) +#define IDENTIFIER_OVL_OP_FLAGS(NODE) \ + (IDENTIFIER_OVL_OP_INFO (NODE)->flags) /* A type-qualifier, or bitmask therefore, using the TYPE_QUAL constants. */ Index: decl.c =================================================================== --- decl.c (revision 254314) +++ decl.c (working copy) @@ -11744,7 +11744,8 @@ grokdeclarator (const cp_declarator *dec if (ctype && TREE_CODE (type) == FUNCTION_TYPE && staticp < 2 && !(identifier_p (unqualified_id) - && IDENTIFIER_NEWDEL_OP_P (unqualified_id))) + && IDENTIFIER_OVL_OP_P (unqualified_id) + && (IDENTIFIER_OVL_OP_FLAGS (unqualified_id) & OVL_OP_FLAG_ALLOC))) { cp_cv_quals real_quals = memfn_quals; if (cxx_dialect < cxx14 && constexpr_p @@ -11857,7 +11858,9 @@ grokdeclarator (const cp_declarator *dec if (virtualp && identifier_p (unqualified_id) - && IDENTIFIER_NEWDEL_OP_P (unqualified_id)) + && IDENTIFIER_OVL_OP_P (unqualified_id) + && (IDENTIFIER_OVL_OP_FLAGS (unqualified_id) + & OVL_OP_FLAG_ALLOC)) { error ("%qD cannot be declared %, since it " "is always static", unqualified_id); Index: lex.c =================================================================== --- lex.c (revision 254314) +++ lex.c (working copy) @@ -100,7 +100,8 @@ get_identifier_kind_name (tree id) /* Keep in sync with cp_id_kind enumeration. */ static const char *const names[cik_max] = { "normal", "keyword", "constructor", "destructor", - "assign-op", "op-assign-op", "simple-op", "conv-op", }; + "simple-op", "assign-op", "conv-op", "udlit-op" + }; unsigned kind = 0; kind |= IDENTIFIER_KIND_BIT_2 (id) << 2; @@ -176,9 +177,7 @@ init_operators (void) else { IDENTIFIER_CP_INDEX (ident) = ix; - set_identifier_kind (ident, - op_ptr->flags & OVL_OP_FLAG_ALLOC - ? cik_newdel_op : cik_simple_op); + set_identifier_kind (ident, cik_simple_op); } } if (op_ptr->tree_code) Index: mangle.c =================================================================== --- mangle.c (revision 254314) +++ mangle.c (working copy) @@ -1263,7 +1263,7 @@ write_unqualified_id (tree identifier) { if (IDENTIFIER_CONV_OP_P (identifier)) write_conversion_operator_name (TREE_TYPE (identifier)); - else if (IDENTIFIER_ANY_OP_P (identifier)) + else if (IDENTIFIER_OVL_OP_P (identifier)) { const ovl_op_info_t *ovl_op = IDENTIFIER_OVL_OP_INFO (identifier); write_string (ovl_op->mangled_name); Index: pt.c =================================================================== --- pt.c (revision 254314) +++ pt.c (working copy) @@ -5329,7 +5329,9 @@ push_template_decl_real (tree decl, bool error ("destructor %qD declared as member template", decl); return error_mark_node; } - if (IDENTIFIER_NEWDEL_OP_P (DECL_NAME (decl)) + if (IDENTIFIER_OVL_OP_P (DECL_NAME (decl)) + && (IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (decl)) + & OVL_OP_FLAG_ALLOC) && (!prototype_p (TREE_TYPE (decl)) || TYPE_ARG_TYPES (TREE_TYPE (decl)) == void_list_node || !TREE_CHAIN (TYPE_ARG_TYPES (TREE_TYPE (decl))) Index: typeck.c =================================================================== --- typeck.c (revision 254314) +++ typeck.c (working copy) @@ -9073,9 +9073,9 @@ check_return_expr (tree retval, bool *no } /* Only operator new(...) throw(), can return NULL [expr.new/13]. */ - if (DECL_OVERLOADED_OPERATOR_P (current_function_decl) - && (DECL_OVERLOADED_OPERATOR_IS (current_function_decl, NEW_EXPR) - || DECL_OVERLOADED_OPERATOR_IS (current_function_decl, VEC_NEW_EXPR)) + if (IDENTIFIER_OVL_OP_P (DECL_NAME (current_function_decl)) + && ((IDENTIFIER_OVL_OP_FLAGS (DECL_NAME (current_function_decl)) + & (OVL_OP_FLAG_ALLOC | OVL_OP_FLAG_DELETE)) == OVL_OP_FLAG_ALLOC) && !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl)) && ! flag_check_new && retval && null_ptr_cst_p (retval))