]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Suppress variable-set-but-not-used warnings from clang 15.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 20 Sep 2022 16:04:37 +0000 (12:04 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 20 Sep 2022 16:04:37 +0000 (12:04 -0400)
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

src/backend/access/gist/gistxlog.c
src/backend/access/transam/xlog.c
src/backend/parser/gram.y
src/backend/utils/adt/array_typanalyze.c
src/backend/utils/adt/jsonpath_gram.y
src/bin/pgbench/exprparse.y

index df70f906b4e04f0df31d94638d831de00683e652..c46132e6b7d49a5f9616428b3230d3b51b774cc8 100644 (file)
@@ -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);
 
index 8f4c8ae4df78535569e159b5639addf488baa860..4c6967d40ee8cc4eb4197406c62f63a0f5cd0d35 100644 (file)
@@ -1778,7 +1778,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);
 
index 3ea25d8be72ad5f6b3507002d72a642872cafd2b..e25b9a85e33478c09bd2346a42fc9d9eed3b7db4 100644 (file)
@@ -859,6 +859,7 @@ parse_toplevel:
                        stmtmulti
                        {
                                pg_yyget_extra(yyscanner)->parsetree = $1;
+                               (void) yynerrs;         /* suppress compiler warning */
                        }
                        | MODE_TYPE_NAME Typename
                        {
index 1964cedd93ff6890889f5c452bae12ecb03aa631..2360c680ac896e82ede0f9ea456a53ac0790b4bc 100644 (file)
@@ -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;
                }
 
index f903dba3e341d7e26b6e564d7c92680e2547f9e7..91e4308d6559f7b68a1f4e41c596b85a7f12e85c 100644 (file)
@@ -131,6 +131,7 @@ result:
                                                                                *result = palloc(sizeof(JsonPathParseResult));
                                                                                (*result)->expr = $2;
                                                                                (*result)->lax = $1;
+                                                                               (void) yynerrs;
                                                                        }
        | /* EMPTY */                                   { *result = NULL; }
        ;
index b5592d4b97d03824e666d7224597740d9b761c67..18da3c6c596c37c73e17e884ddc6f05c4228ebe1 100644 (file)
@@ -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); }