From 0df5fa66b668795d65cdc45c8a5c8969fd56d1b9 Mon Sep 17 00:00:00 2001 From: Nikhil Benesch Date: Sun, 13 Dec 2020 23:37:11 -0800 Subject: -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. --- gcc/godump.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'gcc/godump.c') 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; -- cgit v1.1