public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Use package path with embedded builtin
@ 2022-06-28 17:25 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2022-06-28 17:25 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

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

This patch to the Go frontend changes the mangled name of a struct to
use the package path with an embedded builtin type.  The test case is
https://go.dev/cl/414235.  This fixes https://go.dev/issue/52856.
Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 2039 bytes --]

74956337e8276e5bc9524104b01c147374dd94e7
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 551ea650acf..13cb6ea4046 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-d5b4abed2f206e492890acc20738e89617ea542c
+c7238f58a26131b7611eff6f555cab02af8a623c
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/names.cc b/gcc/go/gofrontend/names.cc
index f85d84ceadf..dac7f20f5c1 100644
--- a/gcc/go/gofrontend/names.cc
+++ b/gcc/go/gofrontend/names.cc
@@ -831,15 +831,28 @@ Struct_type::do_mangled_name(Gogo* gogo, std::string* ret,
 	      ret->push_back(' ');
 	    }
 
-	  // For an anonymous field with an alias type, the field name
-	  // is the alias name.
-	  if (p->is_anonymous()
-	      && p->type()->named_type() != NULL
-	      && p->type()->named_type()->is_alias())
-	    p->type()->named_type()->append_symbol_type_name(gogo, true, ret,
-							     is_non_identifier);
+	  const Type* ft = p->type();
+	  const Named_type* nt = ft->named_type();
+
+	  if (p->is_anonymous() && nt != NULL && nt->is_builtin())
+	    {
+	      // For an embedded field with a builtin type, we must
+	      // include a package path.  Otherwise embedding builtin
+	      // types in different packages will produce identical
+	      // types, which shouldn't happen because the builtin
+	      // types are not exported.
+	      ret->append(gogo->pkgpath());
+	      ret->push_back('.');
+	      nt->append_symbol_type_name(gogo, true, ret, is_non_identifier);
+	    }
+	  else if (p->is_anonymous() && nt != NULL && nt->is_alias())
+	    {
+	      // For an anonymous field with an alias type, the field name
+	      // is the alias name.
+	      nt->append_symbol_type_name(gogo, true, ret, is_non_identifier);
+	    }
 	  else
-	    this->append_mangled_name(p->type(), gogo, ret, is_non_identifier);
+	    this->append_mangled_name(ft, gogo, ret, is_non_identifier);
 
 	  if (p->has_tag())
 	    {

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

only message in thread, other threads:[~2022-06-28 17:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28 17:25 Go patch committed: Use package path with embedded builtin 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).