Skip to content

Commit 7603087

Browse files
committed
Suppress variable-set-but-not-used warnings from clang 15.
clang 15+ will issue a set-but-not-used warning when the only use of a variable is in autoincrements (e.g., "foo++;"). That's perfectly sensible, but it detects a few more cases that we'd not noticed before. Silence the warnings with our usual methods, such as PG_USED_FOR_ASSERTS_ONLY, or in one case by actually removing a useless variable. One thing that we can't nicely get rid of is that with %pure-parser, Bison emits "yynerrs" as a local variable that falls foul of this warning. To silence those, I inserted "(void) yynerrs;" in the top-level productions of affected grammars. Per recently-established project policy, this is a candidate for back-patching into out-of-support branches: it suppresses annoying compiler warnings but changes no behavior. Hence, back-patch to 9.5, which is as far as these patches go without issues. (A preliminary check shows that the prior branches need some other set-but-not-used cleanups too, so I'll leave them for another day.) Discussion: https://postgr.es/m/514615.1663615243@sss.pgh.pa.us
1 parent 68707e9 commit 7603087

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

src/backend/access/gist/gistxlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ gistRedoPageUpdateRecord(XLogReaderState *record)
257257
char *begin;
258258
char *data;
259259
Size datalen;
260-
int ninserted = 0;
260+
int ninserted PG_USED_FOR_ASSERTS_ONLY = 0;
261261

262262
data = begin = XLogRecGetBlockData(record, 0, &datalen);
263263

src/backend/access/transam/xlog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, bool opportunistic)
20732073
XLogRecPtr NewPageEndPtr = InvalidXLogRecPtr;
20742074
XLogRecPtr NewPageBeginPtr;
20752075
XLogPageHeader NewPage;
2076-
int npages = 0;
2076+
int npages pg_attribute_unused() = 0;
20772077

20782078
LWLockAcquire(WALBufMappingLock, LW_EXCLUSIVE);
20792079

src/backend/parser/gram.y

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
775775
stmtblock: stmtmulti
776776
{
777777
pg_yyget_extra(yyscanner)->parsetree = $1;
778+
(void) yynerrs; /* suppress compiler warning */
778779
}
779780
;
780781

src/backend/utils/adt/array_typanalyze.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
217217
{
218218
ArrayAnalyzeExtraData *extra_data;
219219
int num_mcelem;
220-
int null_cnt = 0;
221220
int null_elem_cnt = 0;
222221
int analyzed_rows = 0;
223222

@@ -321,8 +320,7 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
321320
value = fetchfunc(stats, array_no, &isnull);
322321
if (isnull)
323322
{
324-
/* array is null, just count that */
325-
null_cnt++;
323+
/* ignore arrays that are null overall */
326324
continue;
327325
}
328326

src/bin/pgbench/exprparse.y

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ static PgBenchExpr *make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *
6060

6161
%%
6262

63-
result: expr { expr_parse_result = $1; }
63+
result: expr {
64+
expr_parse_result = $1;
65+
(void) yynerrs; /* suppress compiler warning */
66+
}
6467

6568
elist: { $$ = NULL; }
6669
| expr { $$ = make_elist($1, NULL); }

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy