All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
	linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH] compiler.h: Support 64-bit bitwise types in is_signed_type()
Date: Tue, 17 Nov 2026 08:06:21 +0000	[thread overview]
Message-ID: <20261117080621.7ca022dd@pumpkin> (raw)
In-Reply-To: <4002a78c6bf1fa4fc96d089bd6a704bf77e2e060.1794867767.git.bvanassche@acm.org>

On Mon, 16 Nov 2026 14:26:25 -0800
Bart Van Assche <bvanassche@acm.org> wrote:

> Replace -1 with -1LL in the definition of is_signed_type(type) to
> prevent sparse from emitting "cast to restricted __le64" and
> "restricted __le64 degrades to integer" warnings when evaluating
> is_signed_type() on 64-bit __bitwise types such as __le64 (for example,
> in tracepoint __field() macros in net/mac80211/trace.h).

Don't the trace definitions need fixing?
The trace code prints the numeric value so you really want a host
ordered value in the trace record.

An alternative view is that even asking the question 'is_signed_type'
of a bitwise variable makes no sense.

David

> 
> Use a 64-bit all-ones constant (-1LL) rather than a 32-bit int (-1)
> because sparse only permits casting a non-zero integer constant to a
> __bitwise type and ordering it with '<' when the constant has all bits
> set across the full bit width of the target type. Ensure that the
> constant before the cast has 64 bits set so that sparse's
> restricted_value() and can_order() checks succeed for 64-bit __bitwise
> types on both 32-bit and 64-bit architectures.
> 
> Add a KUnit test case for is_signed_type(__le64) in
> lib/tests/is_signed_type_kunit.c to exercise 64-bit __bitwise types.
> 
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  include/linux/compiler.h         | 2 +-
>  lib/tests/is_signed_type_kunit.c | 5 +++++
>  2 files changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/include/linux/compiler.h b/include/linux/compiler.h
> index cb2f6050bdf7..2f133a7c3885 100644
> --- a/include/linux/compiler.h
> +++ b/include/linux/compiler.h
> @@ -326,7 +326,7 @@ static inline void *offset_to_ptr(const int *off)
>   * Whether 'type' is a signed type or an unsigned type. Supports scalar types,
>   * bool and also pointer types.
>   */
> -#define is_signed_type(type) (((type)(-1)) < (__force type)1)
> +#define is_signed_type(type) (((type)(-1LL)) < (__force type)1)
>  #define is_unsigned_type(type) (!is_signed_type(type))
>  
>  /*
> diff --git a/lib/tests/is_signed_type_kunit.c b/lib/tests/is_signed_type_kunit.c
> index 88adbe813f3a..b9c8f7da45e9 100644
> --- a/lib/tests/is_signed_type_kunit.c
> +++ b/lib/tests/is_signed_type_kunit.c
> @@ -18,6 +18,8 @@ enum signed_enum {
>  
>  static void is_signed_type_test(struct kunit *test)
>  {
> +	typedef __bitwise long long bitwise_long_long;
> +
>  	KUNIT_EXPECT_EQ(test, is_signed_type(bool), false);
>  	KUNIT_EXPECT_EQ(test, is_signed_type(signed char), true);
>  	KUNIT_EXPECT_EQ(test, is_signed_type(unsigned char), false);
> @@ -27,7 +29,10 @@ static void is_signed_type_test(struct kunit *test)
>  	KUNIT_EXPECT_EQ(test, is_signed_type(long), true);
>  	KUNIT_EXPECT_EQ(test, is_signed_type(unsigned long), false);
>  	KUNIT_EXPECT_EQ(test, is_signed_type(long long), true);
> +	KUNIT_EXPECT_EQ(test, is_signed_type(bitwise_long_long), true);
>  	KUNIT_EXPECT_EQ(test, is_signed_type(unsigned long long), false);
> +	KUNIT_EXPECT_EQ(test, is_signed_type(__be64), false);
> +	KUNIT_EXPECT_EQ(test, is_signed_type(__le64), false);
>  	KUNIT_EXPECT_EQ(test, is_signed_type(enum unsigned_enum), false);
>  	KUNIT_EXPECT_EQ(test, is_signed_type(enum signed_enum), true);
>  	KUNIT_EXPECT_EQ(test, is_signed_type(void *), false);


  reply	other threads:[~2026-11-17  8:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:26 [PATCH] compiler.h: Support 64-bit bitwise types in is_signed_type() Bart Van Assche
2026-11-17  8:06 ` David Laight [this message]
2026-11-17 16:32   ` Bart Van Assche

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=20261117080621.7ca022dd@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=bvanassche@acm.org \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=torvalds@linux-foundation.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.