selftests: harness: don't compare function pointers in is_signed_var()
Subsystems (2)
PATCH 1/1 selftests: harness: don't compare function pointers in is_signed_var()
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.
---
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(-)
tools/testing/selftests/kselftest_harness.h +5 -1
@@ -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 */ \
Signature · 1 line
2.53.0