[llvmlinux] [PATCH] sched/fair: disable clang -Wconstant-logical-operand

Lukas Bulwahn lukas.bulwahn at gmail.com
Mon Aug 27 19:51:31 UTC 2018



On Mon, 27 Aug 2018, Philipp K wrote:

> Am Mo., 27. Aug. 2018 um 11:32 Uhr schrieb Sedat Dilek <sedat.dilek at gmail.com>:
>       On Mon, Aug 27, 2018 at 11:21 AM, Philipp Klocke <philipp97kl at gmail.com> wrote:
>       > When compiling the kernel with clang, the following warning is issued:
>       >
>       > kernel/sched/fair.c:3927:14: warning: use of logical '&&' with constant operand
>       [-Wconstant-logical-operand]
>       >         if (initial && sched_feat(START_DEBIT))
>       >                     ^  ~~~~~~~~~~~~~~~~~~~~~~~
>       > kernel/sched/fair.c:3927:14: note: use '&' for a bitwise operation
>       >         if (initial && sched_feat(START_DEBIT))
>       >                     ^~
>       >                     &
>       > kernel/sched/fair.c:3927:14: note: remove constant to silence this warning
>       >         if (initial && sched_feat(START_DEBIT))
>       >                    ~^~~~~~~~~~~~~~~~~~~~~~~~~~
>       >
>       > It's obviously a false positive and a 'fix' would make the code less
>       > readable. Peter Zijlstra, asked if we "can't just disable that stupid
>       > warning" and "just fix clang to not be stupid." which is what we do in
>       > this patch.
>       >
>       > In general and in the rest of the kernel sources, we still consider the
>       > warning to be useful, looking at the history of mistakes where || or &&
>       > were used instead of | or &.
>       >
>       > Signed-off-by: Philipp Klocke <philipp97kl at gmail.com>
>       > ---
>       >  kernel/sched/Makefile | 3 +++
>       >  1 file changed, 3 insertions(+)
>       >
>       > diff --git a/kernel/sched/Makefile b/kernel/sched/Makefile
>       > index 7fe183404c38..9f5096847e39 100644
>       > --- a/kernel/sched/Makefile
>       > +++ b/kernel/sched/Makefile
>       > @@ -16,6 +16,9 @@ ifneq ($(CONFIG_SCHED_OMIT_FRAME_POINTER),y)
>       >  CFLAGS_core.o := $(PROFILING) -fno-omit-frame-pointer
>       >  endif
>       >
>       > +# the constant-logical-operand warning is useless in this file.
>       > +CFLAGS_fair.o := $(call cc-disable-warning, constant-logical-operand)
>       > +
>       >  obj-y += core.o loadavg.o clock.o cputime.o
>       >  obj-y += idle.o fair.o rt.o deadline.o
>       >  obj-y += wait.o wait_bit.o swait.o completion.o
>       > --
>       > 2.18.0
>       >
> 
>       [ CC Nick ]
> 
>       Hi Philipp,
> 
>       can you be more precise on the versions of Linux kernel version and
>       llvm-toolchain where you have seen this?
> 
> Hi Sedat,
> 
> I am using clang version 5.0.1-2. The kernel version I tested was 4.16-rc5, which was current when I first
> observed this.
> @Lukas did test it on the current kernel iirc.
> 

I can confirm that the warning still occurs on v4.19-rc1 and the patch 
makes the compiler not further warn about it.

Getting clang compile defconfig needs a hacky patch; I use that for 
running clang-based analysis tools, but would not recommend to boot that 
kernel with those hacks, though.

Lukas

> The code that clang warns about was introduced in 765cc3a4b224e22bf524fabe40284a524f37cdd0.
>  
>       As an information: LLVM/Clang issues are currently collected in [1].
>       Ask Nick for participation if you are interested.
> 
>  
> Thank you for the hint, I haven't seen that page before!
>  
> Philipp
> 
>       [1] https://github.com/ClangBuiltLinux/linux/issues
> 
> 
> 


More information about the LLVMLinux mailing list