Re: [PATCH] config.mak.dev: enable -Wunreachable-code
- From
Mike Hommey <mh@glandium.org>
- Date
- Jun 3, 2025, 21:29 UTC
- Message-ID
- <20250603212934.uojo22zjcuf6yfic@glandium.org>
- In-Reply-To
- <20250308032309.GA584028@coredump.intra.peff.net>
On Fri, Mar 07, 2025 at 10:23:09PM -0500, Jeff King wrote:
Show 35 quoted lines
> On Fri, Mar 07, 2025 at 05:54:45PM -0500, Jeff King wrote:
>
> > However, clang does implement this option, and it finds the case
> > mentioned above (and no other cases within the code base). And since we
> > run clang in several of our CI jobs, that's enough to get an early
> > warning of breakage.
>
> Hmph, this might be more trouble than it is worth.
>
> After correcting the problem in the refs code, the osx CI builds (and
> only those) now fail with:
>
> run-command.c:519:3: error: code will never be executed [-Werror,-Wunreachable-code]
> die_errno("sigfillset");
> ^~~~~~~~~
>
> The code in question is just:
>
> if (sigfillset(&all))
> die_errno("sigfillset");
>
> So I have to imagine that the issue is that sigfillset() on that
> platform is an inline or macro that will never return an error, and the
> compiler can see that. But since POSIX says this can fail (though I'd
> imagine it's unlikely on most platforms), we should check in the general
> case.
>
> So I don't see how to solve it short of:
>
> #ifdef SIGFILLSET_CANNOT_FAIL
> sigfillset(&all);
> #else
> if (sigfillset(&all))
> die_errno("sigfillset");
> #endifThere is a similar problem with this code in refs/files-backend.c:
if (!create_ref_symlink(lock, update->new_target)) continue;
Where create_ref_symlink is defined as such:
#ifdef NO_SYMLINK_HEAD #define create_ref_symlink(a, b) (-1) #else static int create_ref_symlink(struct ref_lock *lock, const char *target) { ... #endif
And NO_SYMLINK_HEAD is defined on Windows.
Mike