diff mbox series

[2/2] selftests/lib.mk: silence some clang warnings that gcc already ignores

Message ID 20240529020842.127275-3-jhubbard@nvidia.com (mailing list archive)
State New
Headers show
Series selftests/lib.mk: LLVM=1, CC=clang, and warnings | expand

Commit Message

John Hubbard May 29, 2024, 2:08 a.m. UTC
gcc defaults to silence (off) for the following warnings, but clang
defaults to the opposite. These warnings are not useful for kselftests,
so silence them for the clang builds as well:

    -Wno-address-of-packed-member
    -Wno-gnu-variable-sized-type-not-at-end

This eliminates warnings for the net/ and user_events/ kselftest
subsystems, in these files:

    ./net/af_unix/scm_rights.c
    ./net/timestamping.c
    ./net/ipsec.c
    ./user_events/perf_test.c

Cc: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 tools/testing/selftests/lib.mk | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Shuah Khan May 30, 2024, 2:25 p.m. UTC | #1
On 5/28/24 20:08, John Hubbard wrote:
> gcc defaults to silence (off) for the following warnings, but clang
> defaults to the opposite. These warnings are not useful for kselftests,
> so silence them for the clang builds as well:

Please you add more information on why they aren't useful
for kselftests.

> 
>      -Wno-address-of-packed-member
>      -Wno-gnu-variable-sized-type-not-at-end
> 
> This eliminates warnings for the net/ and user_events/ kselftest
> subsystems, in these files:
> 
>      ./net/af_unix/scm_rights.c
>      ./net/timestamping.c
>      ./net/ipsec.c
>      ./user_events/perf_test.c
> 
> Cc: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> ---
>   tools/testing/selftests/lib.mk | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
> index 2902787b89b2..41e879f3f8a2 100644
> --- a/tools/testing/selftests/lib.mk
> +++ b/tools/testing/selftests/lib.mk
> @@ -50,6 +50,12 @@ else
>   CLANG_FLAGS     += --target=$(notdir $(CROSS_COMPILE:%-=%))
>   endif # CROSS_COMPILE
>   
> +# gcc defaults to silence (off) for the following warnings, but clang defaults
> +# to the opposite. These warnings are not useful for kselftests, so silence them
> +# for the clang builds as well.
> +CFLAGS += -Wno-address-of-packed-member
> +CFLAGS += -Wno-gnu-variable-sized-type-not-at-end
> +
>   CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
>   else
>   CC := $(CROSS_COMPILE)gcc

thanks,
-- Shuah
John Hubbard May 30, 2024, 7:28 p.m. UTC | #2
On 5/30/24 7:25 AM, Shuah Khan wrote:
> On 5/28/24 20:08, John Hubbard wrote:
>> gcc defaults to silence (off) for the following warnings, but clang
>> defaults to the opposite. These warnings are not useful for kselftests,
>> so silence them for the clang builds as well:
> 
> Please you add more information on why they aren't useful
> for kselftests.

Ah OK. My wording is a little misleading. The warnings are not useful
for the *kernel*, as previous decided by the gcc settings when building
the kernel. And it is only only due to including kernel data structures
in the selftests, that we get the warnings on clang.

So it is not something unique to the selftests. There is nothing that
the selftests' code does that triggers these warnings, other than the
act of including the kernel's data structures.

I can post a v2 to update both the comment and the commit description.


thanks,
Shuah Khan May 31, 2024, 2:30 p.m. UTC | #3
On 5/30/24 13:28, John Hubbard wrote:
> On 5/30/24 7:25 AM, Shuah Khan wrote:
>> On 5/28/24 20:08, John Hubbard wrote:
>>> gcc defaults to silence (off) for the following warnings, but clang
>>> defaults to the opposite. These warnings are not useful for kselftests,
>>> so silence them for the clang builds as well:
>>
>> Please you add more information on why they aren't useful
>> for kselftests.
> 
> Ah OK. My wording is a little misleading. The warnings are not useful
> for the *kernel*, as previous decided by the gcc settings when building
> the kernel. And it is only only due to including kernel data structures
> in the selftests, that we get the warnings on clang.
> 
> So it is not something unique to the selftests. There is nothing that
> the selftests' code does that triggers these warnings, other than the
> act of including the kernel's data structures.
> 
> I can post a v2 to update both the comment and the commit description.
> 
  
Yes please.

thanks,
-- Shuah
diff mbox series

Patch

diff --git a/tools/testing/selftests/lib.mk b/tools/testing/selftests/lib.mk
index 2902787b89b2..41e879f3f8a2 100644
--- a/tools/testing/selftests/lib.mk
+++ b/tools/testing/selftests/lib.mk
@@ -50,6 +50,12 @@  else
 CLANG_FLAGS     += --target=$(notdir $(CROSS_COMPILE:%-=%))
 endif # CROSS_COMPILE
 
+# gcc defaults to silence (off) for the following warnings, but clang defaults
+# to the opposite. These warnings are not useful for kselftests, so silence them
+# for the clang builds as well.
+CFLAGS += -Wno-address-of-packed-member
+CFLAGS += -Wno-gnu-variable-sized-type-not-at-end
+
 CC := $(CLANG) $(CLANG_FLAGS) -fintegrated-as
 else
 CC := $(CROSS_COMPILE)gcc