From: Nathan Chancellor <nathan@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: pmladek@suse.com, rostedt@goodmis.org, senozhatsky@chromium.org,
linux@rasmusvillemoes.dk, ndesaulniers@google.com,
trix@redhat.com, linux-kernel@vger.kernel.org,
llvm@lists.linux.dev, patches@lists.linux.dev
Subject: Re: [PATCH] lib: test_scanf: Add explicit type cast to result initialization in test_number_prefix()
Date: Fri, 4 Aug 2023 07:48:59 -0700 [thread overview]
Message-ID: <20230804144859.GA3027708@dev-arch.thelio-3990X> (raw)
In-Reply-To: <ZMx9nDQVaoRwN5oK@smile.fi.intel.com>
On Fri, Aug 04, 2023 at 07:25:00AM +0300, Andy Shevchenko wrote:
> On Thu, Aug 03, 2023 at 11:14:42AM -0700, Nathan Chancellor wrote:
> > A recent change in clang allows it to consider more expressions as
> > compile time constants, which causes it to point out an implicit
> > conversion in the scanf tests:
> >
> > lib/test_scanf.c:661:2: warning: implicit conversion from 'int' to 'unsigned char' changes value from -168 to 88 [-Wconstant-conversion]
> > 661 | test_number_prefix(unsigned char, "0xA7", "%2hhx%hhx", 0, 0xa7, 2, check_uchar);
> > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > lib/test_scanf.c:609:29: note: expanded from macro 'test_number_prefix'
> > 609 | T result[2] = {~expect[0], ~expect[1]}; \
> > | ~ ^~~~~~~~~~
> > 1 warning generated.
> >
> > The result of the bitwise negation is the type of the operand after
> > going through the integer promotion rules, so this truncation is
> > expected but harmless, as the initial values in the result array get
> > overwritten by _test() anyways. Add an explicit cast to the expected
> > type in test_number_prefix() to silence the warning. There is no
> > functional change, as all the tests still pass with GCC 13.1.0 and clang
> > 18.0.0.
>
> > do { \
> > const T expect[2] = { expect0, expect1 }; \
> > - T result[2] = {~expect[0], ~expect[1]}; \
> > + T result[2] = {(T)~expect[0], (T)~expect[1]}; \
>
> Can we add spaces as above, while at it?
>
> T result[2] = { (T)~expect[0], (T)~expect[1] }; \
Sure. I can send a v2 on Monday to give folks a chance to chime in with
other comments.
> > _test(fn, &expect, str, scan_fmt, n_args, &result[0], &result[1]); \
> > } while (0)
>
> --
> With Best Regards,
> Andy Shevchenko
>
>
prev parent reply other threads:[~2023-08-04 14:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 18:14 [PATCH] lib: test_scanf: Add explicit type cast to result initialization in test_number_prefix() Nathan Chancellor
2023-08-04 4:25 ` Andy Shevchenko
2023-08-04 14:48 ` Nathan Chancellor [this message]
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=20230804144859.GA3027708@dev-arch.thelio-3990X \
--to=nathan@kernel.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=llvm@lists.linux.dev \
--cc=ndesaulniers@google.com \
--cc=patches@lists.linux.dev \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
--cc=senozhatsky@chromium.org \
--cc=trix@redhat.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