diff mbox

[libcp1] handle anon aggregates linkage-named by typedefs

Message ID oro9wuurx2.fsf@lxoliva.fsfla.org
State New
Headers show

Commit Message

Alexandre Oliva March 21, 2017, 11:32 p.m. UTC
GDB has had a work-around that uses the typedef name as the name of an
anonymous class, struct or union, when introducing them through libcc1's
C++ API.  It didn't do that for enums, that remained anonymous, and GCC
warned about using types without linkage as members of types with
linkage, which enabled us to catch the shortcoming in libcc1.

Now GDB can introduce all anonymous aggregate types without a name, and
then introduce their names through typedefs, so as to get the expected
language behavior for typedef-named anonymous types.

Ok to install?  Regression-tested with GDB's gdb.compile tests in the
users/pmuldoon/c++compile branch.


Arrange for the first typedef to an anonymous type in the same context
to be used as the linkage name for the type.

for  libcc1/ChangeLog

	* libcp1plugin.cc (plugin_build_decl): Propagate typedef name to
	anonymous aggregate target type.
---
 libcc1/libcp1plugin.cc |   19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

Comments

Alexandre Oliva April 7, 2017, 6:34 p.m. UTC | #1
Ping?  https://gcc.gnu.org/ml/gcc-patches/2017-03/msg01143.html

On Mar 21, 2017, Alexandre Oliva <aoliva@redhat.com> wrote:

> for  libcc1/ChangeLog
> 	* libcp1plugin.cc (plugin_build_decl): Propagate typedef name to
> 	anonymous aggregate target type.
Jeff Law April 10, 2017, 3:46 p.m. UTC | #2
On 03/21/2017 05:32 PM, Alexandre Oliva wrote:
> GDB has had a work-around that uses the typedef name as the name of an
> anonymous class, struct or union, when introducing them through libcc1's
> C++ API.  It didn't do that for enums, that remained anonymous, and GCC
> warned about using types without linkage as members of types with
> linkage, which enabled us to catch the shortcoming in libcc1.
>
> Now GDB can introduce all anonymous aggregate types without a name, and
> then introduce their names through typedefs, so as to get the expected
> language behavior for typedef-named anonymous types.
>
> Ok to install?  Regression-tested with GDB's gdb.compile tests in the
> users/pmuldoon/c++compile branch.
>
>
> Arrange for the first typedef to an anonymous type in the same context
> to be used as the linkage name for the type.
>
> for  libcc1/ChangeLog
>
> 	* libcp1plugin.cc (plugin_build_decl): Propagate typedef name to
> 	anonymous aggregate target type.
Can you put some kind of pointer in the code you copied from cp/decl.c 
so that there's some chance anyone changing that code would at least go 
look at the libcpplugin.cc copy and try to DTRT.

With that.  OK for the trunk.

jeff
diff mbox

Patch

diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc
index 545f28b9..bc448a7 100644
--- a/libcc1/libcp1plugin.cc
+++ b/libcc1/libcp1plugin.cc
@@ -1494,6 +1494,25 @@  plugin_build_decl (cc1_plugin::connection *self,
 
   set_access_flags (decl, acc_flags);
 
+  /* If this is the typedef that names an otherwise anonymous type,
+     propagate the typedef name to the type.  In normal compilation,
+     this is done in grokdeclarator.  */
+  if (sym_kind == GCC_CP_SYMBOL_TYPEDEF
+      && !template_decl_p
+      && DECL_CONTEXT (decl) == TYPE_CONTEXT (sym_type)
+      && TYPE_UNNAMED_P (sym_type))
+    {
+      for (tree t = TYPE_MAIN_VARIANT (sym_type); t; t = TYPE_NEXT_VARIANT (t))
+	if (anon_aggrname_p (TYPE_IDENTIFIER (t)))
+	  TYPE_NAME (t) = decl;
+      if (TYPE_LANG_SPECIFIC (sym_type))
+	TYPE_WAS_UNNAMED (sym_type) = 1;
+      if (TYPE_LANG_SPECIFIC (sym_type) && CLASSTYPE_TEMPLATE_INFO (sym_type))
+	DECL_NAME (CLASSTYPE_TI_TEMPLATE (sym_type))
+	  = TYPE_IDENTIFIER (sym_type);
+      reset_type_linkage (sym_type);
+    }
+
   if (sym_kind != GCC_CP_SYMBOL_TYPEDEF
       && sym_kind != GCC_CP_SYMBOL_CLASS
       && sym_kind != GCC_CP_SYMBOL_UNION