gcc/analyzer/ChangeLog: * kf.cc (kf_memcpy_memmove::impl_call_pre): Reimplement using region_model::copy_bytes. * region-model.cc (region_model::read_bytes): New. (region_model::copy_bytes): New. * region-model.h (region_model::read_bytes): New decl. (region_model::copy_bytes): New decl. --- gcc/analyzer/kf.cc | 14 ++++---------- gcc/analyzer/region-model.cc | 35 +++++++++++++++++++++++++++++++++++ gcc/analyzer/region-model.h | 9 +++++++++ 3 files changed, 48 insertions(+), 10 deletions(-)
diff --git a/gcc/analyzer/kf.cc b/gcc/analyzer/kf.cc index 6b33cd159dac..3eddbe200387 100644 --- a/gcc/analyzer/kf.cc +++ b/gcc/analyzer/kf.cc @@ -541,7 +541,6 @@ kf_memcpy_memmove::impl_call_pre (const call_details &cd) const const svalue *num_bytes_sval = cd.get_arg_svalue (2); region_model *model = cd.get_model (); - region_model_manager *mgr = cd.get_manager (); const region *dest_reg = model->deref_rvalue (dest_ptr_sval, cd.get_arg_tree (0), cd.get_ctxt ()); @@ -550,15 +549,10 @@ kf_memcpy_memmove::impl_call_pre (const call_details &cd) const cd.maybe_set_lhs (dest_ptr_sval); - const region *sized_src_reg - = mgr->get_sized_region (src_reg, NULL_TREE, num_bytes_sval); - const region *sized_dest_reg - = mgr->get_sized_region (dest_reg, NULL_TREE, num_bytes_sval); - const svalue *src_contents_sval - = model->get_store_value (sized_src_reg, cd.get_ctxt ()); - model->check_for_poison (src_contents_sval, cd.get_arg_tree (1), - sized_src_reg, cd.get_ctxt ()); - model->set_value (sized_dest_reg, src_contents_sval, cd.get_ctxt ()); + model->copy_bytes (dest_reg, + src_reg, cd.get_arg_tree (1), + num_bytes_sval, + cd.get_ctxt ()); } /* Handler for "memset" and "__builtin_memset". */ diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc index 1fe66f4719fa..00c306ab7dae 100644 --- a/gcc/analyzer/region-model.cc +++ b/gcc/analyzer/region-model.cc @@ -3794,6 +3794,41 @@ region_model::write_bytes (const region *dest_reg, set_value (sized_dest_reg, sval, ctxt); } +/* Read NUM_BYTES_SVAL from SRC_REG. + Use CTXT to report any warnings associated with the copy + (e.g. out-of-bounds reads, copying of uninitialized values, etc). */ + +const svalue * +region_model::read_bytes (const region *src_reg, + tree src_ptr_expr, + const svalue *num_bytes_sval, + region_model_context *ctxt) const +{ + const region *sized_src_reg + = m_mgr->get_sized_region (src_reg, NULL_TREE, num_bytes_sval); + const svalue *src_contents_sval = get_store_value (sized_src_reg, ctxt); + check_for_poison (src_contents_sval, src_ptr_expr, + sized_src_reg, ctxt); + return src_contents_sval; +} + +/* Copy NUM_BYTES_SVAL bytes from SRC_REG to DEST_REG. + Use CTXT to report any warnings associated with the copy + (e.g. out-of-bounds reads/writes, copying of uninitialized values, + etc). */ + +void +region_model::copy_bytes (const region *dest_reg, + const region *src_reg, + tree src_ptr_expr, + const svalue *num_bytes_sval, + region_model_context *ctxt) +{ + const svalue *data_sval + = read_bytes (src_reg, src_ptr_expr, num_bytes_sval, ctxt); + write_bytes (dest_reg, num_bytes_sval, data_sval, ctxt); +} + /* Mark REG as having unknown content. */ void diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h index 41df1885ad5b..b1c705e22c28 100644 --- a/gcc/analyzer/region-model.h +++ b/gcc/analyzer/region-model.h @@ -371,6 +371,15 @@ class region_model const svalue *num_bytes_sval, const svalue *sval, region_model_context *ctxt); + const svalue *read_bytes (const region *src_reg, + tree src_ptr_expr, + const svalue *num_bytes_sval, + region_model_context *ctxt) const; + void copy_bytes (const region *dest_reg, + const region *src_reg, + tree src_ptr_expr, + const svalue *num_bytes_sval, + region_model_context *ctxt); void mark_region_as_unknown (const region *reg, uncertainty_t *uncertainty); tristate eval_condition (const svalue *lhs, -- 2.26.3