Suppress more variable-set-but-not-used warnings from clang 15.
authorTom Lane <[email protected]>
Wed, 21 Sep 2022 17:52:38 +0000 (13:52 -0400)
committerTom Lane <[email protected]>
Wed, 21 Sep 2022 17:52:38 +0000 (13:52 -0400)
Mop up assorted set-but-not-used warnings in the back branches.
This includes back-patching relevant fixes from commit 152c9f7b8
the rest of the way, but there are also several cases that did not
appear in HEAD.  Some of those we'd fixed in a retail way but not
back-patched, and others I think just got rewritten out of existence
during nearby refactoring.

While here, also back-patch b1980f6d0 (PL/Tcl: Fix compiler warnings
with Tcl 8.6) into 9.2, so that that branch compiles warning-free
with modern Tcl.

Per 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 all the way to 9.2.

Discussion: https://postgr.es/m/514615.1663615243@sss.pgh.pa.us

contrib/hstore/crc32.c
contrib/ltree/crc32.c
src/backend/access/gin/gindatapage.c
src/backend/optimizer/util/var.c
src/backend/parser/gram.y
src/backend/utils/adt/array_typanalyze.c
src/backend/utils/adt/varlena.c
src/pl/tcl/pltcl.c

index d541d0cc951b15d35fe46ddb9f6fe5c99589cb15..2b59d1e3bba1809637c2f4a368484a6953ff48ff 100644 (file)
@@ -95,12 +95,10 @@ crc32_sz(char *buf, int size)
 {
    unsigned int crc = ~((unsigned int) 0);
    char       *p;
-   int         len,
-               nr;
+   int         nr;
 
-   len = 0;
    nr = size;
-   for (len += nr, p = buf; nr--; ++p)
+   for (p = buf; nr--; ++p)
        _CRC32_(crc, *p);
    return ~crc;
 }
index ea1a661fefbbceaab5f3bf503a8ab68aab2dfeaa..9c62216dd7340bdadaa4498882c7235756b6f2b0 100644 (file)
@@ -103,12 +103,10 @@ ltree_crc32_sz(char *buf, int size)
 {
    unsigned int crc = ~((unsigned int) 0);
    char       *p;
-   int         len,
-               nr;
+   int         nr;
 
-   len = 0;
    nr = size;
-   for (len += nr, p = buf; nr--; ++p)
+   for (p = buf; nr--; ++p)
        _CRC32_(crc, TOLOWER((unsigned int) *p));
    return ~crc;
 }
index 2e14d5636a7ab7ec93cff8088c3878e1f234eb51..e0702950d8d10cd4d6d147ecdfd46f5a7963a29b 100644 (file)
@@ -465,7 +465,6 @@ dataSplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogRe
    Page        rpage = BufferGetPage(rbuf);
    Size        pageSize = PageGetPageSize(lpage);
    Size        freeSpace;
-   uint32      nCopied = 1;
 
    /* these must be static so they can be returned to caller */
    static ginxlogSplit data;
@@ -485,7 +484,6 @@ dataSplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogRe
 
    if (GinPageIsLeaf(lpage) && GinPageRightMost(lpage) && off > GinPageGetOpaque(lpage)->maxoff)
    {
-       nCopied = 0;
        while (btree->curitem < btree->nitem &&
               maxoff * sizeof(ItemPointerData) < 2 * (freeSpace - sizeof(ItemPointerData)))
        {
@@ -493,7 +491,6 @@ dataSplitPage(GinBtree btree, Buffer lbuf, Buffer rbuf, OffsetNumber off, XLogRe
                   btree->items + btree->curitem,
                   sizeof(ItemPointerData));
            maxoff++;
-           nCopied++;
            btree->curitem++;
        }
    }
index d2b1604e16a6a66184f28924db865b2bd28b57c0..8b2fbf956bb05cf0c1d8b781da251c86873caedd 100644 (file)
@@ -784,16 +784,13 @@ flatten_join_alias_vars_mutator(Node *node,
            RowExpr    *rowexpr;
            List       *fields = NIL;
            List       *colnames = NIL;
-           AttrNumber  attnum;
            ListCell   *lv;
            ListCell   *ln;
 
-           attnum = 0;
            Assert(list_length(rte->joinaliasvars) == list_length(rte->eref->colnames));
            forboth(lv, rte->joinaliasvars, ln, rte->eref->colnames)
            {
                newvar = (Node *) lfirst(lv);
-               attnum++;
                /* Ignore dropped columns */
                if (newvar == NULL)
                    continue;
index 4182f2fd7116a75b4e7d1130eaed99c501593120..39a917c29500dde19e330f170138a6c276793abf 100644 (file)
@@ -653,6 +653,7 @@ static void processCASbits(int cas_bits, int location, const char *constrType,
 stmtblock: stmtmulti
            {
                pg_yyget_extra(yyscanner)->parsetree = $1;
+               (void) yynerrs;     /* suppress compiler warning */
            }
        ;
 
index 62e398b1d13a3798b9cf23a96a3a320d5cc0e66d..5369eeb50400b539389495a3590e7457b02ce8db 100644 (file)
@@ -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;
 
@@ -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;
        }
 
index aa27a4b5c06f4138ba0270eb9c9f39f6dd79f8eb..18f3971d70b1707190359043b4c4ce12f1e8e198 100644 (file)
@@ -3169,7 +3169,6 @@ text_to_array_internal(PG_FUNCTION_ARGS)
         * to search for occurrences of fldsep.
         */
        TextPositionState state;
-       int         fldnum;
        int         start_posn;
        int         end_posn;
        int         chunk_len;
@@ -3209,7 +3208,7 @@ text_to_array_internal(PG_FUNCTION_ARGS)
        /* start_ptr points to the start_posn'th character of inputstring */
        start_ptr = VARDATA_ANY(inputstring);
 
-       for (fldnum = 1;; fldnum++)     /* field number is 1 based */
+       for (;;)
        {
            CHECK_FOR_INTERRUPTS();
 
index d3c59797239b87f9fbe9de2a7be7e12f50b870f9..5f5601bd2fd114930fae9220edc16b68dc0392b2 100644 (file)
 #define CONST84
 #endif
 
+/* ... and for Tcl 8.6. */
+#ifndef CONST86
+#define CONST86
+#endif
+
 #include "access/xact.h"
 #include "catalog/pg_proc.h"
 #include "catalog/pg_type.h"
@@ -258,7 +263,7 @@ pltcl_FinalizeNotifier(ClientData clientData)
 }
 
 static void
-pltcl_SetTimer(Tcl_Time *timePtr)
+pltcl_SetTimer(CONST86 Tcl_Time *timePtr)
 {
 }
 
@@ -284,7 +289,7 @@ pltcl_ServiceModeHook(int mode)
 }
 
 static int
-pltcl_WaitForEvent(Tcl_Time *timePtr)
+pltcl_WaitForEvent(CONST86 Tcl_Time *timePtr)
 {
    return 0;
 }