From a23b33a1bdeff7bc2289d9ebb7cb7b7ec0a605f5 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Mon, 6 Mar 2023 15:33:45 -0500 Subject: c++: lambda mangling alias issues [PR107897] In 107897, by the time we are looking at the mangling clash, the alias has already been removed from the symbol table by analyze_functions, so we can't look at n->cpp_implicit_alias. So just assume that it's an alias if it's internal. In 108887 the problem is that removing the mangling alias from the symbol table confuses analyze_functions, because it ended up as first_analyzed somehow, so it becomes a dangling pointer. So instead we call reset() to neutralize the alias. To make this work for variables, I needed to move reset() from cgraph_node to symtab_node. PR c++/107897 PR c++/108887 gcc/ChangeLog: * cgraph.h: Move reset() from cgraph_node to symtab_node. * cgraphunit.cc (symtab_node::reset): Adjust. Also call remove_from_same_comdat_group. gcc/cp/ChangeLog: * decl2.cc (record_mangling): Use symtab_node::reset. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-lambda3.C: Use -flto if supported. * g++.dg/cpp0x/lambda/lambda-mangle7.C: New test. --- gcc/cgraphunit.cc | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) (limited to 'gcc/cgraphunit.cc') diff --git a/gcc/cgraphunit.cc b/gcc/cgraphunit.cc index e12764f..bccd2f2 100644 --- a/gcc/cgraphunit.cc +++ b/gcc/cgraphunit.cc @@ -378,21 +378,15 @@ symbol_table::process_new_functions (void) inlined in others. ??? It may make more sense to use one body for inlining and other - body for expanding the function but this is difficult to do. */ + body for expanding the function but this is difficult to do. + + This is also used to cancel C++ mangling aliases, which can be for + functions or variables. */ void -cgraph_node::reset (void) +symtab_node::reset (void) { - /* If process is set, then we have already begun whole-unit analysis. - This is *not* testing for whether we've already emitted the function. - That case can be sort-of legitimately seen with real function redefinition - errors. I would argue that the front end should never present us with - such a case, but don't enforce that for now. */ - gcc_assert (!process); - /* Reset our data structures so we can analyze the function again. */ - inlined_to = NULL; - memset (&rtl, 0, sizeof (rtl)); analyzed = false; definition = false; alias = false; @@ -400,8 +394,22 @@ cgraph_node::reset (void) weakref = false; cpp_implicit_alias = false; - remove_callees (); remove_all_references (); + remove_from_same_comdat_group (); + + if (cgraph_node *cn = dyn_cast (this)) + { + /* If process is set, then we have already begun whole-unit analysis. + This is *not* testing for whether we've already emitted the function. + That case can be sort-of legitimately seen with real function + redefinition errors. I would argue that the front end should never + present us with such a case, but don't enforce that for now. */ + gcc_assert (!cn->process); + + memset (&cn->rtl, 0, sizeof (cn->rtl)); + cn->inlined_to = NULL; + cn->remove_callees (); + } } /* Return true when there are references to the node. INCLUDE_SELF is -- cgit v1.1