From 9eef1943b8c3b67effea5a054ee9fa45542c6239 Mon Sep 17 00:00:00 2001 From: David Malcolm Date: Fri, 29 May 2020 10:04:53 -0400 Subject: [PATCH 193/315] FIXME: fix flickering test in data-model-14.c --- gcc/analyzer/analyzer.h | 1 + gcc/analyzer/engine.cc | 19 ++++++++++++++----- gcc/analyzer/region-model2.cc | 17 ++++++++++++++--- gcc/analyzer/region-model2.h | 7 +++++++ 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/gcc/analyzer/analyzer.h b/gcc/analyzer/analyzer.h index 00d27d77071..7b49af636b9 100644 --- a/gcc/analyzer/analyzer.h +++ b/gcc/analyzer/analyzer.h @@ -64,6 +64,7 @@ class svalue2; class unaryop_svalue2; class binop_svalue2; class region2; + class frame_region2; class function_region2; class label_region2; class decl_region2; diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 238b0fa40fb..4df661c9e39 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -735,12 +735,14 @@ readability (const_tree expr) case MEM_REF: /* Impose a slight readability penalty relative to that of operand 0. */ - return readability (TREE_OPERAND (expr, 0)) - 1; + return readability (TREE_OPERAND (expr, 0)) - 16; case SSA_NAME: { if (tree var = SSA_NAME_VAR (expr)) - return readability (var); + /* Slightly favor the underlying var over the SSA name to + avoid having them compare equal. */ + return readability (var) - 1; /* Avoid printing '' for SSA names for temporaries. */ return -1; } @@ -749,7 +751,7 @@ readability (const_tree expr) case PARM_DECL: case VAR_DECL: /* Arbitrarily-chosen "high readability" value. */ - return 256; + return 65536; default: return 0; @@ -767,11 +769,18 @@ readability_comparator (const void *p1, const void *p2) path_var pv1 = *(path_var const *)p1; path_var pv2 = *(path_var const *)p2; - /* TODO: should we consider stack depths? */ int r1 = readability (pv1.m_tree); int r2 = readability (pv2.m_tree); + if (int cmp = r2 - r1) + return cmp; - return r2 - r1; + /* Favor items that are deeper on the stack and hence more recent; + this also favors locals over globals. */ + if (int cmp = pv2.m_stack_depth - pv1.m_stack_depth) + return cmp; + + /* TODO: We ought to find ways of sorting such cases. */ + return 0; } /* Create an sm_context and use it to call SM's on_leak vfunc, so that diff --git a/gcc/analyzer/region-model2.cc b/gcc/analyzer/region-model2.cc index f786f7bd386..204d5a03302 100644 --- a/gcc/analyzer/region-model2.cc +++ b/gcc/analyzer/region-model2.cc @@ -2462,12 +2462,23 @@ decl_region2::dump_to_pp (pretty_printer *pp, bool simple) const bool decl_region2::get_representative_path_var (path_var *out) const { - // FIXME: use correct stack depth - // FIXME: should we store a path_var, rather that a tree? - *out = path_var (m_decl, 0); + *out = path_var (m_decl, get_stack_depth ()); return true; } +/* FIXME. */ + +int +decl_region2::get_stack_depth () const +{ + if (get_parent_region () == NULL) + return 0; + if (const frame_region2 *frame_reg + = get_parent_region ()->dyn_cast_frame_region2 ()) + return frame_reg->get_stack_depth (); + return 0; +} + /* class field_region2 : public region2. */ void diff --git a/gcc/analyzer/region-model2.h b/gcc/analyzer/region-model2.h index 2e3953174f7..c380a1bf43b 100644 --- a/gcc/analyzer/region-model2.h +++ b/gcc/analyzer/region-model2.h @@ -850,6 +850,8 @@ public: static int cmp_ids (const region2 *reg1, const region2 *reg2); virtual enum kind get_kind () const = 0; + virtual const frame_region2 * + dyn_cast_frame_region2 () const { return NULL; } virtual const function_region2 * dyn_cast_function_region2 () const { return NULL; } virtual const symbolic_region2 * @@ -999,6 +1001,10 @@ public: /* region2 vfuncs. */ enum kind get_kind () const FINAL OVERRIDE { return RK_FRAME; } + const frame_region2 * dyn_cast_frame_region2 () const FINAL OVERRIDE + { + return this; + } void dump_to_pp (pretty_printer *pp, bool simple) const FINAL OVERRIDE; #if 0 void add_to_hash (inchash::hash &hstate) const FINAL OVERRIDE; @@ -1369,6 +1375,7 @@ public: bool get_representative_path_var (path_var *out) const FINAL OVERRIDE; tree get_decl () const { return m_decl; } + int get_stack_depth () const; protected: void add_to_hash (inchash::hash &hstate) const OVERRIDE; -- 2.26.2