public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
From: "Arnd Bergmann" <arnd@arndb.de>
To: "Eric Dumazet" <edumazet@google.com>, "Arnd Bergmann" <arnd@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	"David S . Miller" <davem@davemloft.net>,
	"David Ahern" <dsahern@kernel.org>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Paolo Abeni" <pabeni@redhat.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Bill Wendling" <morbo@google.com>,
	"Justin Stitt" <justinstitt@google.com>,
	"Dmitry Safonov" <0x7f454c46@gmail.com>,
	"Neal Cardwell" <ncardwell@google.com>,
	"mfreemon@cloudflare.com" <mfreemon@cloudflare.com>,
	"Yan Zhai" <yan@cloudflare.com>, Netdev <netdev@vger.kernel.org>,
	llvm@lists.linux.dev
Subject: Re: [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS
Date: Thu, 28 Mar 2024 17:39:36 +0100	[thread overview]
Message-ID: <62cf1c3c-29b7-48cc-9d52-cd47a6c07aa4@app.fastmail.com> (raw)
In-Reply-To: <CANn89i+3FuKc1RsYaciNe3uQMZuJBjSmvC_ueuQ=NaFVzEnyuA@mail.gmail.com>

On Thu, Mar 28, 2024, at 15:38, Eric Dumazet wrote:
> On Thu, Mar 28, 2024 at 3:31 PM Arnd Bergmann <arnd@kernel.org> wrote:
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> arch/x86/include/asm/percpu.h:127:31: note: expanded from macro 'percpu_add_op'
>>                               ((val) == 1 || (val) == -1)) ?            \
>>                                              ~~~~~ ^  ~~
>>
>
> This seems like a bug in the macro or the compiler, because val is not
> a constant ?
>
> __builtin_constant_p(val) should return false ???
>
> +#define percpu_add_op(size, qual, var, val)                            \
> +do {                                                                   \
> +       const int pao_ID__ = (__builtin_constant_p(val) &&              \
> +                             ((val) == 1 || (val) == -1)) ?            \
> +                               (int)(val) : 0;                         \

It looks like gcc does the same thing, with the broader and
still disabled -Wtype-limits, see: https://godbolt.org/z/3EPTGx68n

As far as I can tell, it does not matter that the comparison
against -1 is never actually evaluated, since the warning
is already printed before it simplifies the condition.

This is the only such warning I got from percpu, but
I guess we could also add the cast inside of the macro,
such as

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 44958ebaf626..5923d786e67a 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -181,12 +181,14 @@ do {                                                                      \
  */
 #define percpu_add_op(size, qual, var, val)                            \
 do {                                                                   \
-       const int pao_ID__ = (__builtin_constant_p(val) &&              \
-                             ((val) == 1 || (val) == -1)) ?            \
-                               (int)(val) : 0;                         \
+       __auto_type __val = (val);                                      \
+       const int pao_ID__ = (__builtin_constant_p(__val) &&            \
+                             ((__val) == (typeof(__val))1 ||           \
+                              (__val) == (typeof(__val))-1)) ?         \
+                               (int)(__val) : 0;                       \
        if (0) {                                                        \
                typeof(var) pao_tmp__;                                  \
-               pao_tmp__ = (val);                                      \
+               pao_tmp__ = (__val);                                    \
                (void)pao_tmp__;                                        \
        }                                                               \
        if (pao_ID__ == 1)                                              \
@@ -194,7 +196,7 @@ do {                                                                        \
        else if (pao_ID__ == -1)                                        \
                percpu_unary_op(size, qual, "dec", var);                \
        else                                                            \
-               percpu_to_op(size, qual, "add", var, val);              \
+               percpu_to_op(size, qual, "add", var, __val);            \
 } while (0)
 
 #define percpu_from_op(size, qual, op, _var)                           \

I added a temporary variable there to avoid expanding
the argument too many times.

       Arnd

  reply	other threads:[~2024-03-28 16:39 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-28 14:30 [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare Arnd Bergmann
2024-03-28 14:30 ` [PATCH 1/9] dm integrity: fix out-of-range warning Arnd Bergmann
2024-03-28 18:36   ` Mikulas Patocka
2024-03-28 21:58   ` Justin Stitt
2024-03-28 14:30 ` [PATCH 2/9] libceph: avoid clang " Arnd Bergmann
2024-03-28 22:53   ` Justin Stitt
2024-03-29  0:06   ` Xiubo Li
2024-03-28 14:30 ` [PATCH 3/9] rbd: avoid " Arnd Bergmann
2024-03-28 14:53   ` Alex Elder
2024-03-29  0:05     ` Xiubo Li
2024-03-28 14:30 ` [PATCH 4/9] kcov: avoid clang " Arnd Bergmann
2024-03-28 22:22   ` Justin Stitt
2024-03-28 14:30 ` [PATCH 5/9] ipv4: tcp_output: avoid warning about NET_ADD_STATS Arnd Bergmann
2024-03-28 14:38   ` Eric Dumazet
2024-03-28 16:39     ` Arnd Bergmann [this message]
2024-03-28 14:30 ` [PATCH 6/9] nilfs2: fix out-of-range warning Arnd Bergmann
2024-03-28 15:21   ` Philipp Stanner
2024-03-28 16:12     ` Arnd Bergmann
2024-03-28 22:04   ` Justin Stitt
2024-03-28 22:25     ` Arnd Bergmann
2024-03-29  9:20   ` Ryusuke Konishi
2024-04-01  8:50   ` (subset) " Christian Brauner
2024-03-28 14:30 ` [PATCH 7/9] infiniband: uverbs: avoid out-of-range warnings Arnd Bergmann
2024-03-28 22:12   ` Justin Stitt
2024-04-03 15:45   ` Jason Gunthorpe
2024-04-03 20:16     ` Arnd Bergmann
2024-03-28 14:30 ` [PATCH 8/9] mlx5: stop warning for 64KB pages Arnd Bergmann
2024-03-28 15:37   ` Maxim Mikityanskiy
2024-03-28 22:09   ` Justin Stitt
2024-03-28 22:21     ` Arnd Bergmann
2024-03-28 22:39   ` Tariq Toukan
2024-03-29 20:00 ` [PATCH 0/9] address remaining -Wtautological-constant-out-of-range-compare 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=62cf1c3c-29b7-48cc-9d52-cd47a6c07aa4@app.fastmail.com \
    --to=arnd@arndb.de \
    --cc=0x7f454c46@gmail.com \
    --cc=arnd@kernel.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=justinstitt@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mfreemon@cloudflare.com \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ncardwell@google.com \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=yan@cloudflare.com \
    /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