From 587bd42530cee75da83979b18bb170302c915034 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sun, 23 Jun 2019 22:10:19 +0000 Subject: [PATCH] compiler: edit error messages to avoid -Wformat-diag warnings MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/183497 * go.test/test/blank1.go: Update for diagnostic message changes. From-SVN: r272608 --- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/ast-dump.cc | 3 ++- gcc/go/gofrontend/expressions.cc | 20 +++++++++++--------- gcc/go/gofrontend/go.cc | 2 +- gcc/go/gofrontend/gogo.cc | 8 ++++---- gcc/go/gofrontend/import-archive.cc | 8 ++++---- gcc/go/gofrontend/import.cc | 4 ++-- gcc/go/gofrontend/lex.cc | 2 +- gcc/go/gofrontend/parse.cc | 22 +++++++++++----------- gcc/go/gofrontend/statements.cc | 2 +- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/go.test/test/blank1.go | 6 +++--- 12 files changed, 45 insertions(+), 38 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 1f9c94ff8f7..92d863e79cb 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -6bb63a21434b3360dbe7e4bd34889734f361d434 +1232eef628227ef855c5fa6d94b31778b2e74a85 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/ast-dump.cc b/gcc/go/gofrontend/ast-dump.cc index 94066cab8c3..b20f7e4e725 100644 --- a/gcc/go/gofrontend/ast-dump.cc +++ b/gcc/go/gofrontend/ast-dump.cc @@ -200,7 +200,8 @@ Ast_dump_context::dump(Gogo* gogo, const char* basename) 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/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 782899cc185..c9d8ea2a829 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -1347,7 +1347,8 @@ Func_expression::get_code_pointer(Gogo* gogo, Named_object* no, Location loc) 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 @@ Func_expression::do_get_backend(Translate_context* context) 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 @@ Builtin_call_expression::lower_make(Statement_inserter* inserter) 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 @@ Builtin_call_expression::do_check_types(Gogo*) { 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 @@ Builtin_call_expression::do_check_types(Gogo*) 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 @@ void 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 @@ Numeric_constant::check_int_type(Integer_type* type, bool issue_error, 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 @@ Numeric_constant::check_float_type(Float_type* type, bool issue_error, 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 @@ Numeric_constant::check_float_type(Float_type* type, bool issue_error, 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/gcc/go/gofrontend/go.cc b/gcc/go/gofrontend/go.cc index 23acaa54f56..12205bd5aa7 100644 --- a/gcc/go/gofrontend/go.cc +++ b/gcc/go/gofrontend/go.cc @@ -92,7 +92,7 @@ go_parse_input_files(const char** filenames, unsigned int filename_count, p != linknames->end(); ++p) go_error_at(p->second.loc, - ("//go:linkname only allowed in Go files that " + ("% only allowed in Go files that " "import \"unsafe\"")); } all_linknames.insert(linknames->begin(), linknames->end()); diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index b135a699e13..d190ec2f3f0 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -552,7 +552,7 @@ Gogo::import_package(const std::string& filename, 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 @@ Gogo::add_linkname(const std::string& go_name, bool is_exported, else go_error_at(loc, ("%s is not a function; " - "//go:linkname is only supported for functions"), + "% is only supported for functions"), go_name.c_str()); } @@ -3693,7 +3693,7 @@ Check_types_traverse::variable(Named_object* named_object) 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 @@ Type_declaration::define_methods(Named_type* nt) ++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/gcc/go/gofrontend/import-archive.cc b/gcc/go/gofrontend/import-archive.cc index 868def7cc75..d5e26ce22a3 100644 --- a/gcc/go/gofrontend/import-archive.cc +++ b/gcc/go/gofrontend/import-archive.cc @@ -420,7 +420,7 @@ Archive_file::read_big_archive_header(off_t off, std::string* pname, 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(off), buf); delete[] buf; @@ -434,7 +434,7 @@ Archive_file::read_big_archive_header(off_t off, std::string* pname, 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(off), buf); delete[] buf; @@ -460,7 +460,7 @@ Archive_file::read_big_archive_header(off_t off, std::string* pname, 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(off), buf); delete[] buf; @@ -655,7 +655,7 @@ Archive_file::get_file_and_offset(off_t off, const std::string& hdrname, 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/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc index 2d76f75a3de..abf0b540bd0 100644 --- a/gcc/go/gofrontend/import.cc +++ b/gcc/go/gofrontend/import.cc @@ -925,7 +925,7 @@ Import::read_type() { 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 @@ Import::type_for_index(int index, const std::string& input_name, if (static_cast(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(input_offset), index, static_cast(this->type_offsets_.size())); diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc index e641b7eaf39..82fd35580c6 100644 --- a/gcc/go/gofrontend/lex.cc +++ b/gcc/go/gofrontend/lex.cc @@ -1863,7 +1863,7 @@ Lex::skip_cpp_comment() } } if (go_name.empty() || ext_name.empty()) - go_error_at(loc, "usage: //go:linkname localname linkname"); + go_error_at(loc, "usage: % localname linkname"); else { if (this->linknames_ == NULL) diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index e611c704662..52371b2b032 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -1359,7 +1359,7 @@ Parse::decl(void (Parse::*pfn)(void*, unsigned int), void* varg, { if (pragmas != 0) go_warning_at(this->location(), 0, - "ignoring magic //go:... comment before group"); + "ignoring magic % comment before group"); if (!this->advance_token()->is_op(OPERATOR_RPAREN)) { this->list(pfn, varg, true); @@ -1605,7 +1605,7 @@ Parse::type_spec(void*, unsigned int pragmas) } if (pragmas != 0) go_warning_at(location, 0, - "ignoring magic //go:... comment before type"); + "ignoring magic % comment before type"); } else { @@ -1633,7 +1633,7 @@ Parse::var_spec(void*, unsigned int pragmas) { if (pragmas != 0) go_warning_at(this->location(), 0, - "ignoring magic //go:... comment before var"); + "ignoring magic % comment before var"); // Get the variable names. Typed_identifier_list til; @@ -2383,7 +2383,7 @@ Parse::function_decl(unsigned int pragmas) if (pragma_check[i].decl_ok) continue; go_warning_at(location, 0, - ("ignoring magic //go:%s comment " + ("ignoring magic % comment " "before declaration"), pragma_check[i].name); } @@ -2392,7 +2392,7 @@ Parse::function_decl(unsigned int pragmas) if (pragma_check[i].func_ok) continue; go_warning_at(location, 0, - ("ignoring magic //go:%s comment " + ("ignoring magic % comment " "before function definition"), pragma_check[i].name); } @@ -2401,7 +2401,7 @@ Parse::function_decl(unsigned int pragmas) if (pragma_check[i].method_ok) continue; go_warning_at(location, 0, - ("ignoring magic //go:%s comment " + ("ignoring magic % comment " "before method definition"), pragma_check[i].name); } @@ -2602,7 +2602,7 @@ Parse::operand(bool may_be_sink, bool* is_parenthesized) 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 @@ Parse::tuple_assignment(Expression_list* lhs, bool may_be_composite_lit, 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 @@ Parse::package_clause() 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 @@ Parse::import_spec(void*, unsigned int pragmas) { if (pragmas != 0) go_warning_at(this->location(), 0, - "ignoring magic //go:... comment before import"); + "ignoring magic % comment before import"); const Token* token = this->peek_token(); Location location = token->location(); @@ -5876,7 +5876,7 @@ Parse::verify_not_sink(Expression* expr) { 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/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc index 4a0116caec1..c0955888b54 100644 --- a/gcc/go/gofrontend/statements.cc +++ b/gcc/go/gofrontend/statements.cc @@ -2168,7 +2168,7 @@ Block_statement::do_import(Import_function_body* ifb, Location loc, { 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(ifb->off())); ifb->set_saw_error(); return NULL; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 70267ff246c..86865a8a122 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-06-23 Ian Lance Taylor + + * go.test/test/blank1.go: Update for diagnostic message changes. + 2019-06-23 Iain Sandoe * gcc.target/powerpc/builtins-2.c: Require VSX hardware support. diff --git a/gcc/testsuite/go.test/test/blank1.go b/gcc/testsuite/go.test/test/blank1.go index 54a72976b77..b60f9e179c4 100644 --- a/gcc/testsuite/go.test/test/blank1.go +++ b/gcc/testsuite/go.test/test/blank1.go @@ -7,7 +7,7 @@ // Test that incorrect uses of the blank identifer are caught. // Does not compile. -package _ // ERROR "invalid package name _" +package _ // ERROR "invalid package name" var t struct { _ int @@ -18,8 +18,8 @@ type T struct { } func main() { - _() // ERROR "cannot use _ as value" - x := _+1 // ERROR "cannot use _ as value" + _() // ERROR "cannot use .* as value" + x := _+1 // ERROR "cannot use .* as value" _ = x _ = t._ // ERROR "cannot refer to blank field|invalid use of" -- 2.30.2