Thread (9 messages) 9 messages, 4 authors, 2022-07-15

Re: [PATCH] unpack-objects: fix compilation warning/error due to missing braces

From: Ævar Arnfjörð Bjarmason <hidden>
Date: 2022-07-12 09:29:47

Possibly related (same subject, not in this thread)

On Tue, Jul 12 2022, Jeff King wrote:
On Tue, Jul 12, 2022 at 03:13:50AM -0400, Eric Sunshine wrote:
quoted
quoted
Since this is only a warning, and only a practical issue with -Werror I
wonder if a config.mak.dev change wouldn't be better, i.e. to provide a
-Wno-missing-braces for this older clang version.
I'm in favor of this. It would, of course, require extra
special-casing for Apple's clang for which the version number bears no
resemblance to reality since Apple invents their own version numbers.
FWIW I was imagining just providing that -Wno-* on clang versions <= 11,
not special-casing Apple's in particular.

If you want to make it more strict you can always compare against the
uname, at this point in config.mak.dev we've already sourced
config.mak.uname, so you can guard this with "ifeq ($(uname_S),Darwin)".

Of course that doesn't tell you if it's Apple's clang, just "a clang on
Apple", but it should be close enough not to matter...
I got PTSD reading that thread again, but in case anybody wants to dig
into this, I think there are some hints from the last time we discussed
this (starting at the end of this message and the subthread):

  https://lore.kernel.org/git/YQ2LdvwEnZN9LUQn@coredump.intra.peff.net/ (local)
Oh yes, the config.mak.dev horror show :)

I have a local patches that carry forward the idea I had in that thread,
i.e. to drop all this version detection insanity and just compile a C
program to detect the compiler.

It takes a bit of doing in the Makefile, but I think the end result is
lovely compared to the status quo. We just do:

	$ head -n 2 config.mak.dev
	include .build/probe/compiler.mak
	include .build/probe/config-mak-dev.mak
	[The rest is all using existing defined variables, no shell magic]

Which is just made with a Makefile by piping this sort of thing to those
.build files:
	
	$ ./.build/probe/config-mak-dev 
	PROBE_COMPILER_NEEDS_std-eq-gnu99 = 1
	PROBE_COMPILER_HAS_Wtautological-constant-out-of-range-compare = 1
	PROBE_COMPILER_HAS_Wextra = 1
	PROBE_COMPILER_HAS_Wpedantic = 1

Which in turn is generated with stand-alone C programs in probe/, which
don't need any of the rest of git:
	
	$ cat probe/config-mak-dev.c
	
	#ifdef PROBE_STANDALONE
	#include <stdlib.h>
	#else
	#include "git-compat-util.h"
	#endif
	
	#include "probe/compiler.h"
	#ifdef __GLIBC__
	#include <gnu/libc-version.h>
	#endif
	
	int probe_config_mak_dev(probe_info_fn_t fn, void *util)
	{
	#ifdef __clang__
	#if __clang_major__ >= 7
		fn(util, "NEEDS_std-eq-gnu99", "1");
	#endif
	#ifndef __has_warning
	#error "Clang version too old to support __has_warning!"
	#endif
	#if __has_warning("-Wtautological-constant-out-of-range-compare")
		fn(util, "HAS_Wtautological-constant-out-of-range-compare", "1");
	#endif
	#if __has_warning("-Wextra")
		fn(util, "HAS_Wextra", "1");
	#endif
	#if __has_warning("-Wpedantic")
		fn(util, "HAS_Wpedantic", "1");
	#endif /* __clang__ */
	
	#elif defined(__GNUC__)
	#if __GNUC__ == 4
		fn(util, "NEEDS_Wno-uninitialized", "1");
	#endif
	#if __GNUC__ >= 5
		fn(util, "HAS_Wpedantic", "1");
	#if __GNUC__ >= 6
		fn(util, "NEEDS_std-eq-gnu99", "1");
		fn(util, "HAS_Wextra", "1");
	#if __GNUC__ >= 10
		fn(util, "HAS_Wno-pedantic-ms-format", "1");
	#endif /* >= 10 */
	#endif /* >= 6 */
	#endif /* >= 5 */
	
	#elif defined(__IBMC__)
	
	#else
		return -1;
	#endif
		return 0;
	}
	
	#ifdef PROBE_STANDALONE
	#include <stdio.h>
	#include "probe/print.h"
	
	int main(void)
	{
		struct probe_print_data data = {
			.prefix = "PROBE_COMPILER_",
		};
	
		if (probe_config_mak_dev(probe_print, &data) < 0)
			fprintf(stderr, "warning: unable to detect compiler type and version\n");
		return 0;
	}
	#endif

The compilation is then triggered by the include in config.mak.dev,
which has a corresponding rule that creates the C program, then the
generated *.mak, so once we do it once we're only ever including an
already generated text file.

It takes a bit of doing in the Makfile, since we need to e.g. declare
that "artifacts-tar", "check-docs" etc. don't want to build this C
program to "configure bootstrap" even if under DEVELOPER=1, i.e. we need
to know which target(s) we'll run to compile C code.

But that has the bonus benefit of making those faster, as now we'll
e.g. $(shell detect-compiler), generate the version info etc., only to
run "$(MAKE) -C Documentation/ ..." or whatever.

I can clean it up for submission if there's interest.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help