mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] selftests: harness: don't compare function pointers in is_signed_var()
@ 2026-11-03 23:23 Sasha Levin
  0 siblings, 0 replies; only message in thread
From: Sasha Levin @ 2026-11-03 23:23 UTC (permalink / raw)
  To: Kees Cook, Shuah Khan
  Cc: Andy Lutomirski, Will Drewry, Thomas Weißschuh,
	Nathan Chancellor, linux-kselftest, llvm, linux-kernel

is_signed_var() checks whether -1 converted to the type of its argument
is below 1. When an ASSERT or EXPECT compares function pointers, such as
the result of signal() against SIG_ERR, that is an ordered comparison of
function pointers, and clang warns about it:

  legacy_check.c:41:2: warning: ordered comparison of function pointers ('typeof (__exp)' (aka 'void (*)(int)') and 'typeof (__exp)' (aka 'void (*)(int)')) [-Wordered-compare-function-pointers]

Do the check on uintptr_t for pointers, which __builtin_classify_type()
reports as class 5. Pointers already come out as unsigned, so the
output doesn't change.

Signed-off-by: Sasha Levin <sashal@kernel.org>
---
Found with clang 19, 21 and 22 in the rseq and namespaces tests; gcc
doesn't warn. On failure the harness prints the same values as before
for integers, char, bool, enums, and object and function pointers. This
is next to the lines that the pending 32-bit __EXPECT() fixes change, so
whichever goes in second needs a trivial rebase.

 tools/testing/selftests/kselftest_harness.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 29a19bc870846..54ee275fac8f0 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -760,7 +760,11 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
 	for (; _metadata->trigger; _metadata->trigger = \
 			__bail(_assert, _metadata))
 
-#define is_signed_var(var)	(!!(((__typeof__(var))(-1)) < (__typeof__(var))1))
+#define __signedness_type(var) \
+	__typeof__(__builtin_choose_expr(__builtin_classify_type(var) == 5, \
+					 (uintptr_t)0, (var)))
+#define is_signed_var(var) \
+	(!!(((__signedness_type(var))(-1)) < (__signedness_type(var))1))
 
 #define __EXPECT(_expected, _expected_str, _seen, _seen_str, _t, _assert) do { \
 	/* Avoid multiple evaluation of the cases */ \
-- 
2.53.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-03 23:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-03 23:23 [PATCH] selftests: harness: don't compare function pointers in is_signed_var() Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®