aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2018-01-25 23:10:35 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2018-01-25 23:10:35 +0000
commita14e122ae2ecf27a8cace7e0d1dda8606d5e4eca (patch)
treee7d8639d02f527aa3613c5443f0d7df1e358d02e /gcc
parent9aba6f77b481d555ea7c3d24911011be013dbc0b (diff)
downloadgcc-a14e122ae2ecf27a8cace7e0d1dda8606d5e4eca.zip
gcc-a14e122ae2ecf27a8cace7e0d1dda8606d5e4eca.tar.gz
gcc-a14e122ae2ecf27a8cace7e0d1dda8606d5e4eca.tar.bz2
compiler: deref receiver types in mangled names
This was the original intent, as reflected in the long comment at the start of names.cc, but I forgot to implement it. Also, remove a leading ".0" from the final name. That could occur for a method whose receiver type starts with 'u', as in that case we prepend a space to the mangled name, to avoid confusion with the Unicode mangling, and the space turns into ".0". Also, if the Unicode encoding would cause the final to start with "..u" or "..U", add a leading underscore. Patch gotest to not get fooled by some names. The result of these changes is that all symbols start with a letter or an underscore. Reviewed-on: https://go-review.googlesource.com/90015 From-SVN: r257068
Diffstat (limited to 'gcc')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/go-encode-id.cc25
-rw-r--r--gcc/go/gofrontend/names.cc13
3 files changed, 22 insertions, 18 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index adee9cc..038a8e8c 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-553e04735d1be372c596c720bcaea27e050b13a6
+203cbe7d3820fa03c965a01f72461f71588fe952
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/go-encode-id.cc b/gcc/go/gofrontend/go-encode-id.cc
index ec5c37f..e130ba1 100644
--- a/gcc/go/gofrontend/go-encode-id.cc
+++ b/gcc/go/gofrontend/go-encode-id.cc
@@ -104,6 +104,14 @@ go_encode_id(const std::string &id)
std::string ret;
const char* p = id.c_str();
const char* pend = p + id.length();
+
+ // A leading ".0" is a space introduced before a mangled type name
+ // that starts with a 'u' or 'U', to avoid confusion with the
+ // mangling used here. We don't need a leading ".0", and we don't
+ // want symbols that start with '.', so remove it.
+ if (p[0] == '.' && p[1] == '0')
+ p += 2;
+
while (p < pend)
{
unsigned int c;
@@ -115,16 +123,19 @@ go_encode_id(const std::string &id)
go_assert(!char_needs_encoding(c));
ret += c;
}
- else if (c < 0x10000)
- {
- char buf[16];
- snprintf(buf, sizeof buf, "..u%04x", c);
- ret += buf;
- }
else
{
char buf[16];
- snprintf(buf, sizeof buf, "..U%08x", c);
+ if (c < 0x10000)
+ snprintf(buf, sizeof buf, "..u%04x", c);
+ else
+ snprintf(buf, sizeof buf, "..U%08x", c);
+
+ // We don't want a symbol to start with '.', so add a prefix
+ // if needed.
+ if (ret.empty())
+ ret += '_';
+
ret += buf;
}
p += len;
diff --git a/gcc/go/gofrontend/names.cc b/gcc/go/gofrontend/names.cc
index eb18f81..2e36a1d 100644
--- a/gcc/go/gofrontend/names.cc
+++ b/gcc/go/gofrontend/names.cc
@@ -213,7 +213,7 @@ Gogo::function_asm_name(const std::string& go_name, const Package* package,
{
std::string ret;
if (rtype != NULL)
- ret = rtype->mangled_name(this);
+ ret = rtype->deref()->mangled_name(this);
else if (package == NULL)
ret = this->pkgpath_symbol();
else
@@ -892,14 +892,7 @@ Named_type::append_mangled_type_name(Gogo* gogo, bool use_alias,
const Typed_identifier* rcvr =
this->in_function_->func_value()->type()->receiver();
if (rcvr != NULL)
- {
- std::string m = rcvr->type()->mangled_name(gogo);
- // Turn a leading ".1" back into "*" since we are going
- // to type-mangle this name again.
- if (m.compare(0, 2, ".1") == 0)
- m = "*" + m.substr(2);
- ret->append(m);
- }
+ ret->append(rcvr->type()->deref()->mangled_name(gogo));
else if (this->in_function_->package() == NULL)
ret->append(gogo->pkgpath_symbol());
else
@@ -956,7 +949,7 @@ Gogo::type_descriptor_name(Type* type, Named_type* nt)
const Typed_identifier* rcvr =
in_function->func_value()->type()->receiver();
if (rcvr != NULL)
- ret.append(rcvr->type()->mangled_name(this));
+ ret.append(rcvr->type()->deref()->mangled_name(this));
else if (in_function->package() == NULL)
ret.append(this->pkgpath_symbol());
else