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

Sedat Dilek sedat.dilek at gmail.com
Mon Aug 27 09:32:45 UTC 2018


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?

As an information: LLVM/Clang issues are currently collected in [1].
Ask Nick for participation if you are interested.

Thanks.

Regards,
- Sedat -

[1] https://github.com/ClangBuiltLinux/linux/issues


More information about the LLVMLinux mailing list