The mangled name of an unnamed type can include '.' characters, e.g.,
for an array of a named type.  This can then appear in the name used for
a hash or equality function for the type.  The code which creates the
externally visible identifier looks for '.'  characters.  In some cases
this could cause confusion about the name, and cause name collisions.
This patch to the Go frontend fixes the problem by changing the '.'
characters in a mangled name used for a type functions.  Bootstrapped
and ran Go testsuite on x86_64-unknown-linux-gnu.  Committed to
mainline.

Ian

diff -r 9481959e66ce go/types.cc
--- a/go/types.cc	Tue Jan 10 20:44:18 2012 -0800
+++ b/go/types.cc	Wed Jan 11 08:23:15 2012 -0800
@@ -1504,7 +1504,17 @@
 
   std::string base_name;
   if (name == NULL)
-    base_name = gogo->pack_hidden_name(this->mangled_name(gogo), false);
+    {
+      // Mangled names can have '.' if they happen to refer to named
+      // types in some way.  That's fine if this is simply a named
+      // type, but otherwise it will confuse the code that builds
+      // function identifiers.  Remove '.' when necessary.
+      base_name = this->mangled_name(gogo);
+      size_t i;
+      while ((i = base_name.find('.')) != std::string::npos)
+	base_name[i] = '$';
+      base_name = gogo->pack_hidden_name(base_name, false);
+    }
   else
     {
       // This name is already hidden or not as appropriate.

Reply via email to