aboutsummaryrefslogtreecommitdiff
path: root/gcc/godump.c
diff options
context:
space:
mode:
authorNikhil Benesch <nikhil.benesch@gmail.com>2020-12-13 23:37:11 -0800
committerIan Lance Taylor <iant@golang.org>2020-12-13 23:39:32 -0800
commit0df5fa66b668795d65cdc45c8a5c8969fd56d1b9 (patch)
tree3ba2b5eef812246e4289bfb94e8df29ed27831c0 /gcc/godump.c
parent8e56e4d9566ce99707befa88bf4d11c74ec45c10 (diff)
downloadgcc-0df5fa66b668795d65cdc45c8a5c8969fd56d1b9.zip
gcc-0df5fa66b668795d65cdc45c8a5c8969fd56d1b9.tar.gz
gcc-0df5fa66b668795d65cdc45c8a5c8969fd56d1b9.tar.bz2
-fgo-dump-spec: skip typedefs that match struct tag
gcc/: * godump.c (go_output_typedef): Suppress typedefs whose name matches the tag of the underlying struct, union, or enum. Output declarations for enums that do not appear in typedefs. gcc/testsuite: * gcc.misc-tests/godump-1.c: Add test cases.
Diffstat (limited to 'gcc/godump.c')
-rw-r--r--gcc/godump.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/gcc/godump.c b/gcc/godump.c
index 033b2c5..ff3a4a9 100644
--- a/gcc/godump.c
+++ b/gcc/godump.c
@@ -1155,15 +1155,25 @@ go_output_typedef (class godump_container *container, tree decl)
{
void **slot;
const char *type;
+ tree original_type;
type = IDENTIFIER_POINTER (DECL_NAME (decl));
+ original_type = DECL_ORIGINAL_TYPE (decl);
+
+ /* Suppress typedefs where the type name matches the underlying
+ struct/union/enum tag. This way we'll emit the struct definition
+ instead of an invalid recursive type. */
+ if (TYPE_IDENTIFIER (original_type) != NULL
+ && IDENTIFIER_POINTER (TYPE_IDENTIFIER (original_type)) == type)
+ return;
+
/* If type defined already, skip. */
slot = htab_find_slot (container->type_hash, type, INSERT);
if (*slot != NULL)
return;
*slot = CONST_CAST (void *, (const void *) type);
- if (!go_format_type (container, DECL_ORIGINAL_TYPE (decl), true, false,
+ if (!go_format_type (container, original_type, true, false,
NULL, false))
{
fprintf (go_dump_file, "// ");
@@ -1187,7 +1197,9 @@ go_output_typedef (class godump_container *container, tree decl)
container->decls_seen.add (decl);
}
- else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)))
+ else if ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
+ || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
+ && TYPE_NAME (TREE_TYPE (decl)) != NULL)
{
void **slot;
const char *type;