The new clang 23 has a new warning apparently enabled by default (at least by default in a PostgreSQL build) about set-but-unused static global variables: -Wunused-but-set-global. This triggers a few warnings in PostgreSQL code. See attached patches. The first four of these are genuine hits; these variables were never read from or the last reading use was removed some time ago. The last one in pg_ctl is about options that can be set from the command line on any platform but are only used on Windows. This seems kind of weird behavior; maybe in the future we should make those options error out on non-Windows, and then the variables wouldn't be uselessly set.
From 531bd644b73bf2f1d2b0fdc6c55e449cbfe8e2d4 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Fri, 28 Aug 2026 23:06:46 +0200
Subject: [PATCH 1/5] Remove unused global variable [xlog.c]

src/backend/access/transam/xlog.c:675:19: error: variable 
'LocalMinRecoveryPointTLI' set but not used [-Werror,-Wunused-but-set-global]

This was apparently never used (initial commit 70e81861fad).
---
 src/backend/access/transam/xlog.c | 10 ----------
 1 file changed, 10 deletions(-)

diff --git a/src/backend/access/transam/xlog.c 
b/src/backend/access/transam/xlog.c
index 7f5d3b1417a..89d0c32b7e2 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -672,7 +672,6 @@ static TimeLineID openLogTLI = 0;
  * Those values are kept consistent as long as crash recovery runs.
  */
 static XLogRecPtr LocalMinRecoveryPoint;
-static TimeLineID LocalMinRecoveryPointTLI;
 static bool updateMinRecoveryPoint = true;
 
 /*
@@ -2753,7 +2752,6 @@ UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force)
 
        /* update local copy */
        LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
-       LocalMinRecoveryPointTLI = ControlFile->minRecoveryPointTLI;
 
        if (!XLogRecPtrIsValid(LocalMinRecoveryPoint))
                updateMinRecoveryPoint = false;
@@ -2788,7 +2786,6 @@ UpdateMinRecoveryPoint(XLogRecPtr lsn, bool force)
                        ControlFile->minRecoveryPointTLI = 
newMinRecoveryPointTLI;
                        UpdateControlFile();
                        LocalMinRecoveryPoint = newMinRecoveryPoint;
-                       LocalMinRecoveryPointTLI = newMinRecoveryPointTLI;
 
                        ereport(DEBUG2,
                                        errmsg_internal("updated min recovery 
point to %X/%08X on timeline %u",
@@ -3202,7 +3199,6 @@ XLogNeedsFlush(XLogRecPtr record)
                if (!LWLockConditionalAcquire(ControlFileLock, LW_SHARED))
                        return true;
                LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
-               LocalMinRecoveryPointTLI = ControlFile->minRecoveryPointTLI;
                LWLockRelease(ControlFileLock);
 
                /*
@@ -6208,12 +6204,10 @@ StartupXLOG(void)
                if (InArchiveRecovery)
                {
                        LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
-                       LocalMinRecoveryPointTLI = 
ControlFile->minRecoveryPointTLI;
                }
                else
                {
                        LocalMinRecoveryPoint = InvalidXLogRecPtr;
-                       LocalMinRecoveryPointTLI = 0;
                }
 
                /* Check that the GUCs used to generate the WAL allow recovery 
*/
@@ -6749,7 +6743,6 @@ SwitchIntoArchiveRecovery(XLogRecPtr EndRecPtr, 
TimeLineID replayTLI)
        }
        /* update local copy */
        LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
-       LocalMinRecoveryPointTLI = ControlFile->minRecoveryPointTLI;
 
        /*
         * The startup process can update its local copy of minRecoveryPoint 
from
@@ -8309,7 +8302,6 @@ CreateRestartPoint(int flags)
 
                                /* update local copy */
                                LocalMinRecoveryPoint = 
ControlFile->minRecoveryPoint;
-                               LocalMinRecoveryPointTLI = 
ControlFile->minRecoveryPointTLI;
                        }
                        if (flags & CHECKPOINT_IS_SHUTDOWN)
                                ControlFile->state = DB_SHUTDOWNED_IN_RECOVERY;
