Re: [PATCH v2] tracing: Make is_signed_type() compatible with sparse

From: Bart Van Assche

Date: Tue Sep 01 2026 - 14:52:12 EST


On 9/1/26 1:20 AM, David Laight wrote:
I suspect you need to change the TRACE_EVENT() calls to remove the
__bitwise marker.

How to remove the __bitwise marker? Removing the __bitwise marker is not
supported by sparse, isn't it?

How about the changes shown below (should be split into two patches)?

diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index cb2f6050bdf7..54c99a25caa5 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -326,7 +326,14 @@ 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) _Generic(((TYPEOF_UNQUAL(type))0), \
+ signed char: true, \
+ signed short: true, \
+ signed int: true, \
+ signed long: true, \
+ signed long long: true, \
+ char: ((char)-1 < (char)1), \
+ default: false)
#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..b72da7f6084f 100644
--- a/lib/tests/is_signed_type_kunit.c
+++ b/lib/tests/is_signed_type_kunit.c
@@ -22,6 +22,8 @@ static void is_signed_type_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, is_signed_type(signed char), true);
KUNIT_EXPECT_EQ(test, is_signed_type(unsigned char), false);
KUNIT_EXPECT_EQ(test, is_signed_type(char), false);
+ KUNIT_EXPECT_EQ(test, is_signed_type(short), true);
+ KUNIT_EXPECT_EQ(test, is_signed_type(unsigned short), false);
KUNIT_EXPECT_EQ(test, is_signed_type(int), true);
KUNIT_EXPECT_EQ(test, is_signed_type(unsigned int), false);
KUNIT_EXPECT_EQ(test, is_signed_type(long), true);
@@ -32,6 +34,13 @@ static void is_signed_type_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, is_signed_type(enum signed_enum), true);
KUNIT_EXPECT_EQ(test, is_signed_type(void *), false);
KUNIT_EXPECT_EQ(test, is_signed_type(const char *), false);
+ KUNIT_EXPECT_EQ(test, is_signed_type(int (*)(void)), false);
+
+ KUNIT_EXPECT_EQ(test, is_signed_type(const int), true);
+ KUNIT_EXPECT_EQ(test, is_signed_type(const unsigned int), false);
+
+ KUNIT_EXPECT_EQ(test, is_signed_type(volatile int), true);
+ KUNIT_EXPECT_EQ(test, is_signed_type(volatile unsigned int), false);
}

static struct kunit_case is_signed_type_test_cases[] = {

Thanks,

Bart.