summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-09-20 12:04:37 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2022-09-20 12:04:37 -0400
commit760308704378a96e6a7266326087ec49922ae3f2 (patch)
tree44b1aaef30f27d1a57d7caca09580ee3201a27b8
parent68707e9c3f327b0fcb952ee3f4cc44a180f56d60 (diff)
downloadpostgresql-760308704378a96e6a7266326087ec49922ae3f2.tar.gz
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
-rw-r--r--src/backend/access/gist/gistxlog.c2
-rw-r--r--src/backend/access/transam/xlog.c2
-rw-r--r--src/backend/parser/gram.y1
-rw-r--r--src/backend/utils/adt/array_typanalyze.c4
-rw-r--r--src/bin/pgbench/exprparse.y5
5 files changed, 8 insertions, 6 deletions
diff --git a/src/backend/access/gist/gistxlog.c b/src/backend/access/gist/gistxlog.c
index f4dfaaa1b8..144e7ab8a0 100644
--- a/src/backend/access/gist/gistxlog.c
+++ b/src/backend/access/gist/gistxlog.c
@@ -257,7 +257,7 @@ gistRedoPageUpdateRecord(XLogReaderState *record)
char *begin;
char *data;
Size datalen;
- int ninserted = 0;
+ int ninserted PG_USED_FOR_ASSERTS_ONLY = 0;
data = begin = XLogRecGetBlockData(record, 0, &datalen);
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 8522765489..23c7a64844 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -2073,7 +2073,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, bool opportunistic)
XLogRecPtr NewPageEndPtr = InvalidXLogRecPtr;
XLogRecPtr NewPageBeginPtr;
XLogPageHeader NewPage;
- int npages = 0;
+ int npages pg_attribute_unused() = 0;
LWLockAcquire(WALBufMappingLock, LW_EXCLUSIVE);
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index d36b82f4df..9478602be8 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -775,6 +775,7 @@ static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
stmtblock: stmtmulti
{
pg_yyget_extra(yyscanner)->parsetree = $1;
+ (void) yynerrs; /* suppress compiler warning */
}
;
diff --git a/src/backend/utils/adt/array_typanalyze.c b/src/backend/utils/adt/array_typanalyze.c
index 78153d232f..2ed823d86f 100644
--- a/src/backend/utils/adt/array_typanalyze.c
+++ b/src/backend/utils/adt/array_typanalyze.c
@@ -217,7 +217,6 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
{
ArrayAnalyzeExtraData *extra_data;
int num_mcelem;
- int null_cnt = 0;
int null_elem_cnt = 0;
int analyzed_rows = 0;
@@ -321,8 +320,7 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
value = fetchfunc(stats, array_no, &isnull);
if (isnull)
{
- /* array is null, just count that */
- null_cnt++;
+ /* ignore arrays that are null overall */
continue;
}
diff --git a/src/bin/pgbench/exprparse.y b/src/bin/pgbench/exprparse.y
index b3a2d9bfd3..4315990d0d 100644
--- a/src/bin/pgbench/exprparse.y
+++ b/src/bin/pgbench/exprparse.y
@@ -60,7 +60,10 @@ static PgBenchExpr *make_func(yyscan_t yyscanner, int fnumber, PgBenchExprList *
%%
-result: expr { expr_parse_result = $1; }
+result: expr {
+ expr_parse_result = $1;
+ (void) yynerrs; /* suppress compiler warning */
+ }
elist: { $$ = NULL; }
| expr { $$ = make_elist($1, NULL); }