Looks like I broke the build with
r16-3091-gac4e7455a33237 on hosts
where unsigned == size_t.
../../gcc/gcc/diagnostics/dumping.cc:98:1: error: redefinition of ‘void diagnostics::dumping::emit_field(FILE*, int, const char*, T) [with T = unsigned int; FILE = FILE]’
98 | emit_field<unsigned> (FILE *outfile, int indent,
| ^~~~~~~~~~~~~~~~~~~~
../../gcc/gcc/diagnostics/dumping.cc:80:1: note: ‘void diagnostics::dumping::emit_field(FILE*, int, const char*, T) [with T = unsigned int; FILE = FILE]’ previously declared here
80 | emit_field<size_t> (FILE *outfile, int indent,
| ^~~~~~~~~~~~~~~~~~
Sorry about this.
Should be fixed by the following patch, which avoids templates here
in favor of being explicit about types, avoids the use of "%zi" with
fprintf in various places, and fixes some other minor issues in the
dumping logic that I noticed whilst testing the patch.
gcc/ChangeLog:
* diagnostics/context.cc (context::dump): Bulletproof against
m_reference_printer being null.
* diagnostics/dumping.cc (emit_field<const char *>): Replace
with...
(emit_string_field): ...this.
(emit_field<char *>): Eliminate.
(emit_field<bool>): Replace with...
(emit_bool_field): ...this.
(emit_field<size_t>): Replace with...
(emit_size_t_field): ...this, and use HOST_SIZE_T_PRINT_DEC rather
than %zi in fprintf call.
(emit_field<int>): Replace with...
(emit_int_field): ...this.
(emit_field<unsigned>): Replace with...
(emit_unsigned_field): ...this.
* diagnostics/dumping.h (emit_field): Replace this template decl
with...
(emit_string_field): ...this,
(emit_bool_field): ...this,
(emit_size_t_field): ...this,
(emit_int_field): ...this,
(emit_unsigned_field): ... and this.
(DIAGNOSTICS_DUMPING_EMIT_FIELD): Rename to...
(DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD): ...this and update for
above change.
* diagnostics/file-cache.cc (file_cache_slot::dump): Replace
emit_field calls with calls that explicitly state the type. Fix
type of dump of m_missing_trailing_newline to use bool.
(file_cache_slot::dump): Use HOST_SIZE_T_PRINT_DEC rather than
%zi in fprintf call.
* diagnostics/html-sink.cc (html_generation_options::dump): Update
for macro renaming.
* diagnostics/sarif-sink.cc
(sarif_serialization_format_json::dump): Likewise.
(sarif_generation_options::dump): Likewise, and for function
renaming.
* diagnostics/text-sink.cc (text_sink::dump): Update for macro
renaming.
* libgdiagnostics.cc (diagnostic_manager_debug_dump_file): Use
HOST_SIZE_T_PRINT_DEC rather than %zi in fprintf call.
* pretty-print.cc: Include "diagnostics/dumping.h".
(pp_formatted_chunks::dump): Use it.
(get_url_format_as_string): New.
(pretty_printer::dump): Use diagnostics::dumping. Bulletproof
against m_buffer being null.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
dumping::emit_heading (outfile, 0, "diagnostics::context");
m_diagnostic_counters.dump (outfile, 2);
dumping::emit_heading (outfile, 2, "reference printer");
- m_reference_printer->dump (outfile, 4);
+ if (m_reference_printer)
+ m_reference_printer->dump (outfile, 4);
+ else
+ dumping::emit_none (outfile, 4);
dumping::emit_heading (outfile, 2, "output sinks");
if (m_sinks.length () > 0)
{
fprintf (outfile, "%s:\n", text);
}
-/* Various specializattions that emit an indented line to OUTFILE
+/* Various functions that emit an indented line to OUTFILE
showing "label: value". */
-template <>
void
-emit_field<const char *> (FILE *outfile, int indent,
- const char *label, const char *value)
+emit_string_field (FILE *outfile, int indent,
+ const char *label, const char *value)
{
emit_indent (outfile, indent);
fprintf (outfile, "%s: %s\n", label, value);
}
-template <>
void
-emit_field<char *> (FILE *outfile, int indent,
- const char *label, char *value)
+emit_bool_field (FILE *outfile, int indent,
+ const char *label, bool value)
{
- emit_indent (outfile, indent);
- fprintf (outfile, "%s: %s\n", label, value);
-}
-
-template <>
-void
-emit_field<bool> (FILE *outfile, int indent,
- const char *label, bool value)
-{
- emit_field<const char *> (outfile, indent, label,
- value ? "true" : "false");
+ emit_string_field (outfile, indent, label,
+ value ? "true" : "false");
}
-template <>
void
-emit_field<size_t> (FILE *outfile, int indent,
- const char *label, size_t value)
+emit_size_t_field (FILE *outfile, int indent,
+ const char *label, size_t value)
{
emit_indent (outfile, indent);
- fprintf (outfile, "%s: %zi\n", label, value);
+ fprintf (outfile, "%s: " HOST_SIZE_T_PRINT_DEC "\n", label, value);
}
-template <>
void
-emit_field<int> (FILE *outfile, int indent,
- const char *label, int value)
+emit_int_field (FILE *outfile, int indent,
+ const char *label, int value)
{
emit_indent (outfile, indent);
fprintf (outfile, "%s: %i\n", label, value);
}
-template <>
void
-emit_field<unsigned> (FILE *outfile, int indent,
- const char *label, unsigned value)
+emit_unsigned_field (FILE *outfile, int indent,
+ const char *label, unsigned value)
{
emit_indent (outfile, indent);
fprintf (outfile, "%s: %u\n", label, value);
extern void emit_heading (FILE *outfile, int indent,
const char *text);
-template <typename T>
-extern void emit_field (FILE *outfile, int indent,
- const char *label, T value);
+extern void emit_string_field (FILE *outfile, int indent,
+ const char *label, const char *value);
+extern void emit_bool_field (FILE *outfile, int indent,
+ const char *label, bool value);
+extern void emit_size_t_field (FILE *outfile, int indent,
+ const char *label, size_t value);
+extern void emit_int_field (FILE *outfile, int indent,
+ const char *label, int value);
+extern void emit_unsigned_field (FILE *outfile, int indent,
+ const char *label, unsigned value);
extern void emit_none (FILE *outfile, int indent);
-#define DIAGNOSTICS_DUMPING_EMIT_FIELD(FLAG) \
- dumping::emit_field (outfile, indent, #FLAG, FLAG)
+#define DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD(FLAG) \
+ dumping::emit_bool_field (outfile, indent, #FLAG, FLAG)
} // namespace dumping
} // namespace diagnostics
fprintf (out, "(unused)\n");
return;
}
- dumping::emit_field (out, indent, "file_path", m_file_path);
+ dumping::emit_string_field (out, indent, "file_path", m_file_path);
{
dumping::emit_indent (out, indent);
fprintf (out, "fp: %p\n", (void *)m_fp);
}
- dumping::emit_field (out, indent, "needs_read_p", needs_read_p ());
- dumping::emit_field (out, indent, "needs_grow_p", needs_grow_p ());
- dumping::emit_field (out, indent, "use_count", m_use_count);
- dumping::emit_field (out, indent, "size", m_size);
- dumping::emit_field (out, indent, "nb_read", m_nb_read);
- dumping::emit_field (out, indent, "start_line_idx", m_line_start_idx);
- dumping::emit_field (out, indent, "line_num", m_line_num);
- dumping::emit_field (out, indent, "missing_trailing_newline",
- (int)m_missing_trailing_newline);
+ dumping::emit_bool_field (out, indent, "needs_read_p", needs_read_p ());
+ dumping::emit_bool_field (out, indent, "needs_grow_p", needs_grow_p ());
+ dumping::emit_unsigned_field (out, indent, "use_count", m_use_count);
+ dumping::emit_size_t_field (out, indent, "size", m_size);
+ dumping::emit_size_t_field (out, indent, "nb_read", m_nb_read);
+ dumping::emit_size_t_field (out, indent, "start_line_idx", m_line_start_idx);
+ dumping::emit_size_t_field (out, indent, "line_num", m_line_num);
+ dumping::emit_bool_field (out, indent, "missing_trailing_newline",
+ m_missing_trailing_newline);
{
dumping::emit_indent (out, indent);
fprintf (out, "line records (%i):\n", m_line_record.length ());
for (auto &line : m_line_record)
{
dumping::emit_indent (out, indent);
- fprintf (out, "[%i]: line %zi: byte offsets: %zi-%zi\n",
+ fprintf (out, ("[%i]:"
+ " line " HOST_SIZE_T_PRINT_DEC ":"
+ " byte offsets: " HOST_SIZE_T_PRINT_DEC
+ "-" HOST_SIZE_T_PRINT_DEC "\n"),
idx++, line.line_num, line.start_pos, line.end_pos);
}
}
void
html_generation_options::dump (FILE *outfile, int indent) const
{
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_css);
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_javascript);
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_show_state_diagrams);
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_show_state_diagrams_sarif);
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_show_state_diagrams_dot_src);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_css);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_javascript);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_state_diagrams);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_state_diagrams_sarif);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_state_diagrams_dot_src);
}
class html_builder;
{
dumping::emit_indent (outfile, indent);
fprintf (outfile, "json\n");
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_formatted);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_formatted);
}
/* A class for managing SARIF output (for -fdiagnostics-format=sarif-stderr
void
sarif_generation_options::dump (FILE *outfile, int indent) const
{
- dumping::emit_field (outfile, indent,
- "m_version",
- get_dump_string_for_sarif_version (m_version));
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_state_graph);
+ dumping::emit_string_field (outfile, indent,
+ "m_version",
+ get_dump_string_for_sarif_version (m_version));
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_state_graph);
}
#if CHECKING_P
void
text_sink::dump (FILE *outfile, int indent) const
{
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_follows_reference_printer);
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_show_nesting);
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_show_locations_in_nesting);
- DIAGNOSTICS_DUMPING_EMIT_FIELD (m_show_nesting_levels);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_follows_reference_printer);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_nesting);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_locations_in_nesting);
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_nesting_levels);
sink::dump (outfile, indent);
dumping::emit_heading (outfile, indent, "saved_output_buffer");
fprintf (out, ", sarif_source_language=\"%s\"",
file->get_sarif_source_language ());
if (const content_buffer *buf = file->get_content ())
- fprintf (out, ", content=(size=%zi)", buf->m_sz);
+ fprintf (out, ", content=(size=" HOST_SIZE_T_PRINT_DEC ")",
+ buf->m_sz);
fprintf (out, ")");
}
else
#include "pretty-print-urlifier.h"
#include "diagnostics/color.h"
#include "diagnostics/event-id.h"
+#include "diagnostics/dumping.h"
#include "diagnostic-highlight-colors.h"
#include "auto-obstack.h"
#include "selftest.h"
{
for (size_t idx = 0; m_args[idx]; ++idx)
{
- fprintf (out, "%*s%i: ",
- indent, "",
- (int)idx);
+ diagnostics::dumping::emit_indent (out, indent);
+ fprintf (out, "%i: ", (int)idx);
m_args[idx]->dump (out);
}
}
pp_string (this, get_end_url_string (this));
}
-/* Dump state of this pretty_printer to OUT, for debugging. */
-
-void
-pretty_printer::dump (FILE *out, int indent) const
+static const char *
+get_url_format_as_string (diagnostic_url_format url_format)
{
- fprintf (out, "%*sm_show_color: %s\n",
- indent, "",
- m_show_color ? "true" : "false");
-
- fprintf (out, "%*sm_url_format: ", indent, "");
- switch (m_url_format)
+ switch (url_format)
{
case URL_FORMAT_NONE:
- fprintf (out, "none");
- break;
+ return "none";
case URL_FORMAT_ST:
- fprintf (out, "st");
- break;
+ return "st";
case URL_FORMAT_BEL:
- fprintf (out, "bel");
- break;
+ return "bel";
default:
gcc_unreachable ();
}
- fprintf (out, "\n");
+}
+
+/* Dump state of this pretty_printer to OUT, for debugging. */
- fprintf (out, "%*sm_buffer:\n", indent, "");
- m_buffer->dump (out, indent + 2);
+void
+pretty_printer::dump (FILE *outfile, int indent) const
+{
+ namespace dumping = diagnostics::dumping;
+
+ DIAGNOSTICS_DUMPING_EMIT_BOOL_FIELD (m_show_color);
+ dumping::emit_string_field
+ (outfile, indent,
+ "m_url_format",
+ get_url_format_as_string (m_url_format));
+ dumping::emit_heading (outfile, indent, "m_buffer");
+ if (m_buffer)
+ m_buffer->dump (outfile, indent + 2);
+ else
+ dumping::emit_none (outfile, indent + 2);
}
/* class pp_markup::context. */