From 183e687af1dd8ca311712b5061c205a43ce1252c Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Wed, 1 Nov 2017 18:30:42 +0000 Subject: [PATCH] [C++ PATCH] overloaded operator fns [8/N] https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00031.html * 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. From-SVN: r254322 --- gcc/cp/ChangeLog | 15 +++++++++++++++ gcc/cp/cp-tree.h | 32 ++++++++++++++++---------------- gcc/cp/decl.c | 7 +++++-- gcc/cp/lex.c | 7 +++---- gcc/cp/mangle.c | 2 +- gcc/cp/pt.c | 4 +++- gcc/cp/typeck.c | 6 +++--- 7 files changed, 46 insertions(+), 27 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index b97bb933357..d3ffadfb1fb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,20 @@ 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. + * cp-tree.h (assign_op_identifier, call_op_identifier): Use compressed code. (struct lang_decl_fn): Use compressed operator code. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index d1d772fda7f..1de32de1405 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -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_alternate[OVL_OP_MAX]; #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. */ diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index d544d068cd2..d88c78f348b 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -11744,7 +11744,8 @@ grokdeclarator (const cp_declarator *declarator, 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 *declarator, 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); diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c index 7754145f648..c097f4b54cf 100644 --- a/gcc/cp/lex.c +++ b/gcc/cp/lex.c @@ -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) diff --git a/gcc/cp/mangle.c b/gcc/cp/mangle.c index e40082f8a58..050055bd26c 100644 --- a/gcc/cp/mangle.c +++ b/gcc/cp/mangle.c @@ -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); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 629b2dd50ef..f807e8c3955 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -5329,7 +5329,9 @@ push_template_decl_real (tree decl, bool is_friend) 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))) diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 0e3ea1a1edf..e2df355921a 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -9073,9 +9073,9 @@ check_return_expr (tree retval, bool *no_warning) } /* 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)) -- 2.30.2