This patch just adds some basic self tests for some of the new relation
operations.
Bootstraps on x86_64-pc-linux-gnu with no regressions. Pushed.
Andrew
>From ca1f9f22854049d6f9cab5b4bfbc46edbcb5c990 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacl...@redhat.com>
Date: Thu, 17 Jun 2021 13:40:05 -0400
Subject: [PATCH 7/7] Add relational self-tests.
* range-op.cc (range_relational_tests): New.
(range_op_tests): Call range_relational_tests.
---
gcc/range-op.cc | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/gcc/range-op.cc b/gcc/range-op.cc
index 92b314df9dd..1692a096e20 100644
--- a/gcc/range-op.cc
+++ b/gcc/range-op.cc
@@ -4244,6 +4244,30 @@ range_op_bitwise_and_tests ()
ASSERT_FALSE (res.contains_p (INT (0)));
}
+static void
+range_relational_tests ()
+{
+ int_range<2> lhs (unsigned_char_type_node);
+ int_range<2> op1 (UCHAR (8), UCHAR (10));
+ int_range<2> op2 (UCHAR (20), UCHAR (20));
+
+ // Never wrapping additions mean LHS > OP1.
+ tree_code code = op_plus.lhs_op1_relation (lhs, op1, op2);
+ ASSERT_TRUE (code == GT_EXPR);
+
+ // Most wrapping additions mean nothing...
+ op1 = int_range<2> (UCHAR (8), UCHAR (10));
+ op2 = int_range<2> (UCHAR (0), UCHAR (255));
+ code = op_plus.lhs_op1_relation (lhs, op1, op2);
+ ASSERT_TRUE (code == VREL_NONE);
+
+ // However, always wrapping additions mean LHS < OP1.
+ op1 = int_range<2> (UCHAR (1), UCHAR (255));
+ op2 = int_range<2> (UCHAR (255), UCHAR (255));
+ code = op_plus.lhs_op1_relation (lhs, op1, op2);
+ ASSERT_TRUE (code == LT_EXPR);
+}
+
void
range_op_tests ()
{
@@ -4251,6 +4275,7 @@ range_op_tests ()
range_op_lshift_tests ();
range_op_bitwise_and_tests ();
range_op_cast_tests ();
+ range_relational_tests ();
}
} // namespace selftest
--
2.17.2