public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb: silence unused-but-set-variable warning about yynerrs in cp-name-parser.y
@ 2022-10-12 17:32 Simon Marchi
  2022-10-14 16:49 ` Tom Tromey
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2022-10-12 17:32 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

When building with clang 15 on Ubuntu 20.04, I get:

      CXX    cp-name-parser.o
    cp-name-parser.c.tmp:1777:9: error: variable 'cpnameyynerrs' set but not used [-Werror,-Wunused-but-set-variable]
        int yynerrs;
            ^
    /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:58:18: note: expanded from macro 'yynerrs'
    #define yynerrs         GDB_YY_REMAP (yynerrs)
                            ^
    /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:40:29: note: expanded from macro 'GDB_YY_REMAP'
    #define GDB_YY_REMAP(YYSYM) GDB_YY_REMAP_1 (GDB_YY_REMAP_PREFIX, YYSYM)
                                ^
    /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:39:39: note: expanded from macro 'GDB_YY_REMAP_1'
    #define GDB_YY_REMAP_1(PREFIX, YYSYM) GDB_YY_REMAP_2 (PREFIX, YYSYM)
                                          ^
    /home/smarchi/src/binutils-gdb/gdb/yy-remap.h:38:39: note: expanded from macro 'GDB_YY_REMAP_2'
    #define GDB_YY_REMAP_2(PREFIX, YYSYM) PREFIX ## YYSYM
                                          ^
    <scratch space>:45:1: note: expanded from here
    cpnameyynerrs
    ^

This is because clang 15 warns for something like this:

    int n;
    n = 0;
    ++n;

whereas previous versions do not.

yynerrs is defined in yyparse and is there for actions to use.  Since
the actions in cp-name-parser.y don't use it, we get a warning.  We see
this problem on this particular .y file because it uses `%pure-parser`
[1], which makes yynerrs a local rather than a global.

I initially fixed this by using
DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE (like in commit f7aa1a5acc5
("gold: Suppress "unused" variable warning on Clang")), but then I
realized we could suppress the warning in a more fine-grained way using
this in a rule:

    (void) yynerrs;

[1] https://www.gnu.org/software/bison/manual/html_node/Error-Reporting-Function.html

Change-Id: I6cae7a4207c19fe1b719e2ac19be69122ebe3af1
---
 gdb/cp-name-parser.y | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/cp-name-parser.y b/gdb/cp-name-parser.y
index 34c691ddabb1..1108c787b7e7 100644
--- a/gdb/cp-name-parser.y
+++ b/gdb/cp-name-parser.y
@@ -346,7 +346,12 @@ static void yyerror (cpname_state *, const char *);
 %%
 
 result		:	start
-			{ state->global_result = $1; }
+			{
+			  state->global_result = $1;
+
+			  /* Avoid warning about "yynerrs" being unused.  */
+			  (void) yynerrs;
+			}
 		;
 
 start		:	type
-- 
2.38.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: silence unused-but-set-variable warning about yynerrs in cp-name-parser.y
  2022-10-12 17:32 [PATCH] gdb: silence unused-but-set-variable warning about yynerrs in cp-name-parser.y Simon Marchi
@ 2022-10-14 16:49 ` Tom Tromey
  2022-10-17 12:38   ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2022-10-14 16:49 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches; +Cc: Simon Marchi

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> I initially fixed this by using
Simon> DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE (like in commit f7aa1a5acc5
Simon> ("gold: Suppress "unused" variable warning on Clang")), but then I
Simon> realized we could suppress the warning in a more fine-grained way using
Simon> this in a rule:

Simon>     (void) yynerrs;

Seems fine to me.

Tom

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] gdb: silence unused-but-set-variable warning about yynerrs in cp-name-parser.y
  2022-10-14 16:49 ` Tom Tromey
@ 2022-10-17 12:38   ` Simon Marchi
  0 siblings, 0 replies; 3+ messages in thread
From: Simon Marchi @ 2022-10-17 12:38 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches; +Cc: Simon Marchi



On 2022-10-14 12:49, Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> I initially fixed this by using
> Simon> DIAGNOSTIC_IGNORE_UNUSED_BUT_SET_VARIABLE (like in commit f7aa1a5acc5
> Simon> ("gold: Suppress "unused" variable warning on Clang")), but then I
> Simon> realized we could suppress the warning in a more fine-grained way using
> Simon> this in a rule:
> 
> Simon>     (void) yynerrs;
> 
> Seems fine to me.
> 
> Tom

Pushed, thanks.

Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-10-17 12:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-12 17:32 [PATCH] gdb: silence unused-but-set-variable warning about yynerrs in cp-name-parser.y Simon Marchi
2022-10-14 16:49 ` Tom Tromey
2022-10-17 12:38   ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).