[libcp1] handle anon aggregates linkage-named by typedefs

Alexandre Oliva aoliva@redhat.com
Tue Mar 21 23:33:00 GMT 2017


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(+)

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

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist|Red Hat Brasil GNU Toolchain Engineer



More information about the Gcc-patches mailing list