compiler: edit error messages to avoid -Wformat-diag warnings

GCC recently introduced -Wformat-diag to scrutinize GCC error messages.
It reports a number of warnings about gofrontend code, such as:

../../trunk/gcc/go/gofrontend/import.cc: In member function ‘Type* Import::type_for_index(int, const string&, size_t, bool*)’:
../../trunk/gcc/go/gofrontend/import.cc:1129:48: warning: unquoted operator ‘>=’ in format [-Wformat-diag]
 1129 |         "error in %s at %lu: bad type index %d >= %d",
      |                                                ^~

../../trunk/gcc/go/gofrontend/ast-dump.cc: In member function ‘void Ast_dump_context::dump(Gogo*, const char*)’:
../../trunk/gcc/go/gofrontend/ast-dump.cc:203:25: warning: unquoted option name ‘-fgo-dump-ast’ in format [-Wformat-diag]
  203 |     "cannot open %s:%m, -fgo-dump-ast ignored", dumpname.c_str());
      |                         ^~~~~~~~~~~~~

../../trunk/gcc/go/gofrontend/expressions.cc: In static member function ‘static Bexpression* Func_expression::get_code_pointer(Gogo*, Named_object*, Location)’:
../../trunk/gcc/go/gofrontend/expressions.cc:1350:29: warning: misspelled term ‘builtin function’ in format; use ‘built-in function’ instead [-Wformat-diag]
 1350 |     "invalid use of special builtin function %qs; must be called",
      |                             ^~~~~~~~~~~~~~~~

../../trunk/gcc/go/gofrontend/gogo.cc: In member function ‘void Gogo::add_linkname(const string&, bool, const string&, Location)’:
../../trunk/gcc/go/gofrontend/gogo.cc:2527:4: warning: unquoted sequence of 2 consecutive punctuation characters ‘//’ in format [-Wformat-diag]
 2527 |   ("%s is not a function; "
      |   ~^~~~~~~~~~~~~~~~~~~~~~~~
 2528 |    "//go:linkname is only supported for functions"),
      |    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This CL edits error messages to avoid these warnings.

Change-Id: If2f4881e9d02fefaf74efce04c63fab24845dea4
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/183497
Reviewed-by: Cherry Zhang <cherryyz@google.com>
diff --git a/go/ast-dump.cc b/go/ast-dump.cc
index 94066ca..b20f7e4 100644
--- a/go/ast-dump.cc
+++ b/go/ast-dump.cc
@@ -200,7 +200,8 @@
   if (out.fail())
     {
       go_error_at(Linemap::unknown_location(),
-		  "cannot open %s:%m, -fgo-dump-ast ignored", dumpname.c_str());
+		  "cannot open %s:%m; %<-fgo-dump-ast%> ignored",
+		  dumpname.c_str());
       return;
     }
 
diff --git a/go/expressions.cc b/go/expressions.cc
index 782899c..c9d8ea2 100644
--- a/go/expressions.cc
+++ b/go/expressions.cc
@@ -1347,7 +1347,8 @@
   if (fntype->is_builtin())
     {
       go_error_at(loc,
-		  "invalid use of special builtin function %qs; must be called",
+		  ("invalid use of special built-in function %qs; "
+		   "must be called"),
 		  no->message_name().c_str());
       return gogo->backend()->error_expression();
     }
