diff mbox series

analyzer: Fix up some -Wformat* warnings

Message ID Zel7OIk4KpWQfH7b@tucnak
State New
Headers show
Series analyzer: Fix up some -Wformat* warnings | expand

Commit Message

Jakub Jelinek March 7, 2024, 8:30 a.m. UTC
Hi!

I'm seeing warnings like
../../gcc/analyzer/access-diagram.cc: In member function ‘void ana::bit_size_expr::print(pretty_printer*) const’:
../../gcc/analyzer/access-diagram.cc:399:26: warning: unknown conversion type character ‘E’ in format [-Wformat=]
  399 |         pp_printf (pp, _("%qE bytes"), bytes_expr);
      |                          ^~~~~~~~~~~
when building stage2/stage3 gcc.  While such warnings would be
understandable when building stage1 because one could e.g. have some
older host compiler which doesn't understand some of the format specifiers,
the above seems to be because we have in pretty-print.h
#ifdef GCC_DIAG_STYLE
#define GCC_PPDIAG_STYLE GCC_DIAG_STYLE
#else
#define GCC_PPDIAG_STYLE __gcc_diag__
#endif
and use GCC_PPDIAG_STYLE e.g. for pp_printf, and while
diagnostic-core.h has
#ifndef GCC_DIAG_STYLE
#define GCC_DIAG_STYLE __gcc_tdiag__
#endif
(and similarly various FE headers include their own GCC_DIAG_STYLE)
when including pretty-print.h before diagnostic-core.h we end up
with __gcc_diag__ style rather than __gcc_tdiag__ style, which I think
is the right thing for the analyzer, because analyzer seems to use
default_tree_printer everywhere:
grep pp_format_decoder.*=.default_tree_printer analyzer/* | wc -l
57

The following patch fixes that by making sure diagnostic-core.h is included
before pretty-print.h.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2024-03-07  Jakub Jelinek  <jakub@redhat.com>

	* access-diagram.cc: Include diagnostic-core.h before including
	diagnostic.h or diagnostic-path.h.
	* sm-malloc.cc: Likewise.
	* diagnostic-manager.cc: Likewise.
	* call-summary.cc: Likewise.
	* record-layout.cc: Likewise.



	Jakub

Comments

David Malcolm March 7, 2024, 12:57 p.m. UTC | #1
On Thu, 2024-03-07 at 09:30 +0100, Jakub Jelinek wrote:
> Hi!
> 
> I'm seeing warnings like
> ../../gcc/analyzer/access-diagram.cc: In member function ‘void
> ana::bit_size_expr::print(pretty_printer*) const’:
> ../../gcc/analyzer/access-diagram.cc:399:26: warning: unknown
> conversion type character ‘E’ in format [-Wformat=]
>   399 |         pp_printf (pp, _("%qE bytes"), bytes_expr);
>       |                          ^~~~~~~~~~~
> when building stage2/stage3 gcc.  While such warnings would be
> understandable when building stage1 because one could e.g. have some
> older host compiler which doesn't understand some of the format
> specifiers,
> the above seems to be because we have in pretty-print.h
> #ifdef GCC_DIAG_STYLE
> #define GCC_PPDIAG_STYLE GCC_DIAG_STYLE
> #else
> #define GCC_PPDIAG_STYLE __gcc_diag__
> #endif
> and use GCC_PPDIAG_STYLE e.g. for pp_printf, and while
> diagnostic-core.h has
> #ifndef GCC_DIAG_STYLE
> #define GCC_DIAG_STYLE __gcc_tdiag__
> #endif
> (and similarly various FE headers include their own GCC_DIAG_STYLE)
> when including pretty-print.h before diagnostic-core.h we end up
> with __gcc_diag__ style rather than __gcc_tdiag__ style, which I
> think
> is the right thing for the analyzer, because analyzer seems to use
> default_tree_printer everywhere:
> grep pp_format_decoder.*=.default_tree_printer analyzer/* | wc -l
> 57
> 
> The following patch fixes that by making sure diagnostic-core.h is
> included
> before pretty-print.h.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

Yes, thanks
Dave
diff mbox series

Patch

--- gcc/analyzer/access-diagram.cc.jj	2024-02-28 22:25:00.937538668 +0100
+++ gcc/analyzer/access-diagram.cc	2024-03-06 22:55:29.472213956 +0100
@@ -30,6 +30,7 @@  along with GCC; see the file COPYING3.
 #include "function.h"
 #include "basic-block.h"
 #include "gimple.h"
+#include "diagnostic-core.h"
 #include "diagnostic.h"
 #include "intl.h"
 #include "make-unique.h"
--- gcc/analyzer/sm-malloc.cc.jj	2024-01-05 21:57:22.532750027 +0100
+++ gcc/analyzer/sm-malloc.cc	2024-03-06 22:57:33.534502472 +0100
@@ -29,6 +29,7 @@  along with GCC; see the file COPYING3.
 #include "gimple.h"
 #include "options.h"
 #include "bitmap.h"
+#include "diagnostic-core.h"
 #include "diagnostic-path.h"
 #include "analyzer/analyzer.h"
 #include "diagnostic-event-id.h"
--- gcc/analyzer/diagnostic-manager.cc.jj	2024-01-03 22:33:37.488703561 +0100
+++ gcc/analyzer/diagnostic-manager.cc	2024-03-06 22:56:26.348429279 +0100
@@ -24,11 +24,11 @@  along with GCC; see the file COPYING3.
 #include "coretypes.h"
 #include "tree.h"
 #include "input.h"
+#include "diagnostic-core.h"
 #include "pretty-print.h"
 #include "gcc-rich-location.h"
 #include "gimple-pretty-print.h"
 #include "function.h"
-#include "diagnostic-core.h"
 #include "diagnostic-event-id.h"
 #include "diagnostic-path.h"
 #include "bitmap.h"
--- gcc/analyzer/call-summary.cc.jj	2024-03-03 22:29:46.122093337 +0100
+++ gcc/analyzer/call-summary.cc	2024-03-06 22:55:59.442800474 +0100
@@ -23,6 +23,7 @@  along with GCC; see the file COPYING3.
 #include "coretypes.h"
 #include "tree.h"
 #include "tree-dfa.h"
+#include "diagnostic-core.h"
 #include "diagnostic.h"
 #include "tree-diagnostic.h"
 #include "analyzer/analyzer.h"
--- gcc/analyzer/record-layout.cc.jj	2024-01-03 22:33:37.492703505 +0100
+++ gcc/analyzer/record-layout.cc	2024-03-06 22:56:48.652121592 +0100
@@ -26,6 +26,7 @@  along with GCC; see the file COPYING3.
 #include "function.h"
 #include "basic-block.h"
 #include "gimple.h"
+#include "diagnostic-core.h"
 #include "diagnostic.h"
 #include "tree-diagnostic.h"
 #include "analyzer/analyzer.h"