diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2022-09-20 12:04:37 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2022-09-20 12:04:37 -0400 |
commit | 152c9f7b8f01437780d9f87bfe945bba47efdd0a (patch) | |
tree | c1e9773423827497d3d5fb14dc21784e26d0e8fd /src | |
parent | c9a21fea44ca5722dbfcced0dfdc84db063aff71 (diff) | |
download | postgresql-152c9f7b8f01437780d9f87bfe945bba47efdd0a.tar.gz postgresql-152c9f7b8f01437780d9f87bfe945bba47efdd0a.zip |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/access/gist/gistxlog.c | 2 | ||||
-rw-r--r-- | src/backend/access/transam/xlog.c | 2 | ||||
-rw-r--r-- | src/backend/parser/gram.y | 1 | ||||
-rw-r--r-- | src/backend/utils/adt/array_typanalyze.c | 4 | ||||
-rw-r--r-- | src/backend/utils/adt/jsonpath_gram.y | 1 | ||||
-rw-r--r-- | src/bin/pgbench/exprparse.y | 5 |
6 files changed, 9 insertions, 6 deletions
diff --git a/src/backend/access/gist/gistxlog.c b/src/backend/access/gist/gistxlog.c index b4f629f4a8f..998befd2cbb 100644 --- a/src/backend/access/gist/gistxlog.c +++ b/src/backend/access/gist/gistxlog.c @@ -81,7 +81,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 eb0430fe98f..e0281246722 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -1785,7 +1785,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, TimeLineID tli, 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 82f03fc9c93..c6ec694cebc 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -864,6 +864,7 @@ parse_toplevel: stmtmulti { pg_yyget_extra(yyscanner)->parsetree = $1; + (void) yynerrs; /* suppress compiler warning */ } | MODE_TYPE_NAME Typename { diff --git a/src/backend/utils/adt/array_typanalyze.c b/src/backend/utils/adt/array_typanalyze.c index 1964cedd93f..2360c680ac8 100644 --- a/src/backend/utils/adt/array_typanalyze.c +++ b/src/backend/utils/adt/array_typanalyze.c @@ -218,7 +218,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; } diff --git a/src/backend/utils/adt/jsonpath_gram.y b/src/backend/utils/adt/jsonpath_gram.y index 7e28853a57f..2a56629cc3a 100644 --- a/src/backend/utils/adt/jsonpath_gram.y +++ b/src/backend/utils/adt/jsonpath_gram.y @@ -113,6 +113,7 @@ result: *result = palloc(sizeof(JsonPathParseResult)); (*result)->expr = $2; (*result)->lax = $1; + (void) yynerrs; } | /* EMPTY */ { *result = NULL; } ; diff --git a/src/bin/pgbench/exprparse.y b/src/bin/pgbench/exprparse.y index ade2ecdaab8..f6387d4a3cb 100644 --- a/src/bin/pgbench/exprparse.y +++ b/src/bin/pgbench/exprparse.y @@ -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; } | expr { $$ = make_elist($1, NULL); } |