[C++ PATCH] overloaded operator fns [6/N]
authorNathan Sidwell <nathan@acm.org>
Wed, 1 Nov 2017 15:46:42 +0000 (15:46 +0000)
committerNathan Sidwell <nathan@gcc.gnu.org>
Wed, 1 Nov 2017 15:46:42 +0000 (15:46 +0000)
https://gcc.gnu.org/ml/gcc-patches/2017-11/msg00019.html
gcc/cp/
* cp-tree.h (assign_op_identifier, call_op_identifier): Use
compressed code.
(struct lang_decl_fn): Use compressed operator code.
(DECL_OVERLOADED_OPERATOR_CODE): Replace with ...
(DECL_OVERLOADED_OPERATOR_CODE_RAW): ... this.
(DECL_OVERLOADED_OPERATOR_CODE_IS): Use it.
* decl.c (duplicate_decls): Use DECL_OVERLOADED_OPERATOR_CODE_RAW.
(build_library_fn): Likewise.
(grok_op_properties): Likewise.
* mangle.c (write_unqualified_name): Likewise.
* method.c (implicitly_declare_fn): Likewise.
* typeck.c (check_return_expr): Use DECL_OVERLOADED_OPERATOR_IS.

libcc1/
* libcp1plugin.cc (plugin_build_decl): Use
DECL_OVERLOADED_OPERATOR_CODE_RAW.

From-SVN: r254314

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/mangle.c
gcc/cp/method.c
gcc/cp/typeck.c
libcc1/ChangeLog
libcc1/libcp1plugin.cc

index 8f4cc9951ec33bf3e9674d4afe07e5bdbf6e8e9f..b97bb933357edb4a4abd1b227678dec53deb61dd 100644 (file)
@@ -1,5 +1,18 @@
 2017-11-01  Nathan Sidwell  <nathan@acm.org>
 
+       * cp-tree.h (assign_op_identifier, call_op_identifier): Use
+       compressed code.
+       (struct lang_decl_fn): Use compressed operator code.
+       (DECL_OVERLOADED_OPERATOR_CODE): Replace with ...
+       (DECL_OVERLOADED_OPERATOR_CODE_RAW): ... this.
+       (DECL_OVERLOADED_OPERATOR_CODE_IS): Use it.
+       * decl.c (duplicate_decls): Use DECL_OVERLOADED_OPERATOR_CODE_RAW.
+       (build_library_fn): Likewise.
+       (grok_op_properties): Likewise.
+       * mangle.c (write_unqualified_name): Likewise.
+       * method.c (implicitly_declare_fn): Likewise.
+       * typeck.c (check_return_expr): Use DECL_OVERLOADED_OPERATOR_IS.
+
        * cp-tree.h (IDENTIFIER_CP_INDEX): Define.
        (enum ovl_op_flags): Add OVL_OP_FLAG_AMBIARY.
        (enum ovl_op_code): New.
index 76ee8541daf10e3534dbf075d3780838180cb1e1..d1d772fda7f724b0a064714f39f1165c3e83773d 100644 (file)
@@ -246,8 +246,8 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
 #define deleting_dtor_identifier       cp_global_trees[CPTI_DELETING_DTOR_IDENTIFIER]
 
 #define ovl_op_identifier(ISASS, CODE)  (OVL_OP_INFO(ISASS, CODE)->identifier)
-#define assign_op_identifier (ovl_op_identifier (true, NOP_EXPR))
-#define call_op_identifier (ovl_op_identifier (false, CALL_EXPR))
+#define assign_op_identifier (ovl_op_info[true][OVL_OP_NOP_EXPR].identifier)
+#define call_op_identifier (ovl_op_info[false][OVL_OP_CALL_EXPR].identifier)
 /* The name used for conversion operators -- but note that actual
    conversion functions use special identifiers outside the identifier
    table.  */
