@@ -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". */
@@ -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
@@ -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,