summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2022-09-20 16:04:37 +0000
committerTom Lane2022-09-20 16:04:37 +0000
commit612e7966127e7f58ae10198250410719df6c1b11 (patch)
tree301e139026c806f35ae2c8462015fe9f6ca6c145
parent9fdeae84864ffbf0bc523646f26a492827cd8a8a (diff)
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/[email protected]
-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
4 files changed, 4 insertions, 5 deletions
diff --git a/src/backend/access/gist/gistxlog.c b/src/backend/access/gist/gistxlog.c
index fbdbb3c51f2..7a8fdd85354 100644
--- a/src/backend/access/gist/gistxlog.c
+++ b/src/backend/access/gist/gistxlog.c
@@ -74,7 +74,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 f5a1599cb37..c3fe1271465 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -1905,7 +1905,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 617e577b663..24bdb86bc2c 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -732,6 +732,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 ffe8035eb4d..e2ded3ccd47 100644
--- a/src/backend/utils/adt/array_typanalyze.c
+++ b/src/backend/utils/adt/array_typanalyze.c
@@ -216,7 +216,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;
@@ -320,8 +319,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;
}