{
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, "// ");
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;
/* { dg-final { scan-file godump-1.out "(?n)^const _ET1 = 0$" } } */
/* { dg-final { scan-file godump-1.out "(?n)^const _ET2 = 1$" } } */
+typedef enum e_t_idem_v1 { ETIV1 } e_t_idem_v1;
+/* { dg-final { scan-file godump-1.out "(?n)^type _e_t_idem_v1 u?int\[0-9\]*$" } } */
+/* { dg-final { scan-file godump-1.out "(?n)^const _ETIV1 = 0$" } } */
+
+typedef enum e_t_idem_v2 e_t_idem_v2;
+enum e_t_idem_v2 { ETIV2 };
+/* { dg-final { scan-file godump-1.out "(?n)^type _e_t_idem_v2 u?int\[0-9\]*$" } } */
+/* { dg-final { scan-file godump-1.out "(?n)^const _ETIV2 = 0$" } } */
+
enum { ETV1, ETV2 } et_v1;
/* { dg-final { scan-file godump-1.out "(?n)^var _et_v1 u?int\[0-9\]*$" } } */
/* { dg-final { scan-file godump-1.out "(?n)^const _ETV1 = 0$" } } */
struct s_fwd { };
/* { dg-final { scan-file godump-1.out "(?n)^type _s_fwd struct \{ \}$" } } */
+typedef struct s_t_idem_v1 {} s_t_idem_v1;
+/* { dg-final { scan-file godump-1.out "(?n)^type _s_t_idem_v1 struct \{ \}$" } } */
+
+typedef struct s_t_idem_v2 s_t_idem_v2;
+struct s_t_idem_v2 { };
+/* { dg-final { scan-file godump-1.out "(?n)^type _s_t_idem_v2 struct \{ \}$" } } */
+
/*** nested structs ***/
typedef struct { struct { uint8_t ca[3]; } s; uint32_t i; } tsn;
/* { dg-final { scan-file godump-1.out "(?n)^type _tsn struct \{ s struct \{ ca \\\[2\\+1\\\]uint8; \}; i uint32; \}$" } } */
union { } ue;
/* { dg-final { scan-file godump-1.out "(?n)^var _ue struct \{ \}$" } } */
+typedef union u_t_idem_v1 { } u_t_idem_v1;
+/* { dg-final { scan-file godump-1.out "(?n)^type _u_t_idem_v1 struct \{ \}$" } } */
+
+typedef union u_t_idem_v2 u_t_idem_v2;
+union u_t_idem_v2 { };
+/* { dg-final { scan-file godump-1.out "(?n)^type _u_t_idem_v2 struct \{ \}$" } } */
+
typedef union { uint8_t c; uint64_t l; } tu1;
/* { dg-final { scan-file godump-1.out "(?n)^type _tu1 struct \{ c uint8; Godump_0_pad \\\[.\\\]byte; Godump_1_align \\\[0\\\]u?int64; \}$" } } */