Skip to content

Commit 04e5c8a

Browse files
author
Enrico Steffinlongo
committed
Added doxygen to all shadow memory util functions
1 parent df12fce commit 04e5c8a

File tree

2 files changed

+85
-21
lines changed

2 files changed

+85
-21
lines changed

src/goto-symex/shadow_memory_util.cpp

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ void log_value_set(
138138
#endif
139139
}
140140

141+
/// Log a match between an address and a value the value set. This version of
142+
/// the function reports more details, including the base address, the pointer
143+
/// and the shadow value.
141144
void log_value_set_match(
142145
const namespacet &ns,
143146
const messaget &log,
@@ -185,6 +188,9 @@ void log_value_set_match(
185188
#endif
186189
}
187190

191+
/// Log trying out a match between an object and a (target) shadow address.
192+
/// @param shadowed_address The address for which we're currently attempting to
193+
/// match.
188194
void log_try_shadow_address(
189195
const namespacet &ns,
190196
const messaget &log,
@@ -199,6 +205,9 @@ void log_try_shadow_address(
199205
#endif
200206
}
201207

208+
/// Generic logging function that will log depending on the configured
209+
/// verbosity. Will log a specific message given to it, along with an expression
210+
/// passed along to it.
202211
void log_cond(
203212
const namespacet &ns,
204213
const messaget &log,
@@ -294,7 +303,9 @@ bool contains_null_or_invalid(
294303
return false;
295304
}
296305

297-
// TODO: doxygen?
306+
/// Casts a given (float) bitvector expression to an unsigned bitvector.
307+
/// \param value The expression that we are to conditionally cast.
308+
/// \return An unsigned bitvector expression if eligible - `id` otherwise.
298309
static exprt conditional_cast_floatbv_to_unsignedbv(const exprt &value)
299310
{
300311
if(value.type().id() != ID_floatbv)
@@ -307,7 +318,13 @@ static exprt conditional_cast_floatbv_to_unsignedbv(const exprt &value)
307318
unsignedbv_typet(to_bitvector_type(value.type()).get_width()));
308319
}
309320

310-
// TODO: doxygen?
321+
/// Extract byte-sized elements from the input bitvector-typed expression value
322+
/// and places them into the array values.
323+
/// \param value the bitvector typed expression to extract the bytes from
324+
/// \param type the type of the expression expr (it must be bitvector)
325+
/// \param field_type the type of the shadow memory
326+
/// \param values the vector where all the extracted bytes of value will be
327+
/// placed.
311328
static void extract_bytes_of_bv(
312329
const exprt &value,
313330
const typet &type,
@@ -327,7 +344,16 @@ static void extract_bytes_of_bv(
327344
}
328345
}
329346

330-
// TODO: doxygen?
347+
/// Extract the components from the input expression value and places them into
348+
/// the array values.
349+
/// \param element the expression to extract the bytes from
350+
/// \param field_type the type of the shadow memory
351+
/// \param ns the namespace within which we're going to perform symbol lookups
352+
/// \param log the message log to which we're going to print debugging messages,
353+
/// if debugging is set
354+
/// \param is_union true if the expression element is part of a union
355+
/// \param values the vector where all the extracted components of element will
356+
/// be placed.
331357
static void extract_bytes_of_expr(
332358
exprt element,
333359
const typet &field_type,
@@ -556,7 +582,6 @@ exprt compute_max_over_bytes(
556582
return max_expr;
557583
}
558584

559-
// TODO: doxygen?
560585
exprt build_if_else_expr(
561586
const std::vector<std::pair<exprt, exprt>> &conds_values)
562587
{
@@ -577,7 +602,12 @@ exprt build_if_else_expr(
577602
return result;
578603
}
579604

580-
// TODO: doxygen?
605+
/// @brief Checks given types (object type and shadow memory field type) for
606+
/// equality. We're inspecting only pointer types here - if the two types
607+
/// given are not pointer types, then we assume it to be vacuously true.
608+
/// @param expr_type The type of the real object.
609+
/// @param shadow_type The type of the shadow memory field's value.
610+
/// @return True if types equal, false otherwise.
581611
static bool
582612
are_types_compatible(const typet &expr_type, const typet &shadow_type)
583613
{
@@ -607,9 +637,9 @@ are_types_compatible(const typet &expr_type, const typet &shadow_type)
607637
return true;
608638
}
609639

610-
// TODO: doxygen?
611-
/// We simplify &string_constant[0] to &string_constant to facilitate expression
640+
/// Simplify &string_constant[0] to &string_constant to facilitate expression
612641
/// equality for exact matching.
642+
/// \note expression expr will be changed.
613643
static void clean_string_constant(exprt &expr)
614644
{
615645
const auto *index_expr = expr_try_dynamic_cast<index_exprt>(expr);
@@ -621,7 +651,10 @@ static void clean_string_constant(exprt &expr)
621651
}
622652
}
623653

624-
// TODO: doxygen?
654+
/// Flattens type of the form `pointer_type(array_type(element_type))` to
655+
/// `pointer_type(element_type)` and `pointer_type(string_constant_type)` to
656+
/// `pointer_type(char)`.
657+
/// \note type `type` will be changed.
625658
static void adjust_array_types(typet &type)
626659
{
627660
auto *pointer_type = type_try_dynamic_cast<pointer_typet>(type);
@@ -641,7 +674,12 @@ static void adjust_array_types(typet &type)
641674
}
642675
}
643676

644-
// TODO: doxygen?
677+
/// Function that compares the two arguments shadowed_address and
678+
/// matched_base_address, simplifies the comparison expression and if the lhs
679+
/// and rhs are structurally identical returns true, otherwise returns the
680+
/// comparison.
681+
/// \return the comparison expression of shadowed_address and
682+
/// matched_base_address (or a true_exprt if identical modulo simplification).
645683
static exprt get_matched_base_cond(
646684
const exprt &shadowed_address,
647685
const exprt &matched_base_address,
@@ -676,7 +714,11 @@ static exprt get_matched_base_cond(
676714
return base_cond;
677715
}
678716

679-
// TODO: doxygen?
717+
/// Function that compares the two arguments dereference_pointer and expr,
718+
/// simplifies the comparison expression and if the lhs and rhs are structurally
719+
/// identical returns true, otherwise returns the comparison.
720+
/// \return the comparison expression of dereference_pointer and expr (or a
721+
/// true_exprt if identical modulo simplification).
680722
static exprt get_matched_expr_cond(
681723
const exprt &dereference_pointer,
682724
const exprt &expr,
@@ -738,7 +780,6 @@ static value_set_dereferencet::valuet get_shadow_dereference(
738780
return shadow_dereference;
739781
}
740782

741-
// TODO: doxygen?
742783
/* foreach shadowed_address in SM:
743784
* if(incompatible(shadow.object, object)) continue; // Type incompatibility
744785
* base_match = object == shadow_object; // Do the base obj match the SM obj
@@ -886,7 +927,6 @@ std::vector<std::pair<exprt, exprt>> get_shadow_dereference_candidates(
886927
return result;
887928
}
888929

889-
// TODO: doxygen?
890930
// Unfortunately.
891931
static object_descriptor_exprt
892932
normalize(const object_descriptor_exprt &expr, const namespacet &ns)

src/goto-symex/shadow_memory_util.h

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ irep_idt extract_field_name(const exprt &string_expr);
3939
/// \param type The followed type of expr.
4040
void clean_pointer_expr(exprt &expr, const typet &type);
4141

42-
/// Converts a given expression into a dereference_exprt.
42+
/// Wraps a given expression into a `dereference_exprt` unless it is an
43+
/// `address_of_exprt` in which case it just unboxes it and returns its content.
4344
exprt deref_expr(const exprt &expr);
4445

4546
/// Logs setting a value to a given shadow field. Mainly for use for
@@ -51,8 +52,8 @@ void log_set_field(
5152
const exprt &expr,
5253
const exprt &value);
5354

54-
/// Logs setting a value to a given shadow field. Mainly for use for
55-
/// debugging purposes.
55+
/// Logs getting a value corresponding to a shadow memory field. Mainly for
56+
/// use for debugging purposes.
5657
void log_get_field(
5758
const namespacet &ns,
5859
const messaget &log,
@@ -85,7 +86,9 @@ void log_value_set_match(
8586
const exprt &address,
8687
const exprt &expr);
8788

88-
// TODO: doxygen
89+
/// Log trying out a match between an object and a (target) shadow address.
90+
/// @param shadowed_address The address for which we're currently attempting to
91+
/// match.
8992
void log_try_shadow_address(
9093
const namespacet &ns,
9194
const messaget &log,
@@ -115,7 +118,11 @@ void replace_invalid_object_by_null(exprt &expr);
115118
const exprt &
116119
get_field_init_expr(const irep_idt &field_name, const goto_symex_statet &state);
117120

118-
// TODO: doxygen?
121+
/// Get a list of `(condition, value)` pairs for a certain pointer from
122+
/// the shadow memory, where each pair denotes the `value` of the pointer
123+
/// expression if the `condition` evaluates to `true`.
124+
/// \return A vector of pair<expr, expr> corresponding to a condition and value.
125+
/// (See above for explanation).
119126
std::vector<std::pair<exprt, exprt>> get_shadow_dereference_candidates(
120127
const namespacet &ns,
121128
const messaget &log,
@@ -126,7 +133,8 @@ std::vector<std::pair<exprt, exprt>> get_shadow_dereference_candidates(
126133
const typet &lhs_type,
127134
bool &exact_match);
128135

129-
/// Retrieves the value of the initialising expression.
136+
/// Retrieves the type of the shadow memory by returning the type of the shadow
137+
/// memory initializer value.
130138
/// \param field_name The name of the field whose value type we want to query.
131139
/// \param state The symex_state within which the query is executed (the field's
132140
/// value is looked up).
@@ -146,8 +154,15 @@ bool contains_null_or_invalid(
146154
const std::vector<exprt> &value_set,
147155
const exprt &address);
148156

149-
/// Performs aggregation of the shadow memory field value over multiple cells
157+
/// Performs aggregation of the shadow memory field value over multiple bytes
150158
/// for fields whose type is _Bool.
159+
/// \param expr the type to compute the or over each of its bytes
160+
/// \param field_type the type of the shadow memory (must be `c_bool` or `bool`)
161+
/// \param ns the namespace within which we're going to perform symbol lookups
162+
/// \param log the message log to which we're going to print debugging messages,
163+
/// if debugging is set
164+
/// \param is_union `true` if the expression expr is part of a union.
165+
/// \return the aggregated `or` byte-sized value contained in expr
151166
exprt compute_or_over_bytes(
152167
const exprt &expr,
153168
const typet &field_type,
@@ -173,11 +188,20 @@ exprt compute_max_over_bytes(
173188
/// used as an antecedent for an if_expr, and `e2` is going to be used
174189
/// as the consequent.
175190
/// \returns An if_exprt of the form `if e1 then e2 else if e3 then e4 else ...`
191+
/// \note the expression created will not have the first condition as the first
192+
/// element will serve fallback if all the other conditions are `false`.
176193
exprt build_if_else_expr(
177194
const std::vector<std::pair<exprt, exprt>> &conds_values);
178195

179-
/// Checks if given expression is a null pointer.
180-
/// \returns true if expr is a a NULL pointer within value_set.
196+
/// Checks if value_set contains only a `NULL` pointer expression of the same
197+
/// type of expr.
198+
/// \param ns the namespace within which we're going to perform symbol lookups
199+
/// \param log the message log to which we're going to print debugging messages,
200+
/// if debugging is set
201+
/// \param value_set the collection to check if it contains *only* the `NULL`
202+
/// pointer
203+
/// \param expr a pointer-typed expression
204+
/// \return `true` if value_set contains only a `NULL` pointer expression
181205
bool check_value_set_contains_only_null_ptr(
182206
const namespacet &ns,
183207
const messaget &log,

0 commit comments

Comments
 (0)