[PATCH 06/13] selftest: af_unix: Support compilers without flex-array-member-not-at-end support

Guenter Roeck posted 13 patches 2 months ago
[PATCH 06/13] selftest: af_unix: Support compilers without flex-array-member-not-at-end support
Posted by Guenter Roeck 2 months ago
Fix:

gcc: error: unrecognized command-line option ‘-Wflex-array-member-not-at-end’

by making the compiler option dependent on its support.

Fixes: 1838731f1072c ("selftest: af_unix: Add -Wall and -Wflex-array-member-not-at-end to CFLAGS.")
Cc: Kuniyuki Iwashima <kuniyu@google.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
 tools/testing/selftests/net/af_unix/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/af_unix/Makefile b/tools/testing/selftests/net/af_unix/Makefile
index 528d14c598bb..04e82a8d21db 100644
--- a/tools/testing/selftests/net/af_unix/Makefile
+++ b/tools/testing/selftests/net/af_unix/Makefile
@@ -1,4 +1,4 @@
-CFLAGS += $(KHDR_INCLUDES) -Wall -Wflex-array-member-not-at-end
+CFLAGS += $(KHDR_INCLUDES) -Wall $(call cc-option,-Wflex-array-member-not-at-end)
 
 TEST_GEN_PROGS := \
 	diag_uid \
-- 
2.43.0

Re: [PATCH 06/13] selftest: af_unix: Support compilers without flex-array-member-not-at-end support
Posted by Jakub Kicinski 2 months ago
On Thu,  4 Dec 2025 08:17:20 -0800 Guenter Roeck wrote:
> -CFLAGS += $(KHDR_INCLUDES) -Wall -Wflex-array-member-not-at-end
> +CFLAGS += $(KHDR_INCLUDES) -Wall $(call cc-option,-Wflex-array-member-not-at-end)

Hm, the Claude code review we have hooked up to patchwork says:

  Is cc-option available in the selftest build environment? Looking at
  tools/testing/selftests/lib.mk (included at line 14), it doesn't include
  scripts/Makefile.compiler where cc-option is defined. When cc-option is
  undefined, $(call cc-option,...) expands to an empty string, which means
  the -Wflex-array-member-not-at-end flag won't be added even on compilers
  that support it.

  This defeats the purpose of commit 1838731f1072c which added the warning
  flag to catch flexible array issues.

  For comparison, tools/testing/selftests/nolibc/Makefile explicitly
  includes scripts/Makefile.compiler before using cc-option.

Testing it:

$ make -C tools/testing/selftests/ TARGETS=net/af_unix Q= V=1
make: Entering directory '/home/kicinski/devel/linux/tools/testing/selftests'
make[1]: Entering directory '/home/kicinski/devel/linux/tools/testing/selftests/net/af_unix'
gcc -isystem /home/kicinski/devel/linux/usr/include -Wall  -D_GNU_SOURCE=     diag_uid.c  -o /home/kicinski/devel/linux/tools/testing/selftests/net/af_unix/diag_uid

looks like the flag just disappears. Even tho:

gcc version 15.2.1
Re: [PATCH 06/13] selftest: af_unix: Support compilers without flex-array-member-not-at-end support
Posted by Guenter Roeck 2 months ago
On Thu, Dec 04, 2025 at 09:40:54AM -0800, Jakub Kicinski wrote:
> On Thu,  4 Dec 2025 08:17:20 -0800 Guenter Roeck wrote:
> > -CFLAGS += $(KHDR_INCLUDES) -Wall -Wflex-array-member-not-at-end
> > +CFLAGS += $(KHDR_INCLUDES) -Wall $(call cc-option,-Wflex-array-member-not-at-end)
> 
> Hm, the Claude code review we have hooked up to patchwork says:
> 
>   Is cc-option available in the selftest build environment? Looking at
>   tools/testing/selftests/lib.mk (included at line 14), it doesn't include
>   scripts/Makefile.compiler where cc-option is defined. When cc-option is
>   undefined, $(call cc-option,...) expands to an empty string, which means
>   the -Wflex-array-member-not-at-end flag won't be added even on compilers
>   that support it.
> 
>   This defeats the purpose of commit 1838731f1072c which added the warning
>   flag to catch flexible array issues.
> 
>   For comparison, tools/testing/selftests/nolibc/Makefile explicitly
>   includes scripts/Makefile.compiler before using cc-option.
> 
> Testing it:
> 
> $ make -C tools/testing/selftests/ TARGETS=net/af_unix Q= V=1
> make: Entering directory '/home/kicinski/devel/linux/tools/testing/selftests'
> make[1]: Entering directory '/home/kicinski/devel/linux/tools/testing/selftests/net/af_unix'
> gcc -isystem /home/kicinski/devel/linux/usr/include -Wall  -D_GNU_SOURCE=     diag_uid.c  -o /home/kicinski/devel/linux/tools/testing/selftests/net/af_unix/diag_uid
> 
> looks like the flag just disappears. Even tho:
> 
> gcc version 15.2.1 

Oops :). I didn't expect that, sorry. Thanks for finding!

... and I guess it's time to set up AI in my environment.

Guenter