From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from alt42.smtp-out.videotron.ca (alt42.smtp-out.videotron.ca [23.233.128.29]) by sourceware.org (Postfix) with ESMTPS id A85E03858D38 for ; Wed, 12 Oct 2022 17:33:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A85E03858D38 Received: from localhost.localdomain ([74.56.249.162]) by Videotron with ESMTP id ifbEozDNt8yhQifbEoTZun; Wed, 12 Oct 2022 13:33:00 -0400 X-Authority-Analysis: v=2.4 cv=RrqmkAqK c=1 sm=1 tr=0 ts=6346fa4c a=vTEE2W6FS0436lLiwMOoNg==:117 a=vTEE2W6FS0436lLiwMOoNg==:17 a=mDV3o1hIAAAA:8 a=mKhhxGDH_lmZbciQ6kYA:9 a=nQn26w8ZHb4A:10 a=ppJC3eF-n6kA:10 a=_FVE-zBwftR9WsbkzFJk:22 From: Simon Marchi To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: silence unused-but-set-variable warning about yynerrs in cp-name-parser.y Date: Wed, 12 Oct 2022 13:32:56 -0400 Message-Id: <20221012173256.20079-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.38.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfJsxTtRxDjb/G0CFE5ndMW8PW7P0o/Q+c/nl0Uf1uSzmLyujgUo+ymed6xwEp1ZGyS33KaExKFwhp0pdcKxmA88TRe5tsKhs22unIX+u+299J1JYtQj8 VANXCH5xqW8Zt1GSuVRiMxkyaAwR1cl+f3LnGOonis47KS6egG/r5iCH0bPWp9yN7tBaOhWp6joS1Z3PSED37NfvwcqLDDKf4D2lhChIjBP1hnOzEi8cXzLl 7aZSfsy9T3EGc0qmv7FnnA== X-Spam-Status: No, score=-1174.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 12 Oct 2022 17:33:02 -0000 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 ^ :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