From 7bca69cd4af02c6d497c12d596f1545b72ffb4d4 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 18 Jun 2020 06:49:48 -0400
Subject: [PATCH 234/293] FIXME: make test_constant_comparisons not need
 -fanalyzer-transitivity

---
 gcc/analyzer/constraint-manager2.cc           | 27 +++++++++++--------
 .../gcc.dg/analyzer/conditionals-notrans.c    | 12 +++------
 2 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/gcc/analyzer/constraint-manager2.cc b/gcc/analyzer/constraint-manager2.cc
index 3ad56fc277c..15e47964bb7 100644
--- a/gcc/analyzer/constraint-manager2.cc
+++ b/gcc/analyzer/constraint-manager2.cc
@@ -183,12 +183,10 @@ tristate
 range2::eval_condition (enum tree_code op,
 			tree rhs_const) const
 {
-#if 0
   range2 copy (*this);
   tree single_element;
   if (copy.constrained_to_single_element (&single_element))
     return compare_constants (single_element, op, rhs_const);
-#endif
 
   switch (op)
     {
@@ -1230,14 +1228,14 @@ constraint_manager2::get_ec_bounds (equiv_class2_id ec_id) const
 
 	      case CONSTRAINT2_LT:
 		/* We have "OTHER_CST < EC_ID"
-		   i.e. "EC_ID >= OTHER_CST".  */
-		result.m_lower_bound = bound2 (other_cst, true);
+		   i.e. "EC_ID > OTHER_CST".  */
+		result.m_lower_bound = bound2 (other_cst, false);
 		break;
 
 	      case CONSTRAINT2_LE:
 		/* We have "OTHER_CST <= EC_ID"
-		   i.e. "EC_ID > OTHER_CST".  */
-		result.m_lower_bound = bound2 (other_cst, false);
+		   i.e. "EC_ID >= OTHER_CST".  */
+		result.m_lower_bound = bound2 (other_cst, true);
 		break;
 	      }
 	}
@@ -1288,13 +1286,22 @@ constraint_manager2::eval_condition (const svalue2 *lhs,
   get_equiv_class2_by_svalue2 (lhs, &lhs_ec);
   get_equiv_class2_by_svalue2 (rhs, &rhs_ec);
   if (!lhs_ec.null_p () && !rhs_ec.null_p ())
-    return eval_condition (lhs_ec, op, rhs_ec);
+    {
+      tristate result_for_ecs
+	= eval_condition (lhs_ec, op, rhs_ec);
+      if (result_for_ecs.is_known ())
+	return result_for_ecs;
+    }
 
   /* If at least one is not in an EC, we have no constraints
      comparing LHS and RHS yet.
-     They might still be comparable if one (or both) is a constant.  */
+     They might still be comparable if one (or both) is a constant.
+
+     Alternatively, we can also get here if we had ECs but they weren't
+     comparable.  Again, constant comparisons might give an answer.  */
   tree lhs_const = lhs->maybe_get_constant ();
   tree rhs_const = rhs->maybe_get_constant ();
+  // TODO: enable this:
 #if 0
   if (lhs_const && rhs_const)
     {
@@ -1307,13 +1314,11 @@ constraint_manager2::eval_condition (const svalue2 *lhs,
 
   if (!lhs_ec.null_p ())
     {
-      gcc_assert (rhs_ec.null_p ());
       if (rhs_const)
 	return eval_condition (lhs_ec, op, rhs_const);
     }
   if (!rhs_ec.null_p ())
     {
-      gcc_assert (lhs_ec.null_p ());
       if (lhs_const)
 	{
 	  enum tree_code swapped_op = swap_tree_comparison (op);
@@ -2563,8 +2568,8 @@ run_constraint_manager2_tests (bool transitivity)
     {
       /* These selftests assume transitivity.  */
       test_transitivity ();
-      test_constant_comparisons ();
     }
+  test_constant_comparisons ();
   test_constraint_impl ();
   test_equality ();
   test_many_constants ();
diff --git a/gcc/testsuite/gcc.dg/analyzer/conditionals-notrans.c b/gcc/testsuite/gcc.dg/analyzer/conditionals-notrans.c
index baee0b684b7..b1ac541920f 100644
--- a/gcc/testsuite/gcc.dg/analyzer/conditionals-notrans.c
+++ b/gcc/testsuite/gcc.dg/analyzer/conditionals-notrans.c
@@ -94,8 +94,7 @@ void test_range_int_gt_lt (int i)
 {
   if (i > 3)
     if (i < 5)
-      __analyzer_eval (i == 4); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
-      /* { dg-bogus "UNKNOWN" "status quo" { xfail *-*-* } .-1 } */
+      __analyzer_eval (i == 4); /* { dg-warning "TRUE" } */
 }
 
 void test_range_float_gt_lt (float f)
@@ -109,8 +108,7 @@ void test_range_int_ge_lt (int i)
 {
   if (i >= 4)
     if (i < 5)
-      __analyzer_eval (i == 4); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
-      /* { dg-bogus "UNKNOWN" "status quo" { xfail *-*-* } .-1 } */
+      __analyzer_eval (i == 4); /* { dg-warning "TRUE" } */
 }
 
 void test_range_float_ge_lt (float f)
@@ -124,8 +122,7 @@ void test_range_int_gt_le (int i)
 {
   if (i > 3)
     if (i <= 4)
-      __analyzer_eval (i == 4); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
-      /* { dg-bogus "UNKNOWN" "status quo" { xfail *-*-* } .-1 } */
+      __analyzer_eval (i == 4); /* { dg-warning "TRUE" } */
 }
 
 void test_range_float_gt_le (float f)
@@ -139,8 +136,7 @@ void test_range_int_ge_le (int i)
 {
   if (i >= 4)
     if (i <= 4)
-      __analyzer_eval (i == 4); /* { dg-warning "TRUE" "desired" { xfail *-*-* } } */
-      /* { dg-bogus "UNKNOWN" "status quo" { xfail *-*-* } .-1 } */
+      __analyzer_eval (i == 4); /* { dg-warning "TRUE" } */
 }
 
 void test_range_float_ge_le (float f)
-- 
2.26.2

