mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
To: Kees Cook <kees@kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>, Shuah Khan <shuah@kernel.org>,
	"Dmitry V. Levin" <ldv@strace.io>
Cc: "Christophe Leroy (CS GROUP)" <chleroy@kernel.org>,
	linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] selftests: harness: fix again 32-bit build warnings in __EXPECT()
Date: Tue, 13 Jan 2026 11:08:14 +0100	[thread overview]
Message-ID: <948937bfe461cf0fb6ade2623e51f673f845fa51.1768298756.git.chleroy@kernel.org> (raw)

/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/testing/selftests/kselftest_harness.h:770:49: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  770 |                         uintmax_t __exp_print = (uintmax_t)__exp; \
      |                                                 ^
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/testing/selftests/kselftest_harness.h:530:9: note: in expansion of macro '__EXPECT'
  530 |         __EXPECT(expected, #expected, seen, #seen, !=, 1)
      |         ^~~~~~~~
test-pcmtest-driver.c:137:9: note: in expansion of macro 'ASSERT_NE'
  137 |         ASSERT_NE(card_name, NULL);
      |         ^~~~~~~~~
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/testing/selftests/kselftest_harness.h:771:50: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
  771 |                         uintmax_t __seen_print = (uintmax_t)__seen; \
      |                                                  ^
/home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/testing/selftests/kselftest_harness.h:530:9: note: in expansion of macro '__EXPECT'
  530 |         __EXPECT(expected, #expected, seen, #seen, !=, 1)
      |         ^~~~~~~~
test-pcmtest-driver.c:137:9: note: in expansion of macro 'ASSERT_NE'
  137 |         ASSERT_NE(card_name, NULL);
      |         ^~~~~~~~~
...

Those warnings were fixed by commit b5bb6d3068ea ("selftests/seccomp:
fix 32-bit build warnings") but then reintroduced by
commit 02bc220dc6dc ("selftests: harness: fix printing of mismatch
values in __EXPECT()")

Fix them for good this time, without re-introducing the printing
mismatch.

Fixes: 02bc220dc6dc ("selftests: harness: fix printing of mismatch values in __EXPECT()")
Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
---
 tools/testing/selftests/kselftest_harness.h | 37 ++++++++++++---------
 1 file changed, 21 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/kselftest_harness.h b/tools/testing/selftests/kselftest_harness.h
index 16a119a4656c7..80a81f96fd5bf 100644
--- a/tools/testing/selftests/kselftest_harness.h
+++ b/tools/testing/selftests/kselftest_harness.h
@@ -759,6 +759,11 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
 
 #define is_signed_var(var)	(!!(((__typeof__(var))(-1)) < (__typeof__(var))1))
 
+#define __ulong_type(x) \
+	__typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
+#define __long_type(x) \
+	__typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0L), 0LL, 0L))
+
 #define __EXPECT(_expected, _expected_str, _seen, _seen_str, _t, _assert) do { \
 	/* Avoid multiple evaluation of the cases */ \
 	__typeof__(_expected) __exp = (_expected); \
@@ -767,35 +772,35 @@ static inline void __kselftest_memset_safe(void *s, int c, size_t n)
 		/* Report with actual signedness to avoid weird output. */ \
 		switch (is_signed_var(__exp) * 2 + is_signed_var(__seen)) { \
 		case 0: { \
-			uintmax_t __exp_print = (uintmax_t)__exp; \
-			uintmax_t __seen_print = (uintmax_t)__seen; \
+			__ulong_type(__exp) __exp_print = (__ulong_type(__exp))__exp; \
+			__ulong_type(__seen) __seen_print = (__ulong_type(__seen))__seen; \
 			__TH_LOG("Expected %s (%ju) %s %s (%ju)", \
-				 _expected_str, __exp_print, #_t, \
-				 _seen_str, __seen_print); \
+				 _expected_str, (uintmax_t)__exp_print, #_t, \
+				 _seen_str, (uintmax_t)__seen_print); \
 			break; \
 			} \
 		case 1: { \
-			uintmax_t __exp_print = (uintmax_t)__exp; \
-			intmax_t  __seen_print = (intmax_t)__seen; \
+			__ulong_type(__exp) __exp_print = (__ulong_type(__exp))__exp; \
+			__long_type(__seen) __seen_print = (__long_type(__seen))__seen; \
 			__TH_LOG("Expected %s (%ju) %s %s (%jd)", \
-				 _expected_str, __exp_print, #_t, \
-				 _seen_str, __seen_print); \
+				 _expected_str, (uintmax_t)__exp_print, #_t, \
+				 _seen_str, (intmax_t)__seen_print); \
 			break; \
 			} \
 		case 2: { \
-			intmax_t  __exp_print = (intmax_t)__exp; \
-			uintmax_t __seen_print = (uintmax_t)__seen; \
+			__long_type(__exp) __exp_print = (__long_type(__exp))__exp; \
+			__ulong_type(__seen) __seen_print = (__ulong_type(__seen))__seen; \
 			__TH_LOG("Expected %s (%jd) %s %s (%ju)", \
-				 _expected_str, __exp_print, #_t, \
-				 _seen_str, __seen_print); \
+				 _expected_str, (intmax_t)__exp_print, #_t, \
+				 _seen_str, (uintmax_t)__seen_print); \
 			break; \
 			} \
 		case 3: { \
-			intmax_t  __exp_print = (intmax_t)__exp; \
-			intmax_t  __seen_print = (intmax_t)__seen; \
+			__long_type(__exp) __exp_print = (__long_type(__exp))__exp; \
+			__long_type(__seen) __seen_print = (__long_type(__seen))__seen; \
 			__TH_LOG("Expected %s (%jd) %s %s (%jd)", \
-				 _expected_str, __exp_print, #_t, \
-				 _seen_str, __seen_print); \
+				 _expected_str, (intmax_t)__exp_print, #_t, \
+				 _seen_str, (intmax_t)__seen_print); \
 			break; \
 			} \
 		} \
-- 
2.49.0


                 reply	other threads:[~2026-01-13 10:10 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=948937bfe461cf0fb6ade2623e51f673f845fa51.1768298756.git.chleroy@kernel.org \
    --to=chleroy@kernel.org \
    --cc=kees@kernel.org \
    --cc=ldv@strace.io \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=shuah@kernel.org \
    --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®