From 6f86087091c5a77e91a711a180550ba35c3f58b5 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Thu, 2 Jul 2020 16:15:44 -0400 Subject: [PATCH 281/315] FIXME: implement pointer comparisons of INIT_VAL(PARM) with &LOCAL --- gcc/analyzer/region-model2.cc | 37 ++++++++++++++++++++++++++++------- gcc/analyzer/region-model2.h | 2 ++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc index 08ccd8ceea2..4579ebd7c5a 100644 --- a/gcc/analyzer/region-model2.cc +++ b/gcc/analyzer/region-model2.cc @@ -6288,12 +6288,8 @@ region_model2::eval_condition_without_cm (const svalue2 *lhs, } } - /* Initial values of "external" values (such as params) can't point - at locals. */ - // FIXME: what about other "external" values vs escaped clusters - /* Initial values of pointers can't point at locals. - FIXME: unless they escaped? */ -#if 0 + /* Handle rejection of equality for comparisons of the initial values of + "external" values (such as params) with the address of locals. */ if (const initial_svalue2 *init_lhs = lhs->dyn_cast_initial_svalue2 ()) if (const region_svalue2 *rhs_ptr = rhs->dyn_cast_region_svalue2 ()) { @@ -6308,7 +6304,6 @@ region_model2::eval_condition_without_cm (const svalue2 *lhs, if (res.is_known ()) return res; } -#endif if (const widening_svalue2 *widen_lhs = lhs->dyn_cast_widening_svalue2 ()) if (tree rhs_cst = rhs->maybe_get_constant ()) @@ -6327,6 +6322,34 @@ region_model2::eval_condition_without_cm (const svalue2 *lhs, return tristate::TS_UNKNOWN; } +/* Subroutine of region_model2::eval_condition_without_cm, for rejecting + equality of INIT_VAL(PARM) with &LOCAL. */ + +tristate +region_model2::compare_initial_and_pointer (const initial_svalue2 *init, + const region_svalue2 *ptr) const +{ + const region2 *pointee = ptr->get_pointee (); + + /* If we have a pointer to something within a stack frame, it can't be the + initial value of a param. */ + if (pointee->maybe_get_frame_region ()) + { + const region2 *reg = init->get_region (); + if (tree reg_decl = reg->maybe_get_decl ()) + if (TREE_CODE (reg_decl) == SSA_NAME) + { + tree ssa_name = reg_decl; + if (SSA_NAME_IS_DEFAULT_DEF (ssa_name) + && SSA_NAME_VAR (ssa_name) + && TREE_CODE (SSA_NAME_VAR (ssa_name)) == PARM_DECL) + return tristate::TS_FALSE; + } + } + + return tristate::TS_UNKNOWN; +} + /* Attempt to add the constraint "LHS OP RHS" to this region_model2. If it is consistent with existing constraints, add it, and return true. Return false if it contradicts existing constraints. diff --git a/gcc/analyzer/region-model2.h b/gcc/analyzer/region-model2.h index a57a8da5c18..c0520d5c985 100644 --- a/gcc/analyzer/region-model2.h +++ b/gcc/analyzer/region-model2.h @@ -2393,6 +2393,8 @@ class region_model2 tristate eval_condition_without_cm (const svalue2 *lhs, enum tree_code op, const svalue2 *rhs) const; + tristate compare_initial_and_pointer (const initial_svalue2 *init, + const region_svalue2 *ptr) const; tristate eval_condition (tree lhs, enum tree_code op, tree rhs, -- 2.26.2