+2018-01-08 Florian Weimer <fweimer@redhat.com>
+
+ * support/check.h (TEST_COMPARE): Allow sign mismatch at compile
+ time. Pass positive flag instead of negative flag to
+ support_test_compare_failure.
+ (support_test_compare_failure): Change negative parameter to
+ positive.
+ * support/support_test_compare_failure.c (report)
+ (support_test_compare_failure): Likewise.
+ * support/tst-test_compare.c (return_ssize_t, return_int): New.
+ (do_test): Check int/size_t, ssize_t/size_t comparisons.
+
2018-01-08 Szabolcs Nagy <szabolcs.nagy@arm.com>
[BZ #22637]
typedef __typeof__ (+ (right)) __right_type; \
__left_type __left_value = (left); \
__right_type __right_value = (right); \
- /* Prevent use with floating-point and boolean types. */ \
+ int __left_is_positive = __left_value > 0; \
+ int __right_is_positive = __right_value > 0; \
+ /* Prevent use with floating-point types. */ \
support_static_assert ((__left_type) 1.0 == (__left_type) 1.5, \
"left value has floating-point type"); \
support_static_assert ((__right_type) 1.0 == (__right_type) 1.5, \
"left value fits into long long"); \
support_static_assert (sizeof (__right_value) <= sizeof (long long), \
"right value fits into long long"); \
- /* Make sure that integer conversions does not alter the sign. */ \
- enum \
- { \
- __left_is_unsigned = (__left_type) -1 > 0, \
- __right_is_unsigned = (__right_type) -1 > 0, \
- __unsigned_left_converts_to_wider = (__left_is_unsigned \
- && (sizeof (__left_value) \
- < sizeof (__right_value))), \
- __unsigned_right_converts_to_wider = (__right_is_unsigned \
- && (sizeof (__right_value) \
- < sizeof (__left_value))) \
- }; \
- support_static_assert (__left_is_unsigned == __right_is_unsigned \
- || __unsigned_left_converts_to_wider \
- || __unsigned_right_converts_to_wider, \
- "integer conversions may alter sign of operands"); \
/* Compare the value. */ \
- if (__left_value != __right_value) \
+ if (__left_value != __right_value \
+ || __left_is_positive != __right_is_positive) \
/* Pass the sign for printing the correct value. */ \
support_test_compare_failure \
(__FILE__, __LINE__, \
- #left, __left_value, __left_value < 0, sizeof (__left_type), \
- #right, __right_value, __right_value < 0, sizeof (__right_type)); \
+ #left, __left_value, __left_is_positive, sizeof (__left_type), \
+ #right, __right_value, __right_is_positive, sizeof (__right_type)); \
})
-/* Internal implementation of TEST_COMPARE. LEFT_NEGATIVE and
- RIGHT_NEGATIVE are used to store the sign separately, so that both
+/* Internal implementation of TEST_COMPARE. LEFT_POSITIVE and
+ RIGHT_POSITIVE are used to store the sign separately, so that both
unsigned long long and long long arguments fit into LEFT_VALUE and
RIGHT_VALUE, and the function can still print the original value.
LEFT_SIZE and RIGHT_SIZE specify the size of the argument in bytes,
void support_test_compare_failure (const char *file, int line,
const char *left_expr,
long long left_value,
- int left_negative,
+ int left_positive,
int left_size,
const char *right_expr,
long long right_value,
- int right_negative,
+ int right_positive,
int right_size);
#include <support/check.h>
static void
-report (const char *which, const char *expr, long long value, int negative,
+report (const char *which, const char *expr, long long value, int positive,
int size)
{
printf (" %s: ", which);
- if (negative)
- printf ("%lld", value);
- else
+ if (positive)
printf ("%llu", (unsigned long long) value);
+ else
+ printf ("%lld", value);
unsigned long long mask
= (~0ULL) >> (8 * (sizeof (unsigned long long) - size));
printf (" (0x%llx); from: %s\n", (unsigned long long) value & mask, expr);
support_test_compare_failure (const char *file, int line,
const char *left_expr,
long long left_value,
- int left_negative,
+ int left_positive,
int left_size,
const char *right_expr,
long long right_value,
- int right_negative,
+ int right_positive,
int right_size)
{
support_record_failure ();
file, line, left_size * 8, right_size * 8);
else
printf ("%s:%d: numeric comparison failure\n", file, line);
- report (" left", left_expr, left_value, left_negative, left_size);
- report ("right", right_expr, right_value, right_negative, right_size);
+ report (" left", left_expr, left_value, left_positive, left_size);
+ report ("right", right_expr, right_value, right_positive, right_size);
}