Skip to contentSkip to conversation

selftests/futex: clang-inspired fixes

PATCH In review John Hubbard 2 participants 5 messages May 31, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover selftests/futex: clang-inspired fixes

Hi,

Here's a few fixes that are part of my effort to get all selftests building cleanly under clang. Plus one that I noticed by inspection.

Changes since v2:

1) Added a sentence to the .PHONY patch, to show that it is removing duplicate code.

2) Added the actual clang warning output to the commit description.

Changes since the first version:

1) Rebased onto Linux 6.10-rc1
2) Added Reviewed-by's.

...and it turns out that all three patches are still required, on -rc1, in order to get a clean clang build.

Enjoy!

thanks,
John Hubbard

John Hubbard (3):
selftests/futex: don't redefine .PHONY targets (all, clean) selftests/futex: don't pass a const char* to asprintf(3) selftests/futex: pass _GNU_SOURCE without a value to the compiler

 tools/testing/selftests/futex/Makefile                      | 2 --
 tools/testing/selftests/futex/functional/Makefile           | 2 +-
 tools/testing/selftests/futex/functional/futex_requeue_pi.c | 2 +-
 3 files changed, 2 insertions(+), 4 deletions(-)

base-commit: b050496579632f86ee1ef7e7501906db579f3457

Signature · 1 line
2.45.1
#1 lore raw

PATCH v3 1/3 selftests/futex: don't redefine .PHONY targets (all, clean)

The .PHONY targets "all" and "clean" are both already defined in the file that is included in the very next line:

    ../lib.mk.

Remove this duplicate code.

---
 tools/testing/selftests/futex/Makefile | 2 --
 1 file changed, 2 deletions(-)
tools/testing/selftests/futex/Makefile +0 -2
index 11e157d7533b..78ab2cd111f6 100644
@@ -3,8 +3,6 @@ SUBDIRS := functional
 
 TEST_PROGS := run.sh
 
-.PHONY: all clean
-
 include ../lib.mk
 
 all:
Signature · 1 line
2.45.1
#2 lore raw

PATCH v3 2/3 selftests/futex: don't pass a const char* to asprintf(3)

In reply to John Hubbard

When building with clang, via:

make LLVM=1 -C tools/testing/selftests

...clang issues this warning:

futex_requeue_pi.c:403:17: warning: passing 'const char **' to parameter of type 'char **' discards qualifiers in nested pointer types [-Wincompatible-pointer-types-discards-qualifiers]

This warning fires because test_name is passed into asprintf(3), which then changes it.

Fix this by simply removing the const qualifier. This is a local automatic variable in a very short function, so there is not much need to use the compiler to enforce const-ness at this scope.

[1] https://lore.kernel.org/all/20240329-selftests-libmk-llvm-rfc-v1-1-2f9ed7d1c49f@valentinobst.de/

Fixes f17d8a87ecb5 ("selftests: fuxex: Report a unique test name per run of futex_requeue_pi")
---
 tools/testing/selftests/futex/functional/futex_requeue_pi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/futex/functional/futex_requeue_pi.c +1 -1
index 7f3ca5c78df1..215c6cb539b4 100644
@@ -360,7 +360,7 @@ int unit_test(int broadcast, long lock, int third_party_owner, long timeout_ns)
 
 int main(int argc, char *argv[])
 {
-	const char *test_name;
+	char *test_name;
 	int c, ret;
 
 	while ((c = getopt(argc, argv, "bchlot:v:")) != -1) {
Signature · 1 line
2.45.1
#3 lore raw

PATCH v3 3/3 selftests/futex: pass _GNU_SOURCE without a value to the compiler

In reply to John Hubbard

It's slightly better to set _GNU_SOURCE in the source code, but if one must do it via the compiler invocation, then the best way to do so is this:

    $(CC) -D_GNU_SOURCE=

...because otherwise, if this form is used:

    $(CC) -D_GNU_SOURCE

...then that leads the compiler to set a value, as if you had passed in:

    $(CC) -D_GNU_SOURCE=1

That, in turn, leads to warnings under both gcc and clang, like this:

futex_requeue_pi.c:20: warning: "_GNU_SOURCE" redefined

Fix this by using the "-D_GNU_SOURCE=" form.

---
 tools/testing/selftests/futex/functional/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/futex/functional/Makefile +1 -1
index a392d0917b4e..994fa3468f17 100644
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0
 INCLUDES := -I../include -I../../ $(KHDR_INCLUDES)
-CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE -pthread $(INCLUDES) $(KHDR_INCLUDES)
+CFLAGS := $(CFLAGS) -g -O2 -Wall -D_GNU_SOURCE= -pthread $(INCLUDES) $(KHDR_INCLUDES)
 LDLIBS := -lpthread -lrt
 
 LOCAL_HDRS := \
Signature · 1 line
2.45.1
maintainer
#4 lore raw
In reply to John Hubbard
Quoted 30 lines · John Hubbard

Hi,

Here's a few fixes that are part of my effort to get all selftests building cleanly under clang. Plus one that I noticed by inspection.

Changes since v2:

1) Added a sentence to the .PHONY patch, to show that it is removing duplicate code.

2) Added the actual clang warning output to the commit description.

Changes since the first version:

1) Rebased onto Linux 6.10-rc1
2) Added Reviewed-by's.

...and it turns out that all three patches are still required, on -rc1, in order to get a clean clang build.

Enjoy!

thanks,
John Hubbard

John Hubbard (3):
selftests/futex: don't redefine .PHONY targets (all, clean) selftests/futex: don't pass a const char* to asprintf(3) selftests/futex: pass _GNU_SOURCE without a value to the compiler

Quoted 7 lines
  tools/testing/selftests/futex/Makefile                      | 2 --
  tools/testing/selftests/futex/functional/Makefile           | 2 +-
  tools/testing/selftests/futex/functional/futex_requeue_pi.c | 2 +-
  3 files changed, 2 insertions(+), 4 deletions(-)

base-commit: b050496579632f86ee1ef7e7501906db579f3457

Thank you - applied to linux-kselftest fixes branch for next rc.

thanks,
-- Shuah