diff options
author | David Malcolm <dmalcolm@redhat.com> | 2023-07-26 10:29:20 -0400 |
---|---|---|
committer | David Malcolm <dmalcolm@redhat.com> | 2023-07-26 10:31:31 -0400 |
commit | 9d804f9b2709b38235a2fe4c6705f2af6784aa2a (patch) | |
tree | cd1fa71643e45c3bcdee6be0e7f86efad1fbcc7d /gcc/analyzer/svalue.h | |
parent | 25072a477a56a727b369bf9b20f4d18198ff5894 (diff) | |
download | gcc-9d804f9b2709b38235a2fe4c6705f2af6784aa2a.zip gcc-9d804f9b2709b38235a2fe4c6705f2af6784aa2a.tar.gz gcc-9d804f9b2709b38235a2fe4c6705f2af6784aa2a.tar.bz2 |
analyzer: add symbol base class, moving region id to there [PR104940]
This patch introduces a "symbol" base class that region and svalue
both inherit from, generalizing the ID from the region class so it's
also used by svalues. This gives a way of sorting regions and svalues
into creation order, which I've found useful in my experiments with
adding SMT support (PR analyzer/104940).
gcc/ChangeLog:
PR analyzer/104940
* Makefile.in (ANALYZER_OBJS): Add analyzer/symbol.o.
gcc/analyzer/ChangeLog:
PR analyzer/104940
* region-model-manager.cc
(region_model_manager::region_model_manager): Update for
generalizing region ids to also cover svalues.
(region_model_manager::get_or_create_constant_svalue): Likewise.
(region_model_manager::get_or_create_unknown_svalue): Likewise.
(region_model_manager::create_unique_svalue): Likewise.
(region_model_manager::get_or_create_initial_value): Likewise.
(region_model_manager::get_or_create_setjmp_svalue): Likewise.
(region_model_manager::get_or_create_poisoned_svalue): Likewise.
(region_model_manager::get_ptr_svalue): Likewise.
(region_model_manager::get_or_create_unaryop): Likewise.
(region_model_manager::get_or_create_binop): Likewise.
(region_model_manager::get_or_create_sub_svalue): Likewise.
(region_model_manager::get_or_create_repeated_svalue): Likewise.
(region_model_manager::get_or_create_bits_within): Likewise.
(region_model_manager::get_or_create_unmergeable): Likewise.
(region_model_manager::get_or_create_widening_svalue): Likewise.
(region_model_manager::get_or_create_compound_svalue): Likewise.
(region_model_manager::get_or_create_conjured_svalue): Likewise.
(region_model_manager::get_or_create_asm_output_svalue): Likewise.
(region_model_manager::get_or_create_const_fn_result_svalue):
Likewise.
(region_model_manager::get_region_for_fndecl): Likewise.
(region_model_manager::get_region_for_label): Likewise.
(region_model_manager::get_region_for_global): Likewise.
(region_model_manager::get_field_region): Likewise.
(region_model_manager::get_element_region): Likewise.
(region_model_manager::get_offset_region): Likewise.
(region_model_manager::get_sized_region): Likewise.
(region_model_manager::get_cast_region): Likewise.
(region_model_manager::get_frame_region): Likewise.
(region_model_manager::get_symbolic_region): Likewise.
(region_model_manager::get_region_for_string): Likewise.
(region_model_manager::get_bit_range): Likewise.
(region_model_manager::get_var_arg_region): Likewise.
(region_model_manager::get_region_for_unexpected_tree_code):
Likewise.
(region_model_manager::get_or_create_region_for_heap_alloc):
Likewise.
(region_model_manager::create_region_for_alloca): Likewise.
(region_model_manager::log_stats): Likewise.
* region-model-manager.h (region_model_manager::get_num_regions):
Replace with...
(region_model_manager::get_num_symbols): ...this.
(region_model_manager::alloc_region_id): Replace with...
(region_model_manager::alloc_symbol_id): ...this.
(region_model_manager::m_next_region_id): Replace with...
(region_model_manager::m_next_symbol_id): ...this.
* region-model.cc (selftest::test_get_representative_tree): Update
for generalizing region ids to also cover svalues.
(selftest::test_binop_svalue_folding): Likewise.
(selftest::test_state_merging): Likewise.
* region.cc (region::cmp_ids): Delete, in favor of
symbol::cmp_ids.
(region::region): Update for introduction of symbol base class.
(frame_region::get_region_for_local): Likewise.
(root_region::root_region): Likewise.
(symbolic_region::symbolic_region): Likewise.
* region.h: Replace include of "analyzer/complexity.h" with
"analyzer/symbol.h".
(class region): Make a subclass of symbol.
(region::get_id): Delete in favor of symbol::get_id.
(region::cmp_ids): Delete in favor of symbol::cmp_ids.
(region::get_complexity): Delete in favor of
symbol::get_complexity.
(region::region): Use symbol::id_t for "id" param.
(region::m_complexity): Move field to symbol base class.
(region::m_id): Likewise.
(space_region::space_region): Use symbol::id_t for "id" param.
(frame_region::frame_region): Likewise.
(globals_region::globals_region): Likewise.
(code_region::code_region): Likewise.
(function_region::function_region): Likewise.
(label_region::label_region): Likewise.
(stack_region::stack_region): Likewise.
(heap_region::heap_region): Likewise.
(thread_local_region::thread_local_region): Likewise.
(root_region::root_region): Likewise.
(symbolic_region::symbolic_region): Likewise.
(decl_region::decl_region): Likewise.
(field_region::field_region): Likewise.
(element_region::element_region): Likewise.
(offset_region::offset_region): Likewise.
(sized_region::sized_region): Likewise.
(cast_region::cast_region): Likewise.
(heap_allocated_region::heap_allocated_region): Likewise.
(alloca_region::alloca_region): Likewise.
(string_region::string_region): Likewise.
(bit_range_region::bit_range_region): Likewise.
(var_arg_region::var_arg_region): Likewise.
(errno_region::errno_region): Likewise.
(unknown_region::unknown_region): Likewise.
* svalue.cc (sub_svalue::sub_svalue): Add symbol::id_t param.
(repeated_svalue::repeated_svalue): Likewise.
(bits_within_svalue::bits_within_svalue): Likewise.
(compound_svalue::compound_svalue): Likewise.
* svalue.h: Replace include of "analyzer/complexity.h" with
"analyzer/symbol.h".
(class svalue): Make a subclass of symbol.
(svalue::get_complexity): Delete in favor of
symbol::get_complexity.
(svalue::svalue): Add symbol::id_t param. Update for new base
class.
(svalue::m_complexity): Delete in favor of
symbol::m_complexity.
(region_svalue::region_svalue): Add symbol::id_t param
(constant_svalue::constant_svalue): Likewise.
(unknown_svalue::unknown_svalue): Likewise.
(poisoned_svalue::poisoned_svalue): Likewise.
(setjmp_svalue::setjmp_svalue): Likewise.
(initial_svalue::initial_svalue): Likewise.
(unaryop_svalue::unaryop_svalue): Likewise.
(binop_svalue::binop_svalue): Likewise.
(sub_svalue::sub_svalue): Likewise.
(repeated_svalue::repeated_svalue): Likewise.
(bits_within_svalue::bits_within_svalue): Likewise.
(unmergeable_svalue::unmergeable_svalue): Likewise.
(placeholder_svalue::placeholder_svalue): Likewise.
(widening_svalue::widening_svalue): Likewise.
(compound_svalue::compound_svalue): Likewise.
(conjured_svalue::conjured_svalue): Likewise.
(asm_output_svalue::asm_output_svalue): Likewise.
(const_fn_result_svalue::const_fn_result_svalue): Likewise.
* symbol.cc: New file.
* symbol.h: New file.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diffstat (limited to 'gcc/analyzer/svalue.h')
-rw-r--r-- | gcc/analyzer/svalue.h | 86 |
1 files changed, 46 insertions, 40 deletions
diff --git a/gcc/analyzer/svalue.h b/gcc/analyzer/svalue.h index c8c3258..fbb1018 100644 --- a/gcc/analyzer/svalue.h +++ b/gcc/analyzer/svalue.h @@ -21,7 +21,7 @@ along with GCC; see the file COPYING3. If not see #ifndef GCC_ANALYZER_SVALUE_H #define GCC_ANALYZER_SVALUE_H -#include "analyzer/complexity.h" +#include "analyzer/symbol.h" #include "analyzer/store.h" #include "analyzer/program-point.h" @@ -86,7 +86,7 @@ enum svalue_kind /* An abstract base class representing a value held by a region of memory. */ -class svalue +class svalue : public symbol { public: virtual ~svalue () {} @@ -146,8 +146,6 @@ public: region_model_manager *mgr, model_merger *merger) const; - const complexity &get_complexity () const { return m_complexity; } - virtual void accept (visitor *v) const = 0; bool live_p (const svalue_set *live_svalues, @@ -180,12 +178,11 @@ public: const region *maybe_get_deref_base_region () const; protected: - svalue (complexity c, tree type) - : m_complexity (c), m_type (type) + svalue (complexity c, symbol::id_t id, tree type) + : symbol (c, id), m_type (type) {} private: - complexity m_complexity; tree m_type; }; @@ -224,8 +221,8 @@ public: const region *m_reg; }; - region_svalue (tree type, const region *reg) - : svalue (complexity (reg), type), + region_svalue (symbol::id_t id, tree type, const region *reg) + : svalue (complexity (reg), id, type), m_reg (reg) { gcc_assert (m_reg != NULL); @@ -273,8 +270,8 @@ namespace ana { class constant_svalue : public svalue { public: - constant_svalue (tree cst_expr) - : svalue (complexity (1, 1), TREE_TYPE (cst_expr)), m_cst_expr (cst_expr) + constant_svalue (symbol::id_t id, tree cst_expr) + : svalue (complexity (1, 1), id, TREE_TYPE (cst_expr)), m_cst_expr (cst_expr) { gcc_assert (cst_expr); gcc_assert (CONSTANT_CLASS_P (cst_expr)); @@ -325,8 +322,8 @@ namespace ana { class unknown_svalue : public svalue { public: - unknown_svalue (tree type) - : svalue (complexity (1, 1), type) + unknown_svalue (symbol::id_t id, tree type) + : svalue (complexity (1, 1), id, type) {} enum svalue_kind get_kind () const final override { return SK_UNKNOWN; } @@ -394,8 +391,8 @@ public: tree m_type; }; - poisoned_svalue (enum poison_kind kind, tree type) - : svalue (complexity (1, 1), type), m_kind (kind) {} + poisoned_svalue (enum poison_kind kind, symbol::id_t id, tree type) + : svalue (complexity (1, 1), id, type), m_kind (kind) {} enum svalue_kind get_kind () const final override { return SK_POISONED; } const poisoned_svalue * @@ -502,8 +499,9 @@ public: }; setjmp_svalue (const setjmp_record &setjmp_record, - tree type) - : svalue (complexity (1, 1), type), m_setjmp_record (setjmp_record) + symbol::id_t id, + tree type) + : svalue (complexity (1, 1), id, type), m_setjmp_record (setjmp_record) {} enum svalue_kind get_kind () const final override { return SK_SETJMP; } @@ -550,8 +548,8 @@ namespace ana { class initial_svalue : public svalue { public: - initial_svalue (tree type, const region *reg) - : svalue (complexity (reg), type), m_reg (reg) + initial_svalue (symbol::id_t id, tree type, const region *reg) + : svalue (complexity (reg), id, type), m_reg (reg) { gcc_assert (m_reg != NULL); } @@ -624,8 +622,9 @@ public: const svalue *m_arg; }; - unaryop_svalue (tree type, enum tree_code op, const svalue *arg) - : svalue (complexity (arg), type), m_op (op), m_arg (arg) + unaryop_svalue (symbol::id_t id, tree type, enum tree_code op, + const svalue *arg) + : svalue (complexity (arg), id, type), m_op (op), m_arg (arg) { gcc_assert (arg->can_have_associated_state_p ()); } @@ -713,11 +712,12 @@ public: const svalue *m_arg1; }; - binop_svalue (tree type, enum tree_code op, - const svalue *arg0, const svalue *arg1) + binop_svalue (symbol::id_t id, tree type, enum tree_code op, + const svalue *arg0, const svalue *arg1) : svalue (complexity::from_pair (arg0->get_complexity (), arg1->get_complexity ()), - type), + id, + type), m_op (op), m_arg0 (arg0), m_arg1 (arg1) { gcc_assert (arg0->can_have_associated_state_p ()); @@ -802,8 +802,8 @@ public: const svalue *m_parent_svalue; const region *m_subregion; }; - sub_svalue (tree type, const svalue *parent_svalue, - const region *subregion); + sub_svalue (symbol::id_t id, tree type, const svalue *parent_svalue, + const region *subregion); enum svalue_kind get_kind () const final override { return SK_SUB; } const sub_svalue *dyn_cast_sub_svalue () const final override @@ -883,7 +883,8 @@ public: const svalue *m_outer_size; const svalue *m_inner_svalue; }; - repeated_svalue (tree type, + repeated_svalue (symbol::id_t id, + tree type, const svalue *outer_size, const svalue *inner_svalue); @@ -970,7 +971,8 @@ public: bit_range m_bits; const svalue *m_inner_svalue; }; - bits_within_svalue (tree type, + bits_within_svalue (symbol::id_t id, + tree type, const bit_range &bits, const svalue *inner_svalue); @@ -1031,8 +1033,8 @@ namespace ana { class unmergeable_svalue : public svalue { public: - unmergeable_svalue (const svalue *arg) - : svalue (complexity (arg), arg->get_type ()), m_arg (arg) + unmergeable_svalue (symbol::id_t id, const svalue *arg) + : svalue (complexity (arg), id, arg->get_type ()), m_arg (arg) { } @@ -1071,8 +1073,8 @@ namespace ana { class placeholder_svalue : public svalue { public: - placeholder_svalue (tree type, const char *name) - : svalue (complexity (1, 1), type), m_name (name) + placeholder_svalue (symbol::id_t id, tree type, const char *name) + : svalue (complexity (1, 1), id, type), m_name (name) { } @@ -1155,10 +1157,11 @@ public: DIR_UNKNOWN }; - widening_svalue (tree type, const function_point &point, + widening_svalue (symbol::id_t id, tree type, const function_point &point, const svalue *base_sval, const svalue *iter_sval) : svalue (complexity::from_pair (base_sval->get_complexity (), iter_sval->get_complexity ()), + id, type), m_point (point), m_base_sval (base_sval), m_iter_sval (iter_sval) @@ -1260,7 +1263,7 @@ public: const binding_map *m_map_ptr; }; - compound_svalue (tree type, const binding_map &map); + compound_svalue (symbol::id_t id, tree type, const binding_map &map); enum svalue_kind get_kind () const final override { return SK_COMPOUND; } const compound_svalue *dyn_cast_compound_svalue () const final override @@ -1389,8 +1392,9 @@ public: const region *m_id_reg; }; - conjured_svalue (tree type, const gimple *stmt, const region *id_reg) - : svalue (complexity (id_reg), type), + conjured_svalue (symbol::id_t id, tree type, const gimple *stmt, + const region *id_reg) + : svalue (complexity (id_reg), id, type), m_stmt (stmt), m_id_reg (id_reg) { gcc_assert (m_stmt != NULL); @@ -1501,12 +1505,13 @@ public: const svalue *m_input_arr[MAX_INPUTS]; }; - asm_output_svalue (tree type, + asm_output_svalue (symbol::id_t id, + tree type, const char *asm_string, unsigned output_idx, unsigned num_outputs, const vec<const svalue *> &inputs) - : svalue (complexity::from_vec_svalue (inputs), type), + : svalue (complexity::from_vec_svalue (inputs), id, type), m_asm_string (asm_string), m_output_idx (output_idx), m_num_outputs (num_outputs), @@ -1634,10 +1639,11 @@ public: const svalue *m_input_arr[MAX_INPUTS]; }; - const_fn_result_svalue (tree type, + const_fn_result_svalue (symbol::id_t id, + tree type, tree fndecl, const vec<const svalue *> &inputs) - : svalue (complexity::from_vec_svalue (inputs), type), + : svalue (complexity::from_vec_svalue (inputs), id, type), m_fndecl (fndecl), m_num_inputs (inputs.length ()) { |