From 5f58cfcff378b2ebacedcea40f6ea6f142cb205d Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Mon, 8 Jul 2019 16:49:49 -0400
Subject: [PATCH 67/85] FIXME: add more selftest coverage to region_model
 merging

---
 gcc/analyzer/region-model.cc | 71 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 59 insertions(+), 12 deletions(-)

diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index 73943b1..fbe97bd 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -4504,12 +4504,14 @@ test_purging ()
 #endif
 
 /* Assert that if we have two region_model instances
-   with values VAL_A and VAL_B for GLOBAL that they are
+   with values VAL_A and VAL_B for EXPR that they are
    mergable.  Write the merged model to *OUT_MERGED_MODEL,
-   and the merged svalue ptr to *OUT_MERGED_SVALUE.  */
+   and the merged svalue ptr to *OUT_MERGED_SVALUE.
+   If VAL_A or VAL_B are NULL_TREE, don't populate EXPR
+   for that region_model.  */
 
 static void
-assert_region_models_merge (tree global, tree val_a, tree val_b,
+assert_region_models_merge (tree expr, tree val_a, tree val_b,
 			    region_model *out_merged_model,
 			    svalue **out_merged_svalue)
 {
@@ -4519,28 +4521,36 @@ assert_region_models_merge (tree global, tree val_a, tree val_b,
   test_region_model_context ctxt;
   region_model model0;
   region_model model1;
-  model0.set_value (model0.get_lvalue (global, &ctxt),
-		    model0.get_rvalue (val_a, &ctxt));
-  model1.set_value (model1.get_lvalue (global, &ctxt),
-		    model1.get_rvalue (val_b, &ctxt));
+  if (val_a)
+    model0.set_value (model0.get_lvalue (expr, &ctxt),
+		      model0.get_rvalue (val_a, &ctxt));
+  if (val_b)
+    model1.set_value (model1.get_lvalue (expr, &ctxt),
+		      model1.get_rvalue (val_b, &ctxt));
 
   /* They should be mergeable.  */
   ASSERT_TRUE (model0.can_merge_with_p (model1, out_merged_model));
 
-  svalue_id merged_svalue_sid = out_merged_model->get_rvalue (global, &ctxt);
+  svalue_id merged_svalue_sid = out_merged_model->get_rvalue (expr, &ctxt);
   *out_merged_svalue = out_merged_model->get_svalue (merged_svalue_sid);
 
   // FIXME: leave verifications to the caller
 #if 0
-  /* In particular, there should be a constant value for "global".  */
-  svalue *merged_global_sval = merged.get_svalue (merged.get_rvalue (global, &ctxt));
-  ASSERT_EQ (merged_global_sval->get_kind (), SK_CONSTANT);
+  /* In particular, there should be a constant value for "expr".  */
+  svalue *merged_expr_sval = merged.get_svalue (merged.get_rvalue (expr, &ctxt));
+  ASSERT_EQ (merged_expr_sval->get_kind (), SK_CONSTANT);
   // FIXME: check cst
 #endif
 
 }
 
-
+struct region_model_merger_test
+{
+  test_region_model_context ctxt;
+  region_model m_model0;
+  region_model m_model1;
+  region_model m_merged;
+};
 
 /* FIXME.  */
 
@@ -4654,6 +4664,43 @@ test_state_merging ()
     // FIXME: constraints on them?
   }
 
+  /* Uninit and constant.  */
+  {
+    region_model merged;
+    svalue *merged_x_sval;
+    assert_region_models_merge (x, NULL_TREE, int_113, &merged, &merged_x_sval);
+
+    /* In particular, there should be an unknown value for "x".  */
+    ASSERT_EQ (merged_x_sval->get_kind (), SK_UNKNOWN);
+    // FIXME: constraints on them?
+  }
+
+  /* Constant and uninit.  */
+  {
+    region_model merged;
+    svalue *merged_x_sval;
+    assert_region_models_merge (x, int_42, NULL_TREE, &merged, &merged_x_sval);
+
+    /* In particular, there should be an unknown value for "x".  */
+    ASSERT_EQ (merged_x_sval->get_kind (), SK_UNKNOWN);
+    // FIXME: constraints on them?
+  }
+
+  /* Unknown and constant.  */
+  {
+#if 0
+    region_model_merger_test test;
+    test.m_model0.
+    region_model merged;
+    svalue *merged_x_sval;
+    assert_region_models_merge (x, int_42, int_113, &merged, &merged_x_sval);
+
+    /* In particular, there should be an unknown value for "x".  */
+    ASSERT_EQ (merged_x_sval->get_kind (), SK_UNKNOWN);
+    // FIXME: constraints on them?
+#endif
+  }
+
 #if 0
   {
     region_model model0;
-- 
1.8.5.3

