From: Nathan Chancellor <nathan@kernel.org>
To: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
Cc: justinstitt@google.com, emma@anholt.net, trix@redhat.com,
intel-gfx@lists.freedesktop.org, ndesaulniers@google.com,
patches@lists.linux.dev, mwen@igalia.com,
dri-devel@lists.freedesktop.org, llvm@lists.linux.dev,
rodrigo.vivi@intel.com
Subject: Re: [Intel-gfx] [PATCH 2/2] drm/i915: Avoid -Wconstant-logical-operand in nsecs_to_jiffies_timeout()
Date: Thu, 20 Jul 2023 08:16:36 -0700 [thread overview]
Message-ID: <20230720151636.GA511202@dev-arch.thelio-3990X> (raw)
In-Reply-To: <1a2aeca6-12f7-6316-c6e2-8474fd17255e@linux.intel.com>
On Thu, Jul 20, 2023 at 09:43:05AM +0100, Tvrtko Ursulin wrote:
>
> On 18/07/2023 22:44, Nathan Chancellor wrote:
> > A proposed update to clang's -Wconstant-logical-operand to warn when the
> > left hand side is a constant shows the following instance in
> > nsecs_to_jiffies_timeout() when NSEC_PER_SEC is not a multiple of HZ,
> > such as CONFIG_HZ=300:
> >
> > drivers/gpu/drm/i915/gem/i915_gem_wait.c:189:24: warning: use of logical '&&' with constant operand [-Wconstant-logical-operand]
> > 189 | if (NSEC_PER_SEC % HZ &&
> > | ~~~~~~~~~~~~~~~~~ ^
> > drivers/gpu/drm/i915/gem/i915_gem_wait.c:189:24: note: use '&' for a bitwise operation
> > 189 | if (NSEC_PER_SEC % HZ &&
> > | ^~
> > | &
> > drivers/gpu/drm/i915/gem/i915_gem_wait.c:189:24: note: remove constant to silence this warning
> > 1 warning generated.
> >
> > Turn this into an explicit comparison against zero to make the
> > expression a boolean to make it clear this should be a logical check,
> > not a bitwise one.
>
> So -Wconstant-logical-operand only triggers when it is a
> constant but not zero constant? Why does that make sense is not
> a kludge to avoid too much noise?
Yes, the warning purposefully does not trigger when the constant is a 1
or 0 (as those are usually indicative of an intentional logical
operation):
https://github.com/llvm/llvm-project/blob/dfdfd306cfaf54fbc43e2d5eb36489dac3eb9976/clang/lib/Sema/SemaExpr.cpp#L13917-L13919
In this case, it is 100, so I kind of understand why this might be
ambiguous to the compiler.
> Personally, it all feels a bit over the top as a warning,
> since code in both cases should optimise away. And we may end
I do not necessarily disagree, as you can see from the differential
review that I linked in the message, but I also understand it is a fine
line to tread when writing compiler warnings between wanting to catch
as many potential problems as possible and having too much noise for
developers to sift through. I think this is erring on the side of
caution.
> up papering over it if it becomes a default.
diagtool tree tells me this warning is already on by default.
> Then again this patch IMO does make the code more readable, so
I think so too.
> I am happy to take this one via our tree. Or either give ack to
> bring it in via drm-misc-next:
>
> Acked-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>
> Let me know which route works best.
Thanks for the feedback! Either route is fine with me but if the v3d
patch is going to go in via drm-misc-next, it seems like it would not be
too much trouble to push this one with it.
Cheers,
Nathan
next prev parent reply other threads:[~2023-07-20 15:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-18 21:44 [Intel-gfx] [PATCH 0/2] Avoid -Wconstant-logical-operand in nsecs_to_jiffies_timeout() Nathan Chancellor
2023-07-18 21:44 ` [Intel-gfx] [PATCH 1/2] drm/v3d: " Nathan Chancellor
2023-07-21 18:36 ` Nick Desaulniers
2023-07-27 14:01 ` Maira Canal
2023-07-27 14:41 ` Nathan Chancellor
2023-07-18 21:44 ` [Intel-gfx] [PATCH 2/2] drm/i915: " Nathan Chancellor
2023-07-20 8:43 ` Tvrtko Ursulin
2023-07-20 15:16 ` Nathan Chancellor [this message]
2023-07-18 23:25 ` [Intel-gfx] ✓ Fi.CI.BAT: success for " Patchwork
2023-07-19 0:45 ` [Intel-gfx] ✓ Fi.CI.IGT: " Patchwork
2023-07-27 16:08 ` [Intel-gfx] [PATCH 0/2] " Maira Canal
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=20230720151636.GA511202@dev-arch.thelio-3990X \
--to=nathan@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=emma@anholt.net \
--cc=intel-gfx@lists.freedesktop.org \
--cc=justinstitt@google.com \
--cc=llvm@lists.linux.dev \
--cc=mwen@igalia.com \
--cc=ndesaulniers@google.com \
--cc=patches@lists.linux.dev \
--cc=rodrigo.vivi@intel.com \
--cc=trix@redhat.com \
--cc=tvrtko.ursulin@linux.intel.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