Commit 26fcb396 by Ian Lance Taylor

compiler: add go_debug and use it for debug messages

    
    GCC recently added a new warning -Wformat-diag which does a lot of
    rigorous checks on GCC diagnostic messages.  This produces a number of
    unnecessary diagnostics on gofrontend diagnostic output, such as
    
    ../../trunk/gcc/go/gofrontend/escape.cc: In member function ‘virtual int Escape_analysis_assign::statement(Block*, size_t*, Statement*)’:
    ../../trunk/gcc/go/gofrontend/escape.cc:1336:33: warning: spurious leading punctuation sequence ‘[’ in format [-Wformat-diag]
     1336 |       go_inform(s->location(), "[%d] %s esc: %s",
          |                                 ^
    
    ../../trunk/gcc/go/gofrontend/escape.cc: In member function ‘void Escape_analysis_assign::call(Call_expression*)’:
    ../../trunk/gcc/go/gofrontend/escape.cc:1964:17: warning: unquoted operator ‘::’ in format [-Wformat-diag]
     1964 |         "esccall:: indirect call <- %s, untracked",
          |                 ^~
    
    ../../trunk/gcc/go/gofrontend/escape.cc:1964:34: warning: unbalanced punctuation character ‘<’ in format [-Wformat-diag]
     1964 |         "esccall:: indirect call <- %s, untracked",
          |                                  ^
    
    Avoid these messages by adding a new function go_debug that uses only
    printf formatting, not GCC diagnostic formatting, and change all the
    optimization debugging messages to use it.  None of the debugging
    messages used the GCC diagnostic formatting specifiers anyhow.
    
    Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/183437

From-SVN: r272607
parent d7e96c46
9b5a43baaf391005989d140109261e5a8e1b1b63
6bb63a21434b3360dbe7e4bd34889734f361d434
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
......@@ -4026,7 +4026,7 @@ Type_conversion_expression::do_get_backend(Translate_context* context)
if (this->no_copy_)
{
if (gogo->debug_optimization())
go_inform(loc, "no copy string([]byte)");
go_debug(loc, "no copy string([]byte)");
Expression* ptr = Expression::make_slice_info(this->expr_,
SLICE_INFO_VALUE_POINTER,
loc);
......
......@@ -175,3 +175,25 @@ go_inform(const Location location, const char* fmt, ...)
go_be_inform(location, expand_message(fmt, ap));
va_end(ap);
}
// go_debug uses normal printf formatting, not GCC diagnostic formatting.
void
go_debug(const Location location, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
char* mbuf = NULL;
int nwr = vasprintf(&mbuf, fmt, ap);
va_end(ap);
if (nwr == -1)
{
go_be_error_at(Linemap::unknown_location(),
"memory allocation failed in vasprintf");
go_assert(0);
}
std::string rval = std::string(mbuf);
free(mbuf);
go_be_inform(location, rval);
}
......@@ -15,6 +15,12 @@
#define GO_ATTRIBUTE_GCC_DIAG(m, n)
#endif
#if __GNUC__ >= 3
#define GO_ATTRIBUTE_PRINTF(m, n) __attribute__ ((__format__ (__printf__, m, n))) __attribute__ ((__nonnull__ (m)))
#else
#define GO_ATTRIBUTE_PRINTF(m, n)
#endif
// These declarations define the interface through which the frontend
// reports errors and warnings. These functions accept printf-like
// format specifiers (e.g. %d, %f, %s, etc), with the following additional
......@@ -41,6 +47,12 @@ extern void go_fatal_error(const Location, const char* fmt, ...)
extern void go_inform(const Location, const char* fmt, ...)
GO_ATTRIBUTE_GCC_DIAG(2,3);
// go_debug is used to report a debugging message at a location. This
// uses standard printf formatting.
extern void go_debug(const Location, const char* fmt, ...)
GO_ATTRIBUTE_PRINTF(2, 3);
// These interfaces provide a way for the front end to ask for
// the open/close quote characters it should use when formatting
// diagnostics (warnings, errors).
......
......@@ -6085,7 +6085,7 @@ For_range_statement::do_lower(Gogo* gogo, Named_object*, Block* enclosing,
if (clear != NULL)
{
if (gogo->debug_optimization())
go_inform(loc, "map range clear");
go_debug(loc, "map range clear");
temp_block->add_statement(clear);
return Statement::make_block_statement(temp_block, loc);
}
......@@ -6102,7 +6102,7 @@ For_range_statement::do_lower(Gogo* gogo, Named_object*, Block* enclosing,
if (clear != NULL)
{
if (gogo->debug_optimization())
go_inform(loc, "array range clear");
go_debug(loc, "array range clear");
temp_block->add_statement(clear);
return Statement::make_block_statement(temp_block, loc);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment