8000 Suppress variable-set-but-not-used warnings from clang 15. · postgrespro/postgres@152c9f7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 152c9f7

Browse files
committed
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
1 parent c9a21fe commit 152c9f7

File tree

6 files changed

+9
-6
lines changed
  • src
    • backend
      • < 8000 div class="PRIVATE_TreeView-item-container prc-TreeView-TreeViewItemContainer--2Rkn" style="--level:3">
        access
  • parser
  • utils/adt
  • bin/pgbench
  • 6 files changed

    +9
    -6
    lines changed

    src/backend/access/gist/gistxlog.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -81,7 +81,7 @@ gistRedoPageUpdateRecord(XLogReaderState *record)
    8181
    char *begin;
    8282
    char *data;
    8383
    Size datalen;
    84-
    int ninserted = 0;
    84+
    int ninserted PG_USED_FOR_ASSERTS_ONLY = 0;
    8585

    8686
    data = begin = XLogRecGetBlockData(record, 0, &datalen);
    8787

    src/backend/access/transam/xlog.c

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1785,7 +1785,7 @@ AdvanceXLInsertBuffer(XLogRecPtr upto, TimeLineID tli, bool opportunistic)
    17851785
    XLogRecPtr NewPageEndPtr = InvalidXLogRecPtr;
    17861786
    XLogRecPtr NewPageBeginPtr;
    17871787
    XLogPageHeader NewPage;
    1788-
    int npages = 0;
    1788+
    int npages pg_attribute_unused() = 0;
    17891789

    17901790
    LWLockAcquire(WALBufMappingLock, LW_EXCLUSIVE);
    17911791

    src/backend/parser/gram.y

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -864,6 +864,7 @@ parse_toplevel:
    864864
    stmtmulti
    865865
    {
    866866
    pg_yyget_extra(yyscanner)->parsetree = $1;
    867+
    (void) yynerrs; /* suppress compiler warning */
    867868
    }
    868869
    | MODE_TYPE_NAME Typename
    869870
    {

    src/backend/utils/adt/array_typanalyze.c

    Lines changed: 1 addition & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -218,7 +218,6 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
    218218
    {
    219219
    ArrayAnalyzeExtraData *extra_data;
    220220
    int num_mcelem;
    221-
    int null_cnt = 0;
    222221
    int null_elem_cnt = 0;
    223222
    int analyzed_rows = 0;
    224223

    @@ -320,8 +319,7 @@ compute_array_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc,
    320319
    value = fetchfunc(stats, array_no, &isnull);
    321320
    if (isnull)
    322321
    {
    323-
    /* array is null, just count that */
    324-
    null_cnt++;
    322+
    /* ignore arrays that are null overall */
    325323
    continue;
    326324
    }
    327325

    src/backend/utils/adt/jsonpath_gram.y

    Lines changed: 1 addition & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -113,6 +113,7 @@ result:
    113113
    *result = palloc(sizeof(JsonPathParseResult));
    114114
    (*result)->expr = $2;
    115115
    (*result)->lax = $1;
    116+
    (void) yynerrs;
    116117
    }
    117118
    | /* EMPTY */ { *result = NULL; }
    118119
    ;

    src/bin/pgbench/exprparse.y

    Lines changed: 4 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -80,7 +80,10 @@ static PgBenchExpr *make_case(yyscan_t yyscanner, PgBenchExprList *when_then_lis
    8080

    8181
    %%
    8282

    83-
    result: expr { expr_parse_result = $1; }
    83+
    result: expr {
    84+
    expr_parse_result = $1;
    85+
    (void) yynerrs; /* suppress compiler warning */
    86+
    }
    8487

    8588
    elist: { $$ = NULL; }
    8689
    | expr { $$ = make_elist($1, NULL); }

    0 commit comments

    Comments
     (0)
    0