Commit 2e124d85 authored by Tom Lane's avatar Tom Lane

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
parent 382cc680
...@@ -81,7 +81,7 @@ gistRedoPageUpdateRecord(XLogReaderState *record) ...@@ -81,7 +81,7 @@ gistRedoPageUpdateRecord(XLogReaderState *record)
char *begin; char *begin;
char *data; char *data;
Size datalen; Size datalen;
int ninserted = 0; int ninserted PG_USED_FOR_ASSERTS_ONLY = 0;
data = begin = XLogRecGetBlockData(record, 0, &datalen); data = begin = XLogRecGetBlockData(record, 0, &datalen);
......
...@@ -2151,7 +2151,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, bool opportunistic) ...@@ -2151,7 +2151,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, bool opportunistic)
XLogRecPtr NewPageEndPtr = InvalidXLogRecPtr; XLogRecPtr NewPageEndPtr = InvalidXLogRecPtr;
XLogRecPtr NewPageBeginPtr; XLogRecPtr NewPageBeginPtr;
XLogPageHeader NewPage; XLogPageHeader NewPage;
int npages = 0; int npages pg_attribute_unused() = 0;
LWLockAcquire(WALBufMappingLock, LW_EXCLUSIVE); LWLockAcquire(WALBufMappingLock, LW_EXCLUSIVE);
......
...@@ -827,6 +827,7 @@ parse_toplevel: ...@@ -827,6 +827,7 @@ parse_toplevel:
stmtmulti stmtmulti
{ {
pg_yyget_extra(yyscanner)->parsetree = $1; pg_yyget_extra(yyscanner)->parsetree = $1;
(void) yynerrs; /* suppress compiler warning */
} }
| MODE_TYPE_NAME Typename | MODE_TYPE_NAME Typename
{ {
......
...@@ -218,7 +218,6 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, ...@@ -218,7 +218,6 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
{ {
ArrayAnalyzeExtraData *extra_data; ArrayAnalyzeExtraData *extra_data;
int num_mcelem; int num_mcelem;
int null_cnt = 0;
int null_elem_cnt = 0; int null_elem_cnt = 0;
int analyzed_rows = 0; int analyzed_rows = 0;
...@@ -320,8 +319,7 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, ...@@ -320,8 +319,7 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
value = fetchfunc(stats, array_no, &isnull); value = fetchfunc(stats, array_no, &isnull);
if (isnull) if (isnull)
{ {
/* array is null, just count that */ /* ignore arrays that are null overall */
null_cnt++;
continue; continue;
} }
......
...@@ -130,6 +130,7 @@ result: ...@@ -130,6 +130,7 @@ result:
*result = palloc(sizeof(JsonPathParseResult)); *result = palloc(sizeof(JsonPathParseResult));
(*result)->expr = $2; (*result)->expr = $2;
(*result)->lax = $1; (*result)->lax = $1;
(void) yynerrs;
} }
| /* EMPTY */ { *result = NULL; } | /* EMPTY */ { *result = NULL; }
; ;
......
...@@ -80,7 +80,10 @@ static PgBenchExpr *make_case(yyscan_t yyscanner, PgBenchExprList *when_then_lis ...@@ -80,7 +80,10 @@ static PgBenchExpr *make_case(yyscan_t yyscanner, PgBenchExprList *when_then_lis
%% %%
result: expr { expr_parse_result = $1; } result: expr {
expr_parse_result = $1;
(void) yynerrs; /* suppress compiler warning */
}
elist: { $$ = NULL; } elist: { $$ = NULL; }
| expr { $$ = make_elist($1, NULL); } | expr { $$ = make_elist($1, NULL); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment