Skip to content

Commit 850578b

Browse files
author
Remi Delmas
committed
Adding readable names for CAR instrumentation variables.
1 parent adfd71d commit 850578b

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

regression/contracts/assigns_enforce_free_dead/test.desc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ main.c
2929
^\[foo.\d+\] line \d+ Check that y is assignable: FAILURE$
3030
^\[foo.\d+\] line \d+ Check that z is assignable: FAILURE$
3131
^\[foo.\d+\] line \d+ Check that POINTER_OBJECT\(\(void \*\)z\) is assignable: FAILURE$
32-
^.*tmp_cc\$\d+.*: FAILURE$
32+
^.*__car_valid.*: FAILURE$
33+
^.*__car_lb.*: FAILURE$
34+
^.*__car_ub.*: FAILURE$
3335
--
3436
Checks that invalidated CARs are correctly tracked on `free` and `DEAD`.
3537

@@ -40,4 +42,4 @@ We also check (using positive regex matches above) that
4042
`**p` should be assignable in one case and should not be assignable in the other.
4143

4244
Finally, we check that there should be no "internal" assertion failures
43-
on `tmp_cc` variables used to track CARs.
45+
on `__car_valid`, `__car_ub`, `__car_lb` variables used to track CARs.

src/goto-instrument/contracts/assigns.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ static const slicet normalize_to_slice(const exprt &expr, const namespacet &ns)
5252
}
5353

5454
const symbolt assigns_clauset::conditional_address_ranget::generate_new_symbol(
55+
const std::string &prefix,
5556
const typet &type,
5657
const source_locationt &location) const
5758
{
5859
return new_tmp_symbol(
5960
type,
6061
location,
6162
parent.symbol_table.lookup_ref(parent.function_name).mode,
62-
parent.symbol_table);
63+
parent.symbol_table,
64+
prefix);
6365
}
6466

6567
assigns_clauset::conditional_address_ranget::conditional_address_ranget(
@@ -70,11 +72,13 @@ assigns_clauset::conditional_address_ranget::conditional_address_ranget(
7072
parent(parent),
7173
slice(normalize_to_slice(expr, parent.ns)),
7274
validity_condition_var(
73-
generate_new_symbol(bool_typet(), location).symbol_expr()),
75+
generate_new_symbol("__car_valid", bool_typet(), location).symbol_expr()),
7476
lower_bound_address_var(
75-
generate_new_symbol(slice.first.type(), location).symbol_expr()),
77+
generate_new_symbol("__car_lb", slice.first.type(), location)
78+
.symbol_expr()),
7679
upper_bound_address_var(
77-
generate_new_symbol(slice.first.type(), location).symbol_expr())
80+
generate_new_symbol("__car_ub", slice.first.type(), location)
81+
.symbol_expr())
7882
{
7983
}
8084

src/goto-instrument/contracts/assigns.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ class assigns_clauset
6060
const exprt
6161
generate_unsafe_inclusion_check(const conditional_address_ranget &) const;
6262

63-
const symbolt
64-
generate_new_symbol(const typet &, const source_locationt &) const;
63+
const symbolt generate_new_symbol(
64+
const std::string &prefix,
65+
const typet &,
66+
const source_locationt &) const;
6567

6668
friend class assigns_clauset;
6769
};

src/goto-instrument/contracts/contracts.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -936,9 +936,10 @@ void code_contractst::instrument_call_statement(
936936
const auto object_validity_var_addr =
937937
new_tmp_symbol(
938938
pointer_type(bool_typet{}),
939-
instruction_it->source_location(),
939+
location_no_checks,
940940
symbol_table.lookup_ref(function).mode,
941-
symbol_table)
941+
symbol_table,
942+
"__car_valid")
942943
.symbol_expr();
943944
write_set_validity_addrs.insert(object_validity_var_addr);
944945

src/goto-instrument/contracts/utils.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,18 @@ const symbolt &new_tmp_symbol(
142142
const typet &type,
143143
const source_locationt &location,
144144
const irep_idt &mode,
145-
symbol_table_baset &symtab)
145+
symbol_table_baset &symtab,
146+
std::string suffix,
147+
bool is_auxiliary)
146148
{
147-
return get_fresh_aux_symbol(
149+
symbolt &new_symbol = get_fresh_aux_symbol(
148150
type,
149-
id2string(location.get_function()) + "::tmp_cc",
150-
"tmp_cc",
151+
id2string(location.get_function()) + "::",
152+
suffix,
151153
location,
152154
mode,
153155
symtab);
156+
new_symbol.is_auxiliary = is_auxiliary;
157+
return new_symbol;
158+
}
154159
}

src/goto-instrument/contracts/utils.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,21 @@ void insert_before_swap_and_advance(
105105
goto_programt::targett &target,
106106
goto_programt &payload);
107107

108-
/// \brief Adds a new temporary symbol to the symbol table.
108+
/// \brief Adds a fresh and uniquely named symbol to the symbol table.
109109
///
110110
/// \param type: The type of the new symbol.
111111
/// \param location: The source location for the new symbol.
112112
/// \param mode: The mode for the new symbol, e.g. ID_C, ID_java.
113113
/// \param symtab: The symbol table to which the new symbol is to be added.
114+
/// \param suffix: Suffix to use to generate the unique name
115+
/// \param is_auxiliary: Do not print symbol in traces if true (default = false)
114116
/// \return The new symbolt object.
115117
const symbolt &new_tmp_symbol(
116118
const typet &type,
117119
const source_locationt &location,
118120
const irep_idt &mode,
119-
symbol_table_baset &symtab);
121+
symbol_table_baset &symtab,
122+
std::string suffix = "tmp_cc",
123+
bool is_auxiliary = false);
120124

121125
#endif // CPROVER_GOTO_INSTRUMENT_CONTRACTS_UTILS_H

0 commit comments

Comments
 (0)