]> git.ipfire.org Git - thirdparty/gcc.git/commit
diagnostics: fix build on hosts where unsigned == size_t
authorDavid Malcolm <dmalcolm@redhat.com>
Sat, 9 Aug 2025 13:15:04 +0000 (09:15 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Sat, 9 Aug 2025 13:15:04 +0000 (09:15 -0400)
commit7c02f011502ea65bb03891239a7317a95c6a00dd
treea797f40ceaaa02aa065b2473fda2cd9e440c23c3
parent8ad36426c78903953bbd2c248a3096d307013e4a
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>
gcc/diagnostics/context.cc
gcc/diagnostics/dumping.cc
gcc/diagnostics/dumping.h
gcc/diagnostics/file-cache.cc
gcc/diagnostics/html-sink.cc
gcc/diagnostics/sarif-sink.cc
gcc/diagnostics/text-sink.cc
gcc/libgdiagnostics.cc
gcc/pretty-print.cc