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

Nick Desaulniers ndesaulniers at google.com
Mon Aug 27 17:18:09 UTC 2018


Please file a bug.  There's more issues with clang in this regard:
https://bugs.llvm.org/show_bug.cgi?id=38571 (there should be more
warnings in this code).  IMO, we should fix the code (if under all
configs the expression contains constants), not disable the warning.
On Mon, Aug 27, 2018 at 4:58 AM Philipp K <philipp97kl at gmail.com> 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.
>
> 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



-- 
Thanks,
~Nick Desaulniers


More information about the LLVMLinux mailing list