public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Patch committed: Don't confuse -fdump-go-spec with tag/var name
@ 2011-01-11 23:37 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2011-01-11 23:37 UTC (permalink / raw)
  To: gcc-patches; +Cc: Rainer Orth

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

In C you can have a struct tag and a variable with the same name.  The
-fdump-go-spec option dumps a struct tag as a type name, but Go does not
permit a type and a variable to have the same name.  This patch avoids
the most common case of this problem by not emitting a variable if it
has already seen a type with the same name.  Bootstrapped and ran Go
testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian


2011-01-11  Ian Lance Taylor  <iant@google.com>

	* godump.c (go_output_var): Don't output the variable if there is
	already a type with the same name.



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: godump --]
[-- Type: text/x-diff, Size: 1171 bytes --]

Index: godump.c
===================================================================
--- godump.c	(revision 168682)
+++ godump.c	(working copy)
@@ -715,13 +715,27 @@ go_output_typedef (struct godump_contain
 static void
 go_output_var (struct godump_container *container, tree decl)
 {
+  bool is_valid;
+
   if (pointer_set_contains (container->decls_seen, decl)
       || pointer_set_contains (container->decls_seen, DECL_NAME (decl)))
     return;
   pointer_set_insert (container->decls_seen, decl);
   pointer_set_insert (container->decls_seen, DECL_NAME (decl));
-  if (!go_format_type (container, TREE_TYPE (decl), true, false))
+
+  is_valid = go_format_type (container, TREE_TYPE (decl), true, false);
+  if (is_valid
+      && htab_find_slot (container->type_hash,
+			 IDENTIFIER_POINTER (DECL_NAME (decl)),
+			 NO_INSERT) != NULL)
+    {
+      /* There is already a type with this name, probably from a
+	 struct tag.  Prefer the type to the variable.  */
+      is_valid = false;
+    }
+  if (!is_valid)
     fprintf (go_dump_file, "// ");
+
   fprintf (go_dump_file, "var _%s ",
 	   IDENTIFIER_POINTER (DECL_NAME (decl)));
   go_output_type (container);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-01-11 23:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-11 23:37 Patch committed: Don't confuse -fdump-go-spec with tag/var name Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).