aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/call.c
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2021-02-11 13:06:03 -0800
committerNathan Sidwell <nathan@acm.org>2021-02-12 13:50:03 -0800
commit8f93e1b892850b00bf6b9cbc5711a7d5bc367967 (patch)
tree3bf9b0f6db39e47d52073a8eb290f1ed0360dd1f /gcc/cp/call.c
parent9769564e7456453e2273071d0faa5aab2554ff78 (diff)
downloadgcc-8f93e1b892850b00bf6b9cbc5711a7d5bc367967.zip
gcc-8f93e1b892850b00bf6b9cbc5711a7d5bc367967.tar.gz
gcc-8f93e1b892850b00bf6b9cbc5711a7d5bc367967.tar.bz2
Expunge namespace-scope IDENTIFIER_TYPE_VALUE & global_type_name [PR 99039]
IDENTIFIER_TYPE_VALUE and friends is a remnant of G++'s C origins. It holds elaborated types on identifier-nodes. While this is fine for C and for local and class-scopes in C++, it fails badly for namespaces. In that case a marker 'global_type_node' was used, which essentially signified 'this is a namespace-scope type *somewhere*', and you'd have to do a regular name_lookup to find it. As the parser and substitution machinery has avanced over the last 25 years or so, there's not much outside of actual name-lookup that uses that. Amusingly the IDENTIFIER_HAS_TYPE_VALUE predicate will do an actual name-lookup and then users would repeat that lookup to find the now-known to be there type. Rather late I realized that this interferes with the lazy loading of module entities, because we were setting IDENTIFIER_TYPE_VALUE to global_type_node. But we could be inside some local scope where that identifier is bound to some local type. Not good! Rather than add more cruft to look at an identifier's shadow stack and alter that as necessary, this takes the approach of removing the existing cruft. We nuke the few places outside of name lookup that use IDENTIFIER_TYPE_VALUE. Replacing them with either proper name lookups, alternative sequences, or in some cases asserting that they (no longer) happen. Class template instantiation was calling pushtag after setting IDENTIFIER_TYPE_VALUE in order to stop pushtag creating an implicit typedef and pushing it, but to get the bookkeeping it needed. Let's just do the bookkeeping directly. Then we can stop having a 'bound at namespace-scope' marker at all, which means lazy loading won't screw up local shadow stacks. Also, it simplifies set_identifier_type_value_with_scope, as it never needs to inspect the scope stack. When developing this patch, I discovered a number of places we'd put an actual namespace-scope type on the type_value slot, rather than global_type_node. You might notice this is killing at least two 'why are we doing this?' comments. While this doesn't fix the two PRs mentioned, it is a necessary step. PR c++/99039 PR c++/99040 gcc/cp/ * cp-tree.h (CPTI_GLOBAL_TYPE): Delete. (global_type_node): Delete. (IDENTIFIER_TYPE_VALUE): Delete. (IDENTIFIER_HAS_TYPE_VALUE): Delete. (get_type_value): Delete. * name-lookup.h (identifier_type_value): Delete. * name-lookup.c (check_module_override): Don't SET_IDENTIFIER_TYPE_VALUE here. (do_pushdecl): Nor here. (identifier_type_value_1, identifier_type_value): Delete. (set_identifier_type_value_with_scope): Only SET_IDENTIFIER_TYPE_VALUE for local and class scopes. (pushdecl_nanmespace_level): Remove shadow stack nadgering. (do_pushtag): Use REAL_IDENTIFIER_TYPE_VALUE. * call.c (check_dtor_name): Use lookup_name. * decl.c (cxx_init_decl_processing): Drop global_type_node. * decl2.c (cplus_decl_attributes): Don't SET_IDENTIFIER_TYPE_VALUE here. * init.c (get_type_value): Delete. * pt.c (instantiate_class_template_1): Don't call pushtag or SET_IDENTIFIER_TYPE_VALUE here. (tsubst): Assert never an identifier. (dependent_type_p): Drop global_type_node assert. * typeck.c (error_args_num): Don't use IDENTIFIER_HAS_TYPE_VALUE to determine ctorness. gcc/testsuite/ * g++.dg/lookup/pr99039.C: New.
Diffstat (limited to 'gcc/cp/call.c')
-rw-r--r--gcc/cp/call.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 4744c97..186feef 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -236,8 +236,15 @@ check_dtor_name (tree basetype, tree name)
|| TREE_CODE (basetype) == ENUMERAL_TYPE)
&& name == constructor_name (basetype))
return true;
- else
- name = get_type_value (name);
+
+ /* Otherwise lookup the name, it could be an unrelated typedef
+ of the correct type. */
+ name = lookup_name (name, LOOK_want::TYPE);
+ if (!name)
+ return false;
+ name = TREE_TYPE (name);
+ if (name == error_mark_node)
+ return false;
}
else
{
@@ -252,8 +259,6 @@ check_dtor_name (tree basetype, tree name)
return false;
}
- if (!name || name == error_mark_node)
- return false;
return same_type_p (TYPE_MAIN_VARIANT (basetype), TYPE_MAIN_VARIANT (name));
}