From b925618e0866b0f2dbbd85ad2134d1d43666633b Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Tue, 9 Jun 2020 13:33:41 -0400 Subject: [PATCH 219/315] FIXME: reject attempts to set sm-state or constraints involving UNKNOWN --- gcc/analyzer/constraint-manager2.cc | 15 +++++++++++++++ gcc/analyzer/program-state.cc | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/gcc/analyzer/constraint-manager2.cc b/gcc/analyzer/constraint-manager2.cc index 34f753124a9..a8779f35e71 100644 --- a/gcc/analyzer/constraint-manager2.cc +++ b/gcc/analyzer/constraint-manager2.cc @@ -665,6 +665,13 @@ constraint_manager2::add_constraint (const svalue2 *lhs, { lhs = lhs->unwrap_any_unmergeable (); rhs = rhs->unwrap_any_unmergeable (); + + /* Nothing can be known about unknown values. */ + if (lhs->get_kind () == svalue2::SK_UNKNOWN + || rhs->get_kind () == svalue2::SK_UNKNOWN) + /* Not a contradiction. */ + return true; + equiv_class2_id lhs_ec_id = get_or_add_equiv_class2 (lhs); equiv_class2_id rhs_ec_id = get_or_add_equiv_class2 (rhs); return add_constraint (lhs_ec_id, op,rhs_ec_id); @@ -943,6 +950,8 @@ constraint_manager2::get_or_add_equiv_class2 (const svalue2 *sval) { equiv_class2_id result (-1); + gcc_assert (sval->get_kind () != svalue2::SK_UNKNOWN); + /* Try svalue2 match. */ if (get_equiv_class2_by_svalue2 (sval, &result)) return result; @@ -1086,6 +1095,12 @@ constraint_manager2::eval_condition (const svalue2 *lhs, { lhs = lhs->unwrap_any_unmergeable (); rhs = rhs->unwrap_any_unmergeable (); + + /* Nothing can be known about unknown values. */ + if (lhs->get_kind () == svalue2::SK_UNKNOWN + || rhs->get_kind () == svalue2::SK_UNKNOWN) + return tristate (tristate::TS_UNKNOWN); + return eval_condition (get_or_add_equiv_class2 (lhs), op, get_or_add_equiv_class2 (rhs)); diff --git a/gcc/analyzer/program-state.cc b/gcc/analyzer/program-state.cc index c05a200fe0e..ebe4452e475 100644 --- a/gcc/analyzer/program-state.cc +++ b/gcc/analyzer/program-state.cc @@ -786,6 +786,11 @@ sm_state_map2::set_state (region_model2 *model, { if (model == NULL) return; + + /* Reject attempts to set state on UNKNOWN. */ + if (sval->get_kind () == svalue2::SK_UNKNOWN) + return; + equiv_class2 &ec = model->get_constraints2 ()->get_equiv_class2 (sval); if (!set_state (ec, state, origin)) return; -- 2.26.2