public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: [C++ PATCH] simplify clone predicate
Date: Sun, 15 Sep 2019 12:23:00 -0000	[thread overview]
Message-ID: <eca3f817-817e-fd3b-09cb-1e9f3401c952@acm.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]

This patch replaces the decl_cloned_function_p function call with simpler macro 
uses.  As only cdtors are cloned, we can use IDENTIFIER_CDTOR_P to check.

In the process I discovered the documentation had bitrotted -- we were giving 
non-function_decls to the predicate, sometimes intentionally (template_decls), 
and sometimes unintentionally (record_types).  The new semantics are we can give 
  any _decl to the predicate and only function_decls to the accessor.  The 
change in pt.d is because at namespace scope, we chain record_types (&enums & 
unions) on the chain list.  Previously that was harmless but now causes the 
predicate to assert.

Applying to trunk.

nathan
-- 
Nathan Sidwell

[-- Attachment #2: clone-1.diff --]
[-- Type: text/x-patch, Size: 4091 bytes --]

2019-09-15  Nathan Sidwell  <nathan@acm.org>

	* cp-tree.h (DECL_CLONED_FUNCTION_P): Reimplement using
	IDENTIFIER_CDTOR_P, correct documentation.
	(DECL_CLONED_FUNCTION): Directly access field.
	(decl_cloned_function_p): Delete.
	* class.c (decl_cloned_function_p): Delete.
	* pt.c (instantiate_template_1): Check DECL_CHAIN is a decl.

Index: gcc/cp/class.c
===================================================================
--- gcc/cp/class.c	(revision 275726)
+++ gcc/cp/class.c	(working copy)
@@ -4701,43 +4701,6 @@ build_clone (tree fn, tree name)
   return clone;
 }
 
-/* Implementation of DECL_CLONED_FUNCTION and DECL_CLONED_FUNCTION_P, do
-   not invoke this function directly.
-
-   For a non-thunk function, returns the address of the slot for storing
-   the function it is a clone of.  Otherwise returns NULL_TREE.
-
-   If JUST_TESTING, looks through TEMPLATE_DECL and returns NULL if
-   cloned_function is unset.  This is to support the separate
-   DECL_CLONED_FUNCTION and DECL_CLONED_FUNCTION_P modes; using the latter
-   on a template makes sense, but not the former.  */
-
-tree *
-decl_cloned_function_p (const_tree decl, bool just_testing)
-{
-  tree *ptr;
-  if (just_testing)
-    decl = STRIP_TEMPLATE (decl);
-
-  if (TREE_CODE (decl) != FUNCTION_DECL
-      || !DECL_LANG_SPECIFIC (decl)
-      || DECL_LANG_SPECIFIC (decl)->u.fn.thunk_p)
-    {
-#if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007)
-      if (!just_testing)
-	lang_check_failed (__FILE__, __LINE__, __FUNCTION__);
-      else
-#endif
-	return NULL;
-    }
-
-  ptr = &DECL_LANG_SPECIFIC (decl)->u.fn.u5.cloned_function;
-  if (just_testing && *ptr == NULL_TREE)
-    return NULL;
-  else
-    return ptr;
-}
-
 /* Produce declarations for all appropriate clones of FN.  If
    UPDATE_METHODS is true, the clones are added to the
    CLASSTYPE_MEMBER_VEC.  */
Index: gcc/cp/cp-tree.h
===================================================================
--- gcc/cp/cp-tree.h	(revision 275726)
+++ gcc/cp/cp-tree.h	(working copy)
@@ -2874,13 +2874,17 @@ struct GTY(()) lang_decl {
   (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (NODE)            \
    || DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (NODE))
 
-/* Nonzero if NODE (a FUNCTION_DECL) is a cloned constructor or
+/* Nonzero if NODE (a _DECL) is a cloned constructor or
    destructor.  */
-#define DECL_CLONED_FUNCTION_P(NODE) (!!decl_cloned_function_p (NODE, true))
+#define DECL_CLONED_FUNCTION_P(NODE)		\
+  (DECL_NAME (NODE)				\
+   && IDENTIFIER_CDTOR_P (DECL_NAME (NODE))	\
+   && !DECL_MAYBE_IN_CHARGE_CDTOR_P (NODE))
 
 /* If DECL_CLONED_FUNCTION_P holds, this is the function that was
    cloned.  */
-#define DECL_CLONED_FUNCTION(NODE) (*decl_cloned_function_p (NODE, false))
+#define DECL_CLONED_FUNCTION(NODE)		\
+  (DECL_LANG_SPECIFIC (FUNCTION_DECL_CHECK (NODE))->u.fn.u5.cloned_function)
 
 /* Perform an action for each clone of FN, if FN is a function with
    clones.  This macro should be used like:
@@ -6333,7 +6337,6 @@ extern void check_abi_tags			(tree);
 extern tree missing_abi_tags			(tree);
 extern void fixup_type_variants			(tree);
 extern void fixup_attribute_variants		(tree);
-extern tree* decl_cloned_function_p		(const_tree, bool);
 extern void clone_function_decl			(tree, bool);
 extern void adjust_clone_args			(tree);
 extern void deduce_noexcept_on_destructor       (tree);
Index: gcc/cp/pt.c
===================================================================
--- gcc/cp/pt.c	(revision 275726)
+++ gcc/cp/pt.c	(working copy)
@@ -19905,8 +19905,9 @@ instantiate_template_1 (tree tmpl, tree
      instantiate all the alternate entry points as well.  We do this
      by cloning the instantiation of the main entry point, not by
      instantiating the template clones.  */
-  if (DECL_CHAIN (gen_tmpl) && DECL_CLONED_FUNCTION_P (DECL_CHAIN (gen_tmpl)))
-    clone_function_decl (fndecl, /*update_methods=*/false);
+  if (tree chain = DECL_CHAIN (gen_tmpl))
+    if (DECL_P (chain) && DECL_CLONED_FUNCTION_P (chain))
+      clone_function_decl (fndecl, /*update_methods=*/false);
 
   if (!access_ok)
     {

                 reply	other threads:[~2019-09-15 12:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eca3f817-817e-fd3b-09cb-1e9f3401c952@acm.org \
    --to=nathan@acm.org \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).