Expunge namespace-scope IDENTIFIER_TYPE_VALUE & global_type_name [PR 99039]

Nathan Sidwell nathan@acm.org
Fri Feb 12 21:28:44 GMT 2021


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.

-- 
Nathan Sidwell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr99040-prep.diff
Type: text/x-patch
Size: 15841 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210212/a33e5aff/attachment.bin>


More information about the Gcc-patches mailing list