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

Philipp Klocke philipp97kl at gmail.com
Mon Aug 27 09:21:26 UTC 2018


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



More information about the LLVMLinux mailing list