@@ -1386,7 +1387,7 @@
 	  if (no->func_declaration_value()->type()->is_builtin())
 	    {
 	      go_error_at(this->location(),
-			  ("invalid use of special builtin function %qs; "
+			  ("invalid use of special built-in function %qs; "
 			   "must be called"),
 			  no->message_name().c_str());
 	      return gogo->backend()->error_expression();
@@ -8425,7 +8426,7 @@
 
   if (!type->in_heap())
     go_error_at(first_arg->location(),
-		"can't make slice of go:notinheap type");
+		"cannot make slice of go:notinheap type");
 
   bool is_slice = false;
   bool is_map = false;
@@ -9804,7 +9805,7 @@
 	  {
 	    if (this->code_ == BUILTIN_PRINT)
 	      go_warning_at(this->location(), 0,
-			 "no arguments for builtin function %<%s%>",
+			 "no arguments for built-in function %<%s%>",
 			 (this->code_ == BUILTIN_PRINT
 			  ? "print"
 			  : "println"));
@@ -9946,7 +9947,7 @@
 	Type* element_type = slice_type->array_type()->element_type();
 	if (!element_type->in_heap())
 	  go_error_at(args->front()->location(),
-		      "can't append to slice of go:notinheap type");
+		      "cannot append to slice of go:notinheap type");
 	if (this->is_varargs())
 	  {
 	    if (!args->back()->type()->is_slice_type()
@@ -14452,7 +14453,7 @@
 Allocation_expression::do_check_types(Gogo*)
 {
   if (!this->type_->in_heap())
-    go_error_at(this->location(), "can't heap allocate go:notinheap type");
+    go_error_at(this->location(), "cannot heap allocate go:notinheap type");
 }
 
 // Make a copy of an allocation expression.
@@ -19025,7 +19026,7 @@
 	  if (issue_error)
             {
               go_error_at(location,
-                          "floating point constant truncated to integer");
+                          "floating-point constant truncated to integer");
               this->set_invalid();
             }
 	  return false;
@@ -19113,7 +19114,8 @@
 	  if (issue_error)
             {
               this->set_invalid();
-              go_error_at(location, "complex constant truncated to float");
+              go_error_at(location,
+			  "complex constant truncated to floating-point");
             }
 	  return false;
 	}
@@ -19178,7 +19180,7 @@
 
   if (!ret && issue_error)
     {
-      go_error_at(location, "floating point constant overflow");
+      go_error_at(location, "floating-point constant overflow");
       this->set_invalid();
     }
 
diff --git a/go/go.cc b/go/go.cc
index 23acaa5..12205bd 100644
--- a/go/go.cc
+++ b/go/go.cc
@@ -92,7 +92,7 @@
 		   p != linknames->end();
 		   ++p)
 		go_error_at(p->second.loc,
-			    ("//go:linkname only allowed in Go files that "
+			    ("%<//go:linkname%> only allowed in Go files that "
 			     "import \"unsafe\""));
 	    }
 	  all_linknames.insert(linknames->begin(), linknames->end());
diff --git a/go/gogo.cc b/go/gogo.cc
index b135a69..d190ec2 100644
--- a/go/gogo.cc
+++ b/go/gogo.cc
@@ -552,7 +552,7 @@
       if (package->pkgpath() == this->pkgpath())
 	go_error_at(location,
 		    ("imported package uses same package path as package "
-		     "being compiled (see -fgo-pkgpath option)"));
+		     "being compiled (see %<-fgo-pkgpath%> option)"));
 
       this->imports_.insert(std::make_pair(filename, package));
     }
@@ -2525,7 +2525,7 @@
   else
     go_error_at(loc,
 		("%s is not a function; "
-		 "//go:linkname is only supported for functions"),
+		 "%<//go:linkname%> is only supported for functions"),
 		go_name.c_str());
 }
 
@@ -3693,7 +3693,7 @@
           if (fntype->is_builtin())
             {
 	      go_error_at(init->location(),
-			  "invalid use of special builtin function %qs; "
+			  "invalid use of special built-in function %qs; "
 			  "must be called",
 			  no->message_name().c_str());
             }
@@ -8161,7 +8161,7 @@
 	       ++p)
 	    go_error_at((*p)->location(),
 			("invalid receiver type "
-			 "(receiver must be a named type"));
+			 "(receiver must be a named type)"));
 	  return;
 	}
     }
