From: David Laight <david.laight.linux@gmail.com>
To: Ian Rogers <irogers@google.com>
Cc: Yury Norov <yury.norov@gmail.com>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Arnd Bergmann <arnd@arndb.de>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <nick.desaulniers+lkml@gmail.com>,
Bill Wendling <morbo@google.com>,
Justin Stitt <justinstitt@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
Jakub Kicinski <kuba@kernel.org>,
Jacob Keller <jacob.e.keller@intel.com>,
linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, Leo Yan <leo.yan@arm.com>
Subject: Re: [PATCH v2 4/5] math64: Silence a clang -Wshorten-64-to-32 warning
Date: Fri, 2 May 2025 13:17:17 +0100 [thread overview]
Message-ID: <20250502131717.69af6fbe@pumpkin> (raw)
In-Reply-To: <CAP-5=fVjAR0g=wN8sWetHoNWdoDVGNoKb8d8UdwxF_te=wmMLA@mail.gmail.com>
On Thu, 1 May 2025 14:11:59 -0700
Ian Rogers <irogers@google.com> wrote:
....
> Sorry I don't understand what you're saying. Java certainly has bugs
> in this area which is why I've written checkers like:
> https://errorprone.info/bugpattern/BadComparable
> For code similar to:
> ```
> s32 compare(s64 a, s64 b) { return (s32)(a - b); }
> ```
> where the truncation is going to throw away the sign of the subtract
> and is almost certainly a bug. This matches the bugs that are fixed in
> this patch series for the perf code, in particular an issue on ARM
> that Leo Yan originally provided the fix for:
> https://lore.kernel.org/lkml/20250331172759.115604-1-leo.yan@arm.com/
That code is wrong with or without the (s32) cast.
And the explicit cast will hide the compiler warning.
If you want the compiler to find bugs you need to reduce the number
of casts to an absolute minimum and disable/fix the compiler warning
for false positives.
These type based (rather than value domain) warnings are all a PITA.
Another example is the 'signed v unsigned compare' which bleats for:
int rval = read(... sizeof (foo));
if (rval < 0)
return -1;
if (rval != sizeof (foo))
// truncated
Whereas a statically_true(rval >= 0) test will pass.
David
next prev parent reply other threads:[~2025-05-02 12:17 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-30 17:15 [PATCH v2 0/5] Silence some clang -Wshorten-64-to-32 warnings Ian Rogers
2025-04-30 17:15 ` [PATCH v2 1/5] bitfield: Silence a clang -Wshorten-64-to-32 warning Ian Rogers
2025-05-03 10:33 ` David Laight
2025-05-07 8:38 ` kernel test robot
2025-04-30 17:15 ` [PATCH v2 2/5] bitmap: " Ian Rogers
2025-05-02 16:03 ` Yury Norov
2025-05-02 16:43 ` Ian Rogers
2025-05-02 16:55 ` Yury Norov
2025-05-02 17:13 ` Ian Rogers
2025-04-30 17:15 ` [PATCH v2 3/5] bitops: " Ian Rogers
2025-04-30 17:15 ` [PATCH v2 4/5] math64: " Ian Rogers
2025-05-01 20:07 ` David Laight
2025-05-01 20:15 ` Ian Rogers
2025-05-01 20:26 ` David Laight
2025-05-01 21:11 ` Ian Rogers
2025-05-02 12:17 ` David Laight [this message]
2025-04-30 17:15 ` [PATCH v2 5/5] hash.h: " Ian Rogers
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=20250502131717.69af6fbe@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=adrian.hunter@intel.com \
--cc=arnd@arndb.de \
--cc=irogers@google.com \
--cc=jacob.e.keller@intel.com \
--cc=justinstitt@google.com \
--cc=kuba@kernel.org \
--cc=leo.yan@arm.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=llvm@lists.linux.dev \
--cc=morbo@google.com \
--cc=nathan@kernel.org \
--cc=nick.desaulniers+lkml@gmail.com \
--cc=tglx@linutronix.de \
--cc=yury.norov@gmail.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