[v2,1/8] Fix warnings for tree formats in gfc_error

Message ID 20240712141155.255186-2-parras@baylibre.com
State Committed
Commit 0450a143d2d132a8b3e6cff896f69e191c3316e2
Headers
Series OpenMP: dispatch + adjust_args support |

Commit Message

Paul-Antoine Arras July 12, 2024, 2:11 p.m. UTC
  This enables proper warnings for formats like %qD.

gcc/c-family/ChangeLog:

	* c-format.cc (gcc_gfc_char_table): Add formats for tree objects.
---
 gcc/c-family/c-format.cc | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Tobias Burnus July 16, 2024, 1:13 p.m. UTC | #1
I think it would be nice if some C/C++/global maintainer could rubber 
stamp the following patch.


Otherwise, I think it is trivial, i.e. I think it can be committed in a 
few days, unless someone has concerns.

This change to gcc/c-family/c-format.cc LGTM from the *gfortran* POV and 
is trivially copied from gcc_tdiag_char_table or gcc_cdiag_char_table 
(which both have it).

* * *

Background:

While this is for gcc/c-family/c-format.cc, the 'gcc_gfc_char_table' is 
for diagnostic for compiling gcc/fortran/, only.

Namely, the gfc_error, gfc_warning etc. functions are annotated by the
format checking attribute:

#define ATTRIBUTE_GCC_GFC(m, n) __attribute__ ((__format__ (__gcc_gfc__, 
m, n))) ATTRIBUTE_NONNULL(m)

* * *

As gfc_error etc. call the common diagnostic at the end, '%qE', %qD' 
etc. are already supported.

(As tested manually; it is also used by this patch series of PA.)

But while %qE is already supported, without the 'gcc_gfc_char_table' 
change, the '__format__ (__gcc_gfc__' check does not recognize it and
yields a -Werror, causing that a bootstrap fails.

Hence, we need this patch …

* * *

Paul-Antoine Arras wrote:
> This enables proper warnings for formats like %qD.
> 
> gcc/c-family/ChangeLog:
> 
> 	* c-format.cc (gcc_gfc_char_table): Add formats for tree objects.
> ---
>   gcc/c-family/c-format.cc | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
> index 5bfd2fc4469..f4163c9cbc0 100644
> --- a/gcc/c-family/c-format.cc
> +++ b/gcc/c-family/c-format.cc
> @@ -847,6 +847,10 @@ static const format_char_info gcc_gfc_char_table[] =
>     /* This will require a "locus" at runtime.  */
>     { "L",   0, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "R", NULL },
>   
> +  /* These will require a "tree" at runtime.  */
> +  { "DFTV", 1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q+", "'",   NULL },
> +  { "E",   1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q+", "",   NULL },
> +
>     /* These will require nothing.  */
>     { "<>",0, STD_C89, NOARGUMENTS, "",      "",   NULL },
>     { NULL,  0, STD_C89, NOLENGTHS, NULL, NULL, NULL
  
Marek Polacek July 17, 2024, 5:16 p.m. UTC | #2
On Fri, Jul 12, 2024 at 04:11:48PM +0200, Paul-Antoine Arras wrote:
> This enables proper warnings for formats like %qD.

Ok.  The new lines are the same as in gcc_cdiag_char_table and
gcc_tdiag_char_table.
 
> gcc/c-family/ChangeLog:
> 
> 	* c-format.cc (gcc_gfc_char_table): Add formats for tree objects.
> ---
>  gcc/c-family/c-format.cc | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
> index 5bfd2fc4469..f4163c9cbc0 100644
> --- a/gcc/c-family/c-format.cc
> +++ b/gcc/c-family/c-format.cc
> @@ -847,6 +847,10 @@ static const format_char_info gcc_gfc_char_table[] =
>    /* This will require a "locus" at runtime.  */
>    { "L",   0, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "R", NULL },
>  
> +  /* These will require a "tree" at runtime.  */
> +  { "DFTV", 1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q+", "'",   NULL },
> +  { "E",   1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q+", "",   NULL },
> +
>    /* These will require nothing.  */
>    { "<>",0, STD_C89, NOARGUMENTS, "",      "",   NULL },
>    { NULL,  0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
> -- 
> 2.45.2
> 

Marek
  

Patch

diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 5bfd2fc4469..f4163c9cbc0 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -847,6 +847,10 @@  static const format_char_info gcc_gfc_char_table[] =
   /* This will require a "locus" at runtime.  */
   { "L",   0, STD_C89, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "", "R", NULL },
 
+  /* These will require a "tree" at runtime.  */
+  { "DFTV", 1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q+", "'",   NULL },
+  { "E",   1, STD_C89, { T89_T,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "q+", "",   NULL },
+
   /* These will require nothing.  */
   { "<>",0, STD_C89, NOARGUMENTS, "",      "",   NULL },
   { NULL,  0, STD_C89, NOLENGTHS, NULL, NULL, NULL }