@@ -2479,26 +2479,24 @@ struct GTY(()) lang_decl_min {
 struct GTY(()) lang_decl_fn {
   struct lang_decl_min min;
 
-  /* In an overloaded operator, this is the value of
-     DECL_OVERLOADED_OPERATOR_P.
-     FIXME: We should really do better in compressing this.  */
-  ENUM_BITFIELD (tree_code) operator_code : 16;
-
+  /* In a overloaded operator, this is the compressed operator code.  */
+  unsigned ovl_op_code : 6;
   unsigned global_ctor_p : 1;
   unsigned global_dtor_p : 1;
+
   unsigned static_function : 1;
   unsigned pure_virtual : 1;
   unsigned defaulted_p : 1;
   unsigned has_in_charge_parm_p : 1;
   unsigned has_vtt_parm_p : 1;
   unsigned pending_inline_p : 1;
-
   unsigned nonconverting : 1;
   unsigned thunk_p : 1;
+
   unsigned this_thunk_p : 1;
   unsigned hidden_friend_p : 1;
   unsigned omp_declare_reduction_p : 1;
-  /* 3 spare bits.  */
+  unsigned spare : 13;
 
   /* 32-bits padding on 64-bit host.  */
 
@@ -2814,14 +2812,14 @@ struct GTY(()) lang_decl {
   IDENTIFIER_ASSIGN_OP_P (DECL_NAME (NODE))
 
 /* NODE is a function_decl for an overloaded operator.  Return its
-   operator code.   */
-#define DECL_OVERLOADED_OPERATOR_CODE(NODE)                    \
-  (LANG_DECL_FN_CHECK (NODE)->operator_code)
+   compressed (raw) operator code.  Note that this is not a TREE_CODE.  */
+#define DECL_OVERLOADED_OPERATOR_CODE_RAW(NODE)                \
+  (LANG_DECL_FN_CHECK (NODE)->ovl_op_code)
 
 /* DECL is an overloaded operator.  Test whether it is for TREE_CODE
    (a literal constant).  */
 #define DECL_OVERLOADED_OPERATOR_IS(DECL, CODE)                        \
-  (DECL_OVERLOADED_OPERATOR_CODE (DECL) == CODE)
+  (DECL_OVERLOADED_OPERATOR_CODE_RAW (DECL) == OVL_OP_##CODE)
 
 /* For FUNCTION_DECLs: nonzero means that this function is a
    constructor or a destructor with an extra in-charge parameter to
@@ -5526,7 +5524,8 @@ extern GTY(()) unsigned char ovl_op_mapping[MAX_TREE_CODES];
 extern GTY(()) unsigned char ovl_op_alternate[OVL_OP_MAX];
 
 /* Given an ass_op_p boolean and a tree code, return a pointer to its
-   overloaded operator info.  */
+   overloaded operator info.  Tree codes for non-overloaded operators
+   map to the error-operator.  */
 #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
index f43c960c939d03577816fca3a011a4848e3d4cba..d544d068cd2b2cfe89ad63d6f53445c7c22a4b80 100644 (file)
@@ -1920,8 +1920,8 @@ next_arg:;
       DECL_OVERRIDE_P (newdecl) |= DECL_OVERRIDE_P (olddecl);
       DECL_THIS_STATIC (newdecl) |= DECL_THIS_STATIC (olddecl);
       if (DECL_OVERLOADED_OPERATOR_P (olddecl))
-       DECL_OVERLOADED_OPERATOR_CODE (newdecl)
-         = DECL_OVERLOADED_OPERATOR_CODE (olddecl);
+       DECL_OVERLOADED_OPERATOR_CODE_RAW (newdecl)
+         = DECL_OVERLOADED_OPERATOR_CODE_RAW (olddecl);
       new_defines_function = DECL_INITIAL (newdecl) != NULL_TREE;
 
       /* Optionally warn about more than one declaration for the same
@@ -4444,7 +4444,8 @@ build_library_fn (tree name, enum tree_code operator_code, tree type,
   DECL_EXTERNAL (fn) = 1;
   TREE_PUBLIC (fn) = 1;
   DECL_ARTIFICIAL (fn) = 1;
-  DECL_OVERLOADED_OPERATOR_CODE (fn) = operator_code;
+  DECL_OVERLOADED_OPERATOR_CODE_RAW (fn)
+    = OVL_OP_INFO (false, operator_code)->ovl_op_code;
   SET_DECL_LANGUAGE (fn, lang_c);
   /* Runtime library routines are, by definition, available in an
      external shared object.  */
@@ -12902,7 +12903,7 @@ grok_op_properties (tree decl, bool complain)
       operator_code = ovl_op->tree_code;
       op_flags = ovl_op->flags;
       gcc_checking_assert (operator_code != ERROR_MARK);
-      DECL_OVERLOADED_OPERATOR_CODE (decl) = operator_code;
+      DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
     }
 
   if (op_flags & OVL_OP_FLAG_ALLOC)
@@ -13046,7 +13047,7 @@ grok_op_properties (tree decl, bool complain)
          const ovl_op_info_t *ovl_op = &ovl_op_info[false][alt];
          gcc_checking_assert (ovl_op->flags == OVL_OP_FLAG_UNARY);
          operator_code = ovl_op->tree_code;
-         DECL_OVERLOADED_OPERATOR_CODE (decl) = operator_code;
+         DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op->ovl_op_code;
        }
       else if (arity != 2)
        {
index 27530f98f8f7e04763f8c0e9b6b1334c1c0f4546..e40082f8a58695f37211718350a47da5512daa8b 100644 (file)
@@ -1321,8 +1321,8 @@ write_unqualified_name (tree decl)
       else if (DECL_OVERLOADED_OPERATOR_P (decl))
        {
          const char *mangled_name
-           = (OVL_OP_INFO (DECL_ASSIGNMENT_OPERATOR_P (decl),
-              DECL_OVERLOADED_OPERATOR_CODE (decl))->mangled_name);
+           = (ovl_op_info[DECL_ASSIGNMENT_OPERATOR_P (decl)]
+              [DECL_OVERLOADED_OPERATOR_CODE_RAW (decl)].mangled_name);
          write_string (mangled_name);
        }
       else if (UDLIT_OPER_P (DECL_NAME (decl)))
index 034431d20850bc898032a629db2d8d10b8314fd6..714b50879910f516538997af607b0e10af0fe04d 100644 (file)
@@ -2078,7 +2078,7 @@ implicitly_declare_fn (special_function_kind kind, tree type,
 
   if (!IDENTIFIER_CDTOR_P (name))
     /* Assignment operator.  */
-    DECL_OVERLOADED_OPERATOR_CODE (fn) = NOP_EXPR;
+    DECL_OVERLOADED_OPERATOR_CODE_RAW (fn) = OVL_OP_NOP_EXPR;
   else if (IDENTIFIER_CTOR_P (name))
     DECL_CXX_CONSTRUCTOR_P (fn) = true;
   else
index 285d8d2fb11181015505c3d04a35b04bad0ee978..0e3ea1a1edf4b8a6de1e7649da4cfee3c9b9f3bc 100644 (file)
@@ -9074,9 +9074,8 @@ 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_CODE (current_function_decl) == NEW_EXPR
-         || (DECL_OVERLOADED_OPERATOR_CODE (current_function_decl)
-             == VEC_NEW_EXPR))
+      && (DECL_OVERLOADED_OPERATOR_IS (current_function_decl,  NEW_EXPR)
+         || DECL_OVERLOADED_OPERATOR_IS (current_function_decl, VEC_NEW_EXPR))
       && !TYPE_NOTHROW_P (TREE_TYPE (current_function_decl))
       && ! flag_check_new
       && retval && null_ptr_cst_p (retval))
index 70998bcddacc5411cb4a1856873fcc6187fecf32..2194aa8a5a4d112a7968d2e40df05b4709dc0a1e 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-01  Nathan Sidwell  <nathan@acm.org>
+
+       * libcp1plugin.cc (plugin_build_decl): Use
+       DECL_OVERLOADED_OPERATOR_CODE_RAW.
+
 2017-10-31  Nathan Sidwell  <nathan@acm.org>
 
        * libcp1plugin.cc (plugin_build_decl): Use ovl_op_identifier.
index d83521ec176e6f06fa1f446aa68e8fb2427eb37c..030721340c1066cbd1a08822bbfd75beca77fc00 100644 (file)
@@ -1412,7 +1412,7 @@ plugin_build_decl (cc1_plugin::connection *self,
        DECL_CXX_DESTRUCTOR_P (decl) = 1;
       else if ((sym_flags & GCC_CP_FLAG_SPECIAL_FUNCTION)
               && opcode != ERROR_MARK)
-       DECL_OVERLOADED_OPERATOR_CODE (decl) = opcode;
+       DECL_OVERLOADED_OPERATOR_CODE_RAW (decl) = ovl_op_mapping[opcode];
     }
   else if (RECORD_OR_UNION_CODE_P (code))
     {