@@ -9154,7 +9146,6 @@ xlog_redo(XLogReaderState *record)
                if (InArchiveRecovery)
                {
                        LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
-                       LocalMinRecoveryPointTLI = 
ControlFile->minRecoveryPointTLI;
                }
                if (XLogRecPtrIsValid(LocalMinRecoveryPoint) && 
LocalMinRecoveryPoint < lsn)
                {
@@ -9300,7 +9291,6 @@ xlog2_redo(XLogReaderState *record)
                if (InArchiveRecovery)
                {
                        LocalMinRecoveryPoint = ControlFile->minRecoveryPoint;
-                       LocalMinRecoveryPointTLI = 
ControlFile->minRecoveryPointTLI;
                }
                if (XLogRecPtrIsValid(LocalMinRecoveryPoint) && 
LocalMinRecoveryPoint < lsn)
                {

base-commit: 7ddb9c41a13534011bb64a856fb5a60e41b82b75
-- 
2.55.0

From 3e4957dcb0ed5d2512ed2d9fbd55a3c1df23bc1e Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Fri, 28 Aug 2026 23:08:56 +0200
Subject: [PATCH 2/5] Remove unused global variable [test_resowner]

src/test/modules/test_resowner/test_resowner_many.c:49:29: error: variable 
'current_release_phase' set but not used [-Werror,-Wunused-but-set-global]

This was apparently never used (initial commit b8bff07daa8).
---
 src/test/modules/test_resowner/test_resowner_many.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/test/modules/test_resowner/test_resowner_many.c 
b/src/test/modules/test_resowner/test_resowner_many.c
index 4962b371bdc..40a3948ae04 100644
--- a/src/test/modules/test_resowner/test_resowner_many.c
+++ b/src/test/modules/test_resowner/test_resowner_many.c
@@ -43,10 +43,9 @@ typedef struct
 } ManyTestResource;
 
 /*
- * Current release phase, and priority of last call to the release callback.
+ * Current release priority of last call to the release callback.
  * This is used to check that the resources are released in correct order.
  */
-static ResourceReleasePhase current_release_phase;
 static uint32 last_release_priority = 0;
 
 /* prototypes for local functions */
@@ -272,18 +271,15 @@ test_resowner_many(PG_FUNCTION_ARGS)
 
        /* Start releasing */
        elog(NOTICE, "releasing resources before locks");
-       current_release_phase = RESOURCE_RELEASE_BEFORE_LOCKS;
        last_release_priority = 0;
        ResourceOwnerRelease(resowner, RESOURCE_RELEASE_BEFORE_LOCKS, false, 
false);
        Assert(GetTotalResourceCount(before_kinds, nkinds) == 0);
 
        elog(NOTICE, "releasing locks");
-       current_release_phase = RESOURCE_RELEASE_LOCKS;
        last_release_priority = 0;
        ResourceOwnerRelease(resowner, RESOURCE_RELEASE_LOCKS, false, false);
 
        elog(NOTICE, "releasing resources after locks");
-       current_release_phase = RESOURCE_RELEASE_AFTER_LOCKS;
        last_release_priority = 0;
        ResourceOwnerRelease(resowner, RESOURCE_RELEASE_AFTER_LOCKS, false, 
false);
        Assert(GetTotalResourceCount(before_kinds, nkinds) == 0);
-- 
2.55.0

From 924cf10bfe8443974725c4bacd304b50494ab407 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Fri, 28 Aug 2026 23:10:47 +0200
Subject: [PATCH 3/5] Remove unused global variable [pg_dump]

src/bin/pg_dump/pg_dump_sort.c:160:15: error: variable 'preDataBoundId' set but 
not used [-Werror,-Wunused-but-set-global]

This was apparently never used (initial commit a1ef01fe163).
---
 src/bin/pg_dump/pg_dump_sort.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index 03e5c1c1116..3496303932b 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -157,7 +157,6 @@ static const int dbObjectTypePriority[] =
 StaticAssertDecl(lengthof(dbObjectTypePriority) == NUM_DUMPABLE_OBJECT_TYPES,
                                 "array length mismatch");
 
-static DumpId preDataBoundId;
 static DumpId postDataBoundId;
 
 
@@ -569,7 +568,6 @@ sortDumpableObjects(DumpableObject **objs, int numObjs,
         * Saving the boundary IDs in static variables is a bit grotty, but 
seems
         * better than adding them to parameter lists of subsidiary functions.
         */
-       preDataBoundId = preBoundaryId;
        postDataBoundId = postBoundaryId;
 
        ordering = pg_malloc_array(DumpableObject *, numObjs);
-- 
2.55.0

From 85ae2328696b7ac1cb02d4842fabc8216646f3bb Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Fri, 28 Aug 2026 23:18:31 +0200
Subject: [PATCH 4/5] Remove unused global variable [postmaster]

src/backend/postmaster/postmaster.c:372:13: error: variable 
'ReachedNormalRunning' set but not used [-Werror,-Wunused-but-set-global]

The last use was removed in commit 39969e2a1e4.
---
 src/backend/postmaster/postmaster.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/backend/postmaster/postmaster.c 
b/src/backend/postmaster/postmaster.c
index c5b141ed3e3..4d5338a462d 100644
--- a/src/backend/postmaster/postmaster.c
+++ b/src/backend/postmaster/postmaster.c
@@ -369,8 +369,6 @@ static time_t AbortStartTime = 0;
 /* Length of said timeout */
 #define SIGKILL_CHILDREN_AFTER_SECS            5
 
-static bool ReachedNormalRunning = false;      /* T if we've reached PM_RUN */
-
 bool           ClientAuthInProgress = false;   /* T during new-client
                                                                                
         * authentication */
 
@@ -2362,7 +2360,6 @@ process_pm_child_exit(void)
                        StartupStatus = STARTUP_NOT_RUNNING;
                        FatalError = false;
                        AbortStartTime = 0;
-                       ReachedNormalRunning = true;
                        UpdatePMState(PM_RUN);
                        connsAllowed = true;
 
-- 
2.55.0

From 526d5dfac2c4ea95094944b15e652ff8259de89a Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <[email protected]>
Date: Fri, 28 Aug 2026 23:23:12 +0200
Subject: [PATCH 5/5] Silence warnings about unused global variables [pg_ctl]

Several global variables are only used in Windows build.

This patch marks these with an unused attribute to silence warnings.

Alternatively, this code should perhaps be restricted to Windows more
consistently.  For example, currently you can use the -e option on any
platform, but it only does something on Windows.
---
 src/bin/pg_ctl/pg_ctl.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index b5433a75d12..271d545da59 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -75,7 +75,7 @@ StaticAssertDecl(USECS_PER_SEC % WAITS_PER_SEC == 0,
 
 static bool do_wait = true;
 static int     wait_seconds = DEFAULT_WAIT;
-static bool wait_seconds_arg = false;
+pg_attribute_unused() static bool wait_seconds_arg = false;
 static bool silent_mode = false;
 static ShutdownMode shutdown_mode = FAST_MODE;
 static int     sig = SIGINT;           /* default */
@@ -87,10 +87,10 @@ static char *post_opts = NULL;
 static const char *progname;
 static char *log_file = NULL;
 static char *exec_path = NULL;
-static char *event_source = NULL;
-static char *register_servicename = "PostgreSQL";      /* FIXME: + version ID? 
*/
-static char *register_username = NULL;
-static char *register_password = NULL;
+pg_attribute_unused() static char *event_source = NULL;
+pg_attribute_unused() static char *register_servicename = "PostgreSQL"; /* 
FIXME: + version ID? */
+pg_attribute_unused() static char *register_username = NULL;
+pg_attribute_unused() static char *register_password = NULL;
 static char *argv0 = NULL;
 static bool allow_core_files = false;
 static time_t start_time;
-- 
2.55.0

Reply via email to