aboutsummaryrefslogtreecommitdiff
path: root/gcc/analyzer
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/analyzer')
-rw-r--r--gcc/analyzer/region-model-reachability.cc8
-rw-r--r--gcc/analyzer/svalue.cc42
-rw-r--r--gcc/analyzer/svalue.h2
3 files changed, 46 insertions, 6 deletions
diff --git a/gcc/analyzer/region-model-reachability.cc b/gcc/analyzer/region-model-reachability.cc
index b876b8f..12d09c3 100644
--- a/gcc/analyzer/region-model-reachability.cc
+++ b/gcc/analyzer/region-model-reachability.cc
@@ -252,12 +252,8 @@ reachable_regions::handle_parm (const svalue *sval, tree param_type)
m_mutable_svals.add (sval);
else
m_reachable_svals.add (sval);
- if (const region_svalue *parm_ptr
- = sval->dyn_cast_region_svalue ())
- {
- const region *pointee_reg = parm_ptr->get_pointee ();
- add (pointee_reg, is_mutable);
- }
+ if (const region *base_reg = sval->maybe_get_deref_base_region ())
+ add (base_reg, is_mutable);
/* Treat all svalues within a compound_svalue as reachable. */
if (const compound_svalue *compound_sval
= sval->dyn_cast_compound_svalue ())
diff --git a/gcc/analyzer/svalue.cc b/gcc/analyzer/svalue.cc
index 536bc28..a1403f0 100644
--- a/gcc/analyzer/svalue.cc
+++ b/gcc/analyzer/svalue.cc
@@ -651,6 +651,48 @@ svalue::all_zeroes_p () const
return false;
}
+/* If this svalue is a pointer, attempt to determine the base region it points
+ to. Return NULL on any problems. */
+
+const region *
+svalue::maybe_get_deref_base_region () const
+{
+ const svalue *iter = this;
+ while (1)
+ {
+ switch (iter->get_kind ())
+ {
+ default:
+ return NULL;
+
+ case SK_REGION:
+ {
+ const region_svalue *region_sval
+ = as_a <const region_svalue *> (iter);
+ return region_sval->get_pointee ()->get_base_region ();
+ }
+
+ case SK_BINOP:
+ {
+ const binop_svalue *binop_sval
+ = as_a <const binop_svalue *> (iter);
+ switch (binop_sval->get_op ())
+ {
+ case POINTER_PLUS_EXPR:
+ /* If we have a symbolic value expressing pointer arithmetic,
+ use the LHS. */
+ iter = binop_sval->get_arg0 ();
+ continue;
+
+ default:
+ return NULL;
+ }
+ return NULL;
+ }
+ }
+ }
+}
+
/* class region_svalue : public svalue. */
/* Implementation of svalue::dump_to_pp vfunc for region_svalue. */
diff --git a/gcc/analyzer/svalue.h b/gcc/analyzer/svalue.h
index 4bbe858..29ea2ee 100644
--- a/gcc/analyzer/svalue.h
+++ b/gcc/analyzer/svalue.h
@@ -175,6 +175,8 @@ public:
per-type and thus it's meaningless for them to "have state". */
virtual bool can_have_associated_state_p () const { return true; }
+ const region *maybe_get_deref_base_region () const;
+
protected:
svalue (complexity c, tree type)
: m_complexity (c), m_type (type)