git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] refs: forbid clang to complain about unreachable code

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 10, 2025, 05:34 UTC
Message-ID
<aOia55_sjFQjw1UQ@pks.im>
In-Reply-To
<pull.1984.git.1759995982220.gitgitgadget@gmail.com>
On Thu, Oct 09, 2025 at 07:46:22AM +0000, Johannes Schindelin via GitGitGadget wrote:
Show 17 quoted lines
> diff --git a/refs/files-backend.c b/refs/files-backend.c
> index 088b52c740..814decf323 100644
> --- a/refs/files-backend.c
> +++ b/refs/files-backend.c
> @@ -3186,7 +3186,13 @@ static int files_transaction_finish(struct ref_store *ref_store,
>  		 * next update. If not, we try and create a regular symref.
>  		 */
>  		if (update->new_target && refs->prefer_symlink_refs)
> -			if (!create_ref_symlink(lock, update->new_target))
> +			/*
> +			 * By using the `NOT_CONSTANT()` trick, we can avoid
> +			 * errors by `clang`'s `-Wunreachable` logic that would
> +			 * report that the `continue` statement is not reachable
> +			 * when `NO_SYMLINK_HEAD` is `#define`d.
> +			 */
> +			if (NOT_CONSTANT(!create_ref_symlink(lock, update->new_target)))
>  				continue;

An alternative could be to fix this at the source, e.g. like the below (untested) patch. But I don't mind this too much, especially given that this here is the only callsite of that function anyway. So please feel free to disregard.

Thanks!
Patrick
diff --git a/refs/files-backend.c b/refs/files-backend.c
index bb2bec3807..cb402a2a54 100644
--- a/refs/files-backend.c
+++ b/refs/files-backend.c
@@ -2115,7 +2115,7 @@ static int commit_ref_update(struct files_ref_store *refs,
 }
 
 #ifdef NO_SYMLINK_HEAD
-#define create_ref_symlink(a, b) (-1)
+#define create_ref_symlink(a, b) NOT_CONSTANT(-1)
 #else
 static int create_ref_symlink(struct ref_lock *lock, const char *target)
 {
Previous: Patrick SteinhardtNext: Johannes Schindelin
Message 4 of 7 in “refs: forbid clang to complain about unreachable code”
  1. refs: forbid clang to complain about unreachable codeJohannes Schindelin via GitGitGadget, Oct 9, 2025
  2. Junio C HamanoOct 9, 2025
  3. Patrick SteinhardtOct 10, 2025
  4. Patrick SteinhardtOct 10, 2025
  5. Johannes SchindelinOct 10, 2025
  6. Patrick SteinhardtOct 11, 2025
  7. Junio C HamanoOct 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.