Skip to content

var: drop the write-only variable index - #436

Open
andypost wants to merge 1 commit into
masterfrom
build/clang23-unused-var
Open

andypost wants to merge 1 commit into
masterfrom
build/clang23-unused-var

Conversation

@andypost

Copy link
Copy Markdown

Problem

The scheduled "Build (Fedora/Alpine · GCC/Clang)" workflow fails on both clang legs since the images moved to clang 23 (Alpine clang 23.1.1, Fedora clang 23.1.0); the gcc legs pass:

https://github.com/freeunitorg/freeunit/actions/runs/35585942071

src/nxt_var.c:75:29: error: variable 'nxt_vars' set but not used [-Werror,-Wunused-but-set-global]

The last green run (https://github.com/freeunitorg/freeunit/actions/runs/33384248955, 2026-08-31) used Alpine clang 22.1.8; the first red one (https://github.com/freeunitorg/freeunit/actions/runs/34830122484, 2026-09-14) was already on 23.x. No source change is involved. The clang 23 release notes add -Wunused-but-set-global as a new subgroup of -Wunused-but-set-variable (in -Wall) covering file-scope statics; configure adds -Werror, so the new warning is fatal.

Fix

The diagnostic is right, so delete the dead code rather than suppress the flag.

nxt_vars is a file-static pointer written once by nxt_var_index_init() and never read; git log -S nxt_vars -- src/nxt_var.c shows no reader in the whole history of the file. That makes nxt_var_index_init() dead at startup: it nxt_memalign(64, …)s an array of every registered variable, copies the hash into it, stores the pointer and returns. nxt_var_count exists only to size that array. Remove the index, the counter, the prototype in nxt_var.h and the call in nxt_runtime_create(); the surrounding goto fail chain is unchanged.

No user-visible change, so no CHANGES / changes.xml entry.

Verification

  • Reproduced the error on unmodified origin/master in alpine:edge with clang 23.1.1 (./configure --cc=clang --openssl --tests && make unitd); with make -k it is the only error in the tree, so no other file trips the new warning.
  • With this patch, the same container builds unitd cleanly; unitd --version reports 1.36.1 and a --no-daemon start brings up controller and router and exits cleanly on SIGTERM.
  • Local no-regression builds: gcc 15.2.0 and clang 21.1.8 (make unitd), plus make tests under clang 21 with the C test binary passing.

🤖 Generated with Claude Code

clang 23 adds -Wunused-but-set-global, a subgroup of the
-Wunused-but-set-variable that -Wall already enables, and configure
adds -Werror.  It fails the build on nxt_vars:

    src/nxt_var.c:75:29: error: variable 'nxt_vars' set but not used

The diagnostic is right.  nxt_vars is a file-static pointer that
nxt_var_index_init() fills and nothing reads; the history of nxt_var.c
never had a reader.  So the whole function is dead at startup: it
allocates a 64-byte aligned array of every registered variable, copies
the hash into it, stores the pointer and returns.  nxt_var_count exists
only to size that array.

Remove the index, its counter, the prototype and the call from
nxt_runtime_create().  The remaining nxt_var_register() failure path is
unchanged.  No behaviour changes; the startup allocation goes away.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant