diff options
Diffstat (limited to 'gcc/go/gofrontend/lex.cc')
-rw-r--r-- | gcc/go/gofrontend/lex.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc index af23e9b..d46334f 100644 --- a/gcc/go/gofrontend/lex.cc +++ b/gcc/go/gofrontend/lex.cc @@ -866,6 +866,7 @@ Lex::gather_identifier() this->lineoff_ = p - this->linebuf_; const char* pnext = this->advance_one_utf8_char(p, &ci, &issued_error); + bool is_invalid = false; if (!Lex::is_unicode_letter(ci) && !Lex::is_unicode_digit(ci)) { // There is no valid place for a non-ASCII character @@ -876,6 +877,7 @@ Lex::gather_identifier() error_at(this->location(), "invalid character 0x%x in identifier", ci); + is_invalid = true; } if (is_first) { @@ -887,6 +889,8 @@ Lex::gather_identifier() buf.assign(pstart, p - pstart); has_non_ascii_char = true; } + if (is_invalid && !Lex::is_invalid_identifier(buf)) + buf.append("$INVALID$"); p = pnext; char ubuf[50]; // This assumes that all assemblers can handle an identifier @@ -2312,3 +2316,13 @@ Lex::is_exported_name(const std::string& name) return Lex::is_unicode_uppercase(ci); } } + +// Return whether the identifier NAME contains an invalid character. +// This is based on how we handle invalid characters in +// gather_identifier. + +bool +Lex::is_invalid_identifier(const std::string& name) +{ + return name.find("$INVALID$") != std::string::npos; +} |