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
2019-09-15 Nathan Sidwell <nat...@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)
{