aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2016-12-22 23:05:02 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2016-12-22 23:05:02 +0000
commit839a896d5b99530d3ff55ce53f8748d73478354a (patch)
treed89a2a32fc4fe6b2ca04d0ad5487f72a348c05bb /gcc/go
parent27d5c203f975b1242371f48397c061b5fc85166c (diff)
compiler: fix spurious redefinition error for anon struct
Change Struct_type::do_mangled_name to incorporate the field names even for hidden symbols. This is needed in cases where a package imports a type "S" that has an anonymous struct, e.g. // imported from some other package type S struct { X struct{ _ struct{} } } and then defines a local type that uses a structurally identical anonymous struct, e.g. // defined locally type T struct { U struct{ _ struct{} } } In the case above both types triggered the creation of hash/equal methods, but the method names were clashing (since both structs had the same mangled name). Fixes golang/go#18414 Reviewed-on: https://go-review.googlesource.com/34621 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@243899 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/gogo.h21
-rw-r--r--gcc/go/gofrontend/types.cc31
3 files changed, 28 insertions, 26 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index b8468965dba..b9c62808b67 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-4a0bb435bbb1d1516b486d1998e8dc184576db61
+9a89f32811e6b3a29e22dda46e9c23811f562876
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/gogo.h b/gcc/go/gofrontend/gogo.h
index 23d1f08a59a..905f48d233d 100644
--- a/gcc/go/gofrontend/gogo.h
+++ b/gcc/go/gofrontend/gogo.h
@@ -202,6 +202,27 @@ class Gogo
}
// Given a name which may or may not have been hidden, return the
+ // name to use within a mangled symbol name.
+ static std::string
+ mangle_possibly_hidden_name(const std::string& name)
+ {
+ // FIXME: This adds in pkgpath twice for hidden symbols, which is
+ // less than ideal.
+ std::string n;
+ if (!Gogo::is_hidden_name(name))
+ n = name;
+ else
+ {
+ n = ".";
+ std::string pkgpath = Gogo::hidden_name_pkgpath(name);
+ n.append(Gogo::pkgpath_for_symbol(pkgpath));
+ n.append(1, '.');
+ n.append(Gogo::unpack_hidden_name(name));
+ }
+ return n;
+ }
+
+ // Given a name which may or may not have been hidden, return the
// name to use in an error message.
static std::string
message_name(const std::string& name);
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index e03201e2522..93d7d807aa8 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -1337,18 +1337,8 @@ Type::type_descriptor_var_name(Gogo* gogo, Named_type* nt)
}
}
- // FIXME: This adds in pkgpath twice for hidden symbols, which is
- // pointless.
- const std::string& name(no->name());
- if (!Gogo::is_hidden_name(name))
- ret.append(name);
- else
- {
- ret.append(1, '.');
- ret.append(Gogo::pkgpath_for_symbol(Gogo::hidden_name_pkgpath(name)));
- ret.append(1, '.');
- ret.append(Gogo::unpack_hidden_name(name));
- }
+ std::string mname(Gogo::mangle_possibly_hidden_name(no->name()));
+ ret.append(mname);
return ret;
}
@@ -5638,8 +5628,9 @@ Struct_type::do_mangled_name(Gogo* gogo, std::string* ret) const
if (p->is_anonymous())
ret->append("0_");
else
- {
- std::string n = Gogo::unpack_hidden_name(p->field_name());
+ {
+
+ std::string n(Gogo::mangle_possibly_hidden_name(p->field_name()));
char buf[20];
snprintf(buf, sizeof buf, "%u_",
static_cast<unsigned int>(n.length()));
@@ -8712,17 +8703,7 @@ Interface_type::do_mangled_name(Gogo* gogo, std::string* ret) const
{
if (!p->name().empty())
{
- std::string n;
- if (!Gogo::is_hidden_name(p->name()))
- n = p->name();
- else
- {
- n = ".";
- std::string pkgpath = Gogo::hidden_name_pkgpath(p->name());
- n.append(Gogo::pkgpath_for_symbol(pkgpath));
- n.append(1, '.');
- n.append(Gogo::unpack_hidden_name(p->name()));
- }
+ std::string n(Gogo::mangle_possibly_hidden_name(p->name()));
char buf[20];
snprintf(buf, sizeof buf, "%u_",
static_cast<unsigned int>(n.length()));