public inbox for bpf@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Yonghong Song <yonghong.song@linux.dev>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com, Martin KaFai Lau <martin.lau@kernel.org>,
	kernel test robot <lkp@intel.com>
Subject: Re: [PATCH bpf-next 1/2] bpf: Fix compilation warning with -Wparentheses
Date: Fri, 28 Jul 2023 12:25:28 +0200	[thread overview]
Message-ID: <ZMOXmM4/pdACHPBq@krava> (raw)
In-Reply-To: <20230728055740.2284534-1-yonghong.song@linux.dev>

On Thu, Jul 27, 2023 at 10:57:40PM -0700, Yonghong Song wrote:
> The kernel test robot reported compilation warnings when -Wparentheses is
> added to KBUILD_CFLAGS with gcc compiler. The following is the error message:
> 
>   .../bpf-next/kernel/bpf/verifier.c: In function ‘coerce_reg_to_size_sx’:
>   .../bpf-next/kernel/bpf/verifier.c:5901:14:
>     error: suggest parentheses around comparison in operand of ‘==’ [-Werror=parentheses]
>     if (s64_max >= 0 == s64_min >= 0) {
>         ~~~~~~~~^~~~
>   .../bpf-next/kernel/bpf/verifier.c: In function ‘coerce_subreg_to_size_sx’:
>   .../bpf-next/kernel/bpf/verifier.c:5965:14:
>     error: suggest parentheses around comparison in operand of ‘==’ [-Werror=parentheses]
>     if (s32_min >= 0 == s32_max >= 0) {
>         ~~~~~~~~^~~~
> 
> To fix the issue, add proper parentheses for the above '>=' condition
> to silence the warning/error.
> 
> I tried a few clang compilers like clang16 and clang18 and they do not emit
> such warnings with -Wparentheses.

I just hit it with gcc and this fixes it for me

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> 
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202307281133.wi0c4SqG-lkp@intel.com/
> Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
> ---
>  kernel/bpf/core.c     | 4 ++--
>  kernel/bpf/verifier.c | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index db0b631908c2..baccdec22f19 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -1877,7 +1877,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
>  		case 1:
>  			AX = abs((s32)DST);
>  			do_div(AX, abs((s32)SRC));
> -			if ((s32)DST < 0 == (s32)SRC < 0)
> +			if (((s32)DST < 0) == ((s32)SRC < 0))
>  				DST = (u32)AX;
>  			else
>  				DST = (u32)-AX;
> @@ -1904,7 +1904,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
>  		case 1:
>  			AX = abs((s32)DST);
>  			do_div(AX, abs((s32)IMM));
> -			if ((s32)DST < 0 == (s32)IMM < 0)
> +			if (((s32)DST < 0) == ((s32)IMM < 0))
>  				DST = (u32)AX;
>  			else
>  				DST = (u32)-AX;
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 0b1ada93582b..e7b1af016841 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -5898,7 +5898,7 @@ static void coerce_reg_to_size_sx(struct bpf_reg_state *reg, int size)
>  	s64_min = min(init_s64_max, init_s64_min);
>  
>  	/* both of s64_max/s64_min positive or negative */
> -	if (s64_max >= 0 == s64_min >= 0) {
> +	if ((s64_max >= 0) == (s64_min >= 0)) {
>  		reg->smin_value = reg->s32_min_value = s64_min;
>  		reg->smax_value = reg->s32_max_value = s64_max;
>  		reg->umin_value = reg->u32_min_value = s64_min;
> @@ -5962,7 +5962,7 @@ static void coerce_subreg_to_size_sx(struct bpf_reg_state *reg, int size)
>  	s32_max = max(init_s32_max, init_s32_min);
>  	s32_min = min(init_s32_max, init_s32_min);
>  
> -	if (s32_min >= 0 == s32_max >= 0) {
> +	if ((s32_min >= 0) == (s32_max >= 0)) {
>  		reg->s32_min_value = s32_min;
>  		reg->s32_max_value = s32_max;
>  		reg->u32_min_value = (u32)s32_min;
> -- 
> 2.34.1
> 
> 

  parent reply	other threads:[~2023-07-28 10:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-28  5:57 [PATCH bpf-next 1/2] bpf: Fix compilation warning with -Wparentheses Yonghong Song
2023-07-28  5:57 ` [PATCH bpf-next 2/2] selftests/bpf: Enable test test_progs-cpuv4 for gcc build kernel Yonghong Song
2023-07-28 10:25 ` Jiri Olsa [this message]
2023-07-28 16:00 ` [PATCH bpf-next 1/2] bpf: Fix compilation warning with -Wparentheses patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZMOXmM4/pdACHPBq@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=lkp@intel.com \
    --cc=martin.lau@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox