This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[libcp1] handle anon aggregates linkage-named by typedefs
- From: Alexandre Oliva <aoliva at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: jason at redhat dot com, keiths at redhat dot com, pmuldoon at redhat dot com
- Date: Tue, 21 Mar 2017 20:32:57 -0300
- Subject: [libcp1] handle anon aggregates linkage-named by typedefs
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=aoliva at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2A7A8107BD
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2A7A8107BD
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