From: Sasha Levin <sashal@kernel.org>
To: Kees Cook <kees@kernel.org>, Shuah Khan <shuah@kernel.org>
Cc: "Andy Lutomirski" <luto@amacapital.net>,
"Will Drewry" <wad@chromium.org>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"Nathan Chancellor" <nathan@kernel.org>,
linux-kselftest@vger.kernel.org, llvm@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: [PATCH] selftests: harness: don't compare function pointers in is_signed_var()
Date: Tue, 3 Nov 2026 18:23:05 -0500 [thread overview]
Message-ID: <20261103232307.1924618-1-sashal@kernel.org> (raw)
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
reply other threads:[~2026-11-03 23:23 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20261103232307.1924618-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=luto@amacapital.net \
--cc=nathan@kernel.org \
--cc=shuah@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
--cc=wad@chromium.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 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®