I'm submitting a patch for an issue that doesn't appear to have been
reported yet. The -fdump-go-spec flag currently mishandles the following
C code:

    typedef struct s *sp;
    struct s {};

These are the Go declarations that are generated:

    type sp *struct{}
    type s s

Whereas these are the Go declarations that I would expect to be generated:

    type sp *s
    type s struct{}

The enclosed patch fixes the issue.

A note on the context for this change. I am attempting to port gccgo to
Darwin, where the system header files include a C declaration of this
form, i.e., one that is currently mishandled by -fdump-go-spec. This
results in the build getting stuck in libgo/mksysinfo.sh.

2018-11-22  Nikhil Benesch  <nikhil.bene...@gmail.com>

        * gcc/godump.c (go_output_typedef): When outputting a typedef, use
        the refer to the underlying type by its name and not its structure.
        This is necessary when the typedef occurs before the definition of
        an element of the underlying type.
        * gcc.misc-tests/godump-1.c: Add test cases for the new behavior.

---
 godump.c                            |    2 +-
 testsuite/gcc.misc-tests/godump-1.c |    5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)

Index: gcc/godump.c
===================================================================
--- gcc/godump.c        (revision 266365)
+++ gcc/godump.c        (working copy)
@@ -1181,7 +1181,7 @@
        return;
       *slot = CONST_CAST (void *, (const void *) type);

-      if (!go_format_type (container, TREE_TYPE (decl), false, false, NULL,
+      if (!go_format_type (container, TREE_TYPE (decl), true, false, NULL,
                           false))
        {
          fprintf (go_dump_file, "// ");
Index: gcc/testsuite/gcc.misc-tests/godump-1.c
===================================================================
--- gcc/testsuite/gcc.misc-tests/godump-1.c     (revision 266365)
+++ gcc/testsuite/gcc.misc-tests/godump-1.c     (working copy)
@@ -468,7 +468,12 @@

 typedef struct s_undef_t s_undef_t2;

+typedef struct s_fwd *s_fwd_p;
+/* { dg-final { scan-file godump-1.out "(?n)^type _s_fwd_p \\*_s_fwd$" } } */

+struct s_fwd { };
+/* { dg-final { scan-file godump-1.out "(?n)^type _s_fwd 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; \}$" } } */

Reply via email to