From: David Malcolm Date: Thu, 6 Jan 2022 16:43:36 +0000 (-0500) Subject: analyzer: add logging of aliasing X-Git-Tag: upstream/12.2.0~2319 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11a2ff8d981110e1562caf7d98e41c1ff2e76056;p=platform%2Fupstream%2Fgcc.git analyzer: add logging of aliasing gcc/analyzer/ChangeLog: * engine.cc (impl_run_checkers): Pass logger to engine ctor. * region-model-manager.cc (region_model_manager::region_model_manager): Add logger param and use it to initialize m_logger. * region-model.cc (engine::engine): New. * region-model.h (region_model_manager::region_model_manager): Add logger param. (region_model_manager::get_logger): New. (region_model_manager::m_logger): New field. (engine::engine): New. * store.cc (store_manager::get_logger): New. (store::set_value): Log scope. Log when marking a cluster as unknown due to possible aliasing. * store.h (store_manager::get_logger): New decl. --- diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc index 0d456a1..346b659 100644 --- a/gcc/analyzer/engine.cc +++ b/gcc/analyzer/engine.cc @@ -5329,7 +5329,7 @@ impl_run_checkers (logger *logger) FOR_EACH_FUNCTION_WITH_GIMPLE_BODY (node) node->get_untransformed_body (); - engine eng; + engine eng (logger); /* Create the supergraph. */ supergraph sg (logger); diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc index 19e1a93..998bbe7 100644 --- a/gcc/analyzer/region-model-manager.cc +++ b/gcc/analyzer/region-model-manager.cc @@ -66,8 +66,9 @@ namespace ana { /* region_model_manager's ctor. */ -region_model_manager::region_model_manager () -: m_next_region_id (0), +region_model_manager::region_model_manager (logger *logger) +: m_logger (logger), + m_next_region_id (0), m_root_region (alloc_region_id ()), m_stack_region (alloc_region_id (), &m_root_region), m_heap_region (alloc_region_id (), &m_root_region), diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index cb86d79..8708a91 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -3965,6 +3965,13 @@ rejected_ranges_constraint::dump_to_pp (pretty_printer *pp) const /* class engine. */ +/* engine's ctor. */ + +engine::engine (logger *logger) +: m_mgr (logger) +{ +} + /* Dump the managed objects by class to LOGGER, and the per-class totals. */ void diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index 669f1c7..b1fa4fc 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -240,7 +240,7 @@ namespace ana { class region_model_manager { public: - region_model_manager (); + region_model_manager (logger *logger = NULL); ~region_model_manager (); /* svalue consolidation. */ @@ -335,6 +335,8 @@ public: void enable_complexity_check (void) { m_check_complexity = true; } void disable_complexity_check (void) { m_check_complexity = false; } + logger *get_logger () const { return m_logger; } + private: bool too_complex_p (const complexity &c) const; bool reject_if_too_complex (svalue *sval); @@ -358,6 +360,8 @@ private: const svalue *maybe_fold_asm_output_svalue (tree type, const vec &inputs); + logger *m_logger; + unsigned m_next_region_id; root_region m_root_region; stack_region m_stack_region; @@ -1080,6 +1084,7 @@ private: class engine { public: + engine (logger *logger = NULL); region_model_manager *get_model_manager () { return &m_mgr; } void log_stats (logger *logger) const; diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc index 3f91b61..ade6dec 100644 --- a/gcc/analyzer/store.cc +++ b/gcc/analyzer/store.cc @@ -1987,6 +1987,12 @@ binding_cluster::maybe_get_simple_value (store_manager *mgr) const /* class store_manager. */ +logger * +store_manager::get_logger () const +{ + return m_mgr->get_logger (); +} + /* binding consolidation. */ const concrete_binding * @@ -2353,6 +2359,9 @@ store::set_value (store_manager *mgr, const region *lhs_reg, const svalue *rhs_sval, uncertainty_t *uncertainty) { + logger *logger = mgr->get_logger (); + LOG_SCOPE (logger); + remove_overlapping_bindings (mgr, lhs_reg); rhs_sval = simplify_for_binding (rhs_sval); @@ -2405,6 +2414,18 @@ store::set_value (store_manager *mgr, const region *lhs_reg, gcc_unreachable (); case tristate::TS_UNKNOWN: + if (logger) + { + pretty_printer *pp = logger->get_printer (); + logger->start_log_line (); + logger->log_partial ("possible aliasing of "); + iter_base_reg->dump_to_pp (pp, true); + logger->log_partial (" when writing SVAL: "); + rhs_sval->dump_to_pp (pp, true); + logger->log_partial (" to LHS_REG: "); + lhs_reg->dump_to_pp (pp, true); + logger->end_log_line (); + } iter_cluster->mark_region_as_unknown (mgr, iter_base_reg, uncertainty); break; diff --git a/gcc/analyzer/store.h b/gcc/analyzer/store.h index f30b6bc..ee084dd 100644 --- a/gcc/analyzer/store.h +++ b/gcc/analyzer/store.h @@ -787,6 +787,8 @@ class store_manager public: store_manager (region_model_manager *mgr) : m_mgr (mgr) {} + logger *get_logger () const; + /* binding consolidation. */ const concrete_binding * get_concrete_binding (bit_offset_t start_bit_offset,