diff --git a/go/import-archive.cc b/go/import-archive.cc
index 868def7..d5e26ce 100644
--- a/go/import-archive.cc
+++ b/go/import-archive.cc
@@ -420,7 +420,7 @@
       char* buf = new char[sizeof(hdr.ar_size) + 1];
       memcpy(buf, hdr.ar_size, sizeof(hdr.ar_size));
       go_error_at(this->location_,
-                  ("%s: malformed ar_size in entry header at %ld"
+                  ("%s: malformed size in entry header at %ld"
                    " (expected decimal, got %s)"),
                   this->filename_.c_str(), static_cast<long>(off), buf);
       delete[] buf;
@@ -434,7 +434,7 @@
       char* buf = new char[sizeof(hdr.ar_namlen) + 1];
       memcpy(buf, hdr.ar_namlen, sizeof(hdr.ar_namlen));
       go_error_at(this->location_,
-                  ("%s: malformed ar_namlen in entry header at %ld"
+                  ("%s: malformed name length in entry header at %ld"
                    " (expected decimal, got %s)"),
                   this->filename_.c_str(), static_cast<long>(off), buf);
       delete[] buf;
@@ -460,7 +460,7 @@
       char* buf = new char[sizeof(hdr.ar_nxtmem) + 1];
       memcpy(buf, hdr.ar_nxtmem, sizeof(hdr.ar_nxtmem));
       go_error_at(this->location_,
-                  ("%s: malformed ar_nxtmem in entry header at %ld"
+                  ("%s: malformed next member offset in entry header at %ld"
                    " (expected decimal, got %s)"),
                   this->filename_.c_str(), static_cast<long>(off), buf);
       delete[] buf;
@@ -655,7 +655,7 @@
 	  int nfd = open(filename.c_str(), O_RDONLY | O_BINARY);
 	  if (nfd < 0)
 	    {
-	      go_error_at(this->location_, "%s: can't open nested archive %s",
+	      go_error_at(this->location_, "%s: cannot open nested archive %s",
 			  this->filename_.c_str(), filename.c_str());
 	      return false;
 	    }
diff --git a/go/import.cc b/go/import.cc
index 2d76f75..abf0b54 100644
--- a/go/import.cc
+++ b/go/import.cc
@@ -925,7 +925,7 @@
     {
       if (!stream->saw_error())
 	go_error_at(this->location_,
-		    "error in import data at %d: expected %< %> or %<>%>'",
+		    "error in import data at %d: expected %< %> or %<>%>",
 		    stream->pos());
       stream->set_saw_error();
       stream->advance(1);
@@ -1126,7 +1126,7 @@
       if (static_cast<size_t>(index) >= this->type_offsets_.size())
 	{
 	  go_error_at(this->location_,
-		      "error in %s at %lu: bad type index %d >= %d",
+		      "error in %s at %lu: bad type index %d, max %d",
 		      input_name.c_str(),
 		      static_cast<unsigned long>(input_offset),
 		      index, static_cast<int>(this->type_offsets_.size()));
diff --git a/go/lex.cc b/go/lex.cc
index e641b7e..82fd355 100644
--- a/go/lex.cc
+++ b/go/lex.cc
@@ -1863,7 +1863,7 @@
 	    }
 	}
       if (go_name.empty() || ext_name.empty())
-	go_error_at(loc, "usage: //go:linkname localname linkname");
+	go_error_at(loc, "usage: %<//go:linkname%> localname linkname");
       else
 	{
 	  if (this->linknames_ == NULL)
diff --git a/go/parse.cc b/go/parse.cc
index e611c70..52371b2 100644
--- a/go/parse.cc
+++ b/go/parse.cc
@@ -1359,7 +1359,7 @@
     {
       if (pragmas != 0)
 	go_warning_at(this->location(), 0,
-		      "ignoring magic //go:... comment before group");
+		      "ignoring magic %<//go:...%> comment before group");
       if (!this->advance_token()->is_op(OPERATOR_RPAREN))
 	{
 	  this->list(pfn, varg, true);
@@ -1605,7 +1605,7 @@
 	    }
 	  if (pragmas != 0)
 	    go_warning_at(location, 0,
-			  "ignoring magic //go:... comment before type");
+			  "ignoring magic %<//go:...%> comment before type");
 	}
       else
 	{
@@ -1633,7 +1633,7 @@
 {
   if (pragmas != 0)
     go_warning_at(this->location(), 0,
-		  "ignoring magic //go:... comment before var");
+		  "ignoring magic %<//go:...%> comment before var");
 
   // Get the variable names.
   Typed_identifier_list til;
@@ -2383,7 +2383,7 @@
 	      if (pragma_check[i].decl_ok)
 		continue;
 	      go_warning_at(location, 0,
-			    ("ignoring magic //go:%s comment "
+			    ("ignoring magic %<//go:%s%> comment "
 			     "before declaration"),
 			    pragma_check[i].name);
 	    }
@@ -2392,7 +2392,7 @@
 	      if (pragma_check[i].func_ok)
 		continue;
 	      go_warning_at(location, 0,
-			    ("ignoring magic //go:%s comment "
+			    ("ignoring magic %<//go:%s%> comment "
 			     "before function definition"),
 			    pragma_check[i].name);
 	    }
@@ -2401,7 +2401,7 @@
 	      if (pragma_check[i].method_ok)
 		continue;
 	      go_warning_at(location, 0,
-			    ("ignoring magic //go:%s comment "
+			    ("ignoring magic %<//go:%s%> comment "
 			     "before method definition"),
 			    pragma_check[i].name);
 	    }
@@ -2602,7 +2602,7 @@
 	      return Expression::make_sink(location);
 	    else
 	      {
-		go_error_at(location, "cannot use _ as value");
+		go_error_at(location, "cannot use %<_%> as value");
 		return Expression::make_error(location);
 	      }
 	  case Named_object::NAMED_OBJECT_FUNC:
@@ -4178,7 +4178,7 @@
       if ((*pe)->is_error_expression())
 	return;
       if (op != OPERATOR_EQ && (*pe)->is_sink_expression())
-	go_error_at((*pe)->location(), "cannot use _ as value");
+	go_error_at((*pe)->location(), "cannot use %<_%> as value");
     }
   for (Expression_list::const_iterator pe = vals->begin();
        pe != vals->end();
@@ -5721,7 +5721,7 @@
 	  name = token->identifier();
 	  if (name == "_")
 	    {
-	      go_error_at(this->location(), "invalid package name _");
+	      go_error_at(this->location(), "invalid package name %<_%>");
 	      name = Gogo::erroneous_name();
 	    }
 	  this->advance_token();
@@ -5752,7 +5752,7 @@
 {
   if (pragmas != 0)
     go_warning_at(this->location(), 0,
-		  "ignoring magic //go:... comment before import");
+		  "ignoring magic %<//go:...%> comment before import");
 
   const Token* token = this->peek_token();
   Location location = token->location();
@@ -5876,7 +5876,7 @@
 {
   if (expr->is_sink_expression())
     {
-      go_error_at(expr->location(), "cannot use _ as value");
+      go_error_at(expr->location(), "cannot use %<_%> as value");
       expr = Expression::make_error(expr->location());
     }
 
diff --git a/go/statements.cc b/go/statements.cc
index 4a0116c..c095588 100644
--- a/go/statements.cc
+++ b/go/statements.cc
@@ -2168,7 +2168,7 @@
     {
       if (!ifb->saw_error())
 	go_error_at(ifb->location(),
-		    "import error: no newline after { at %lu",
+		    "import error: no newline after %<{%> at %lu",
 		    static_cast<unsigned long>(ifb->off()));
       ifb->set_saw_error();
       return NULL;