Skip to content

Commit f872119

Browse files
committed
amend! build: tolerate use of _Generic from glibc 2.43 with Clang
build: tolerate use of _Generic from glibc 2.43 with Clang When building with `make DEVELOPER=1` we explicitly pass "-std=gnu99" to the compiler so that we don't start leaning on features exposed by more recent versions of the C standard. Unfortunately though, glibc 2.43 started to use type-generic expressions. This works alright with GCC, but when compiling with Clang this leads to errors: $ make DEVELOPER=1 CC=clang CC daemon.o In file included from daemon.c:3: ./git-compat-util.h:344:11: error: '_Generic' is a C11 extension [-Werror,-Wc11-extensions] 344 | return !!strchr(path, '/'); | ^ /usr/include/string.h:265:3: note: expanded from macro 'strchr' 265 | __glibc_const_generic (S, const char *, strchr (S, C)) | ^ /usr/include/x86_64-linux-gnu/sys/cdefs.h:838:3: note: expanded from macro '__glibc_const_generic' 838 | _Generic (0 ? (PTR) : (void *) 1, \ | ^ In theory, the `__glibc_const_generic` macro does have feature gating: #if !defined __cplusplus \ && (__GNUC_PREREQ (4, 9) \ || __glibc_has_extension (c_generic_selections) \ || (!defined __GNUC__ && defined __STDC_VERSION__ \ && __STDC_VERSION__ >= 201112L)) # define __HAVE_GENERIC_SELECTION 1 #else # define __HAVE_GENERIC_SELECTION 0 #endif But this feature gating isn't effective because `_has_extension()` will always evaluate to true as C generics _are_ available as a language extension to GNU C99 when using Clang. This would have been different if `_has_feature()` was used instead, in which case it would have properly evaluated to `false`. GCC has a workaround to squelch this warning from standard system headers, but because clang fails due to [-Werror,-Wc11-extensions], as it lacks the corresponding workaround. For both meson and Makefile, pass -Wno-c11-extensions when we are building with clang. Signed-off-by: Patrick Steinhardt <ps@pks.im> Helped-by: Shardul Natu <snatu@google.com> [jc: replaced Makefile side with Shardul's approach] Signed-off-by: Junio C Hamano <gitster@pobox.com> Assisted-by: Opus 4.7 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 74c3ea9 commit f872119

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

config.mak.dev

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@ endif
2121
endif
2222

2323
ifneq ($(uname_S),FreeBSD)
24-
ifneq ($(filter gcc6,$(COMPILER_FEATURES)),)
24+
ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang7,$(COMPILER_FEATURES))),)
2525
ifndef USE_MIMALLOC
2626
DEVELOPER_CFLAGS += -std=gnu99
2727
endif
2828
endif
2929
else
3030
# FreeBSD cannot limit to C99 because its system headers unconditionally
3131
# rely on C11 features.
32-
#
33-
# Clang cannot limit to C99 when using glibc 2.43 because its system headers
34-
# depend on the _Generic C11 feature. This works with GCC though.
3532
endif
3633

3734
DEVELOPER_CFLAGS += -Wdeclaration-after-statement
@@ -103,6 +100,13 @@ endif
103100
endif
104101
endif
105102

103+
# glibc 2.43 headers unconditionally use _Generic even when we ask the
104+
# compiler to stick to -std=gnu99 and unlike GCC, clang lacks a
105+
# workaround to squelch warnings from system headers.
106+
ifneq ($(filter clang1,$(COMPILER_FEATURES)),) # if we are using clang
107+
DEVELOPER_CFLAGS += -Wno-c11-extensions
108+
endif
109+
106110
# https://bugzilla.redhat.com/show_bug.cgi?id=2075786
107111
ifneq ($(filter gcc12,$(COMPILER_FEATURES)),)
108112
DEVELOPER_CFLAGS += -Wno-error=stringop-overread

0 commit comments

Comments
 (0)