aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2025-08-09 09:15:04 -0400
committerDavid Malcolm <dmalcolm@redhat.com>2025-08-09 09:15:04 -0400
commit7c02f011502ea65bb03891239a7317a95c6a00dd (patch)
treea797f40ceaaa02aa065b2473fda2cd9e440c23c3 /gcc
parent8ad36426c78903953bbd2c248a3096d307013e4a (diff)
downloadgcc-7c02f011502ea65bb03891239a7317a95c6a00dd.zip
gcc-7c02f011502ea65bb03891239a7317a95c6a00dd.tar.gz
gcc-7c02f011502ea65bb03891239a7317a95c6a00dd.tar.bz2
diagnostics: fix build on hosts where unsigned == size_t
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>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/diagnostics/context.cc5
-rw-r--r--gcc/diagnostics/dumping.cc42
-rw-r--r--gcc/diagnostics/dumping.h17
-rw-r--r--gcc/diagnostics/file-cache.cc25
-rw-r--r--gcc/diagnostics/html-sink.cc10
-rw-r--r--gcc/diagnostics/sarif-sink.cc10
-rw-r--r--gcc/diagnostics/text-sink.cc8
-rw-r--r--gcc/libgdiagnostics.cc3
-rw-r--r--gcc/pretty-print.cc49
9 files changed, 87 insertions, 82 deletions
diff --git a/gcc/diagnostics/context.cc b/gcc/diagnostics/context.cc
index c948246..3668958 100644
--- a/gcc/diagnostics/context.cc
+++ b/gcc/diagnostics/context.cc
@@ -391,7 +391,10 @@ context::dump (FILE *outfile) const
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)
{
diff --git a/gcc/diagnostics/dumping.cc b/gcc/diagnostics/dumping.cc
index f0366a5..1dbecf4 100644
--- a/gcc/diagnostics/dumping.cc
+++ b/gcc/diagnostics/dumping.cc
@@ -45,58 +45,44 @@ emit_heading (FILE *outfile, int indent,
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);
diff --git a/gcc/diagnostics/dumping.h b/gcc/diagnostics/dumping.h
index 08c7ee4..02f6485 100644
--- a/gcc/diagnostics/dumping.h
+++ b/gcc/diagnostics/dumping.h
@@ -28,14 +28,21 @@ extern void emit_indent (FILE *outfile, int indent);
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
diff --git a/gcc/diagnostics/file-cache.cc b/gcc/diagnostics/file-cache.cc
index 9acf82e..0ec0679 100644
--- a/gcc/diagnostics/file-cache.cc
+++ b/gcc/diagnostics/file-cache.cc
@@ -547,20 +547,20 @@ file_cache_slot::dump (FILE *out, int indent) const
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 ());
@@ -569,7 +569,10 @@ file_cache_slot::dump (FILE *out, int indent) const
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);
}
}
diff --git a/gcc/diagnostics/html-sink.cc b/gcc/diagnostics/html-sink.cc
index 448d461..1fd317a 100644
--- a/gcc/diagnostics/html-sink.cc
+++ b/gcc/diagnostics/html-sink.cc
@@ -65,11 +65,11 @@ html_generation_options::html_generation_options ()
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;
diff --git a/gcc/diagnostics/sarif-sink.cc b/gcc/diagnostics/sarif-sink.cc
index 0c4d77a..7526c16 100644
--- a/gcc/diagnostics/sarif-sink.cc
+++ b/gcc/diagnostics/sarif-sink.cc
@@ -710,7 +710,7 @@ sarif_serialization_format_json::dump (FILE *outfile, int indent) const
{
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
@@ -4360,10 +4360,10 @@ get_dump_string_for_sarif_version (enum sarif_version version)
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
diff --git a/gcc/diagnostics/text-sink.cc b/gcc/diagnostics/text-sink.cc
index a7ebb30..48b369c 100644
--- a/gcc/diagnostics/text-sink.cc
+++ b/gcc/diagnostics/text-sink.cc
@@ -159,10 +159,10 @@ text_sink::~text_sink ()
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");
diff --git a/gcc/libgdiagnostics.cc b/gcc/libgdiagnostics.cc
index 784e281..d87dd46 100644
--- a/gcc/libgdiagnostics.cc
+++ b/gcc/libgdiagnostics.cc
@@ -1939,7 +1939,8 @@ diagnostic_manager_debug_dump_file (diagnostic_manager *,
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
diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc
index 77d40ec..d79a828 100644
--- a/gcc/pretty-print.cc
+++ b/gcc/pretty-print.cc
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see
#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"
@@ -1600,9 +1601,8 @@ pp_formatted_chunks::dump (FILE *out, int indent) const
{
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);
}
}
@@ -3100,34 +3100,39 @@ pretty_printer::end_url ()
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. */