Skip to content

Commit b0f2506

Browse files
authored
Merge pull request #3607 from tautschnig/vs-shadow
Avoid shadowing of variables [blocks: #2310]
2 parents ab030e9 + adde39e commit b0f2506

File tree

8 files changed

+48
-54
lines changed

8 files changed

+48
-54
lines changed

jbmc/unit/solvers/refinement/string_constraint_instantiation/instantiate_not_contains.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ SCENARIO("instantiate_not_contains",
191191

192192
// Generating the corresponding axioms and simplifying, recording info
193193
string_constraint_generatort generator(empty_ns);
194-
const auto pair = generator.add_axioms_for_function_application(
195-
generator.fresh_symbol, func);
194+
const auto pair = generator.add_axioms_for_function_application(func);
196195
const string_constraintst &constraints = pair.second;
197196

198197
std::string axioms;

src/solvers/refinement/refine_arrays.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ void bv_refinementt::freeze_lazy_constraints()
119119

120120
for(const auto &constraint : lazy_array_constraints)
121121
{
122-
std::set<symbol_exprt> symbols;
123-
find_symbols(constraint.lazy, symbols);
124-
for(const auto &symbol : symbols)
122+
std::set<symbol_exprt> symbols_in_constraint;
123+
find_symbols(constraint.lazy, symbols_in_constraint);
124+
for(const auto &symbol : symbols_in_constraint)
125125
{
126126
const bvt bv=convert_bv(symbol);
127127
forall_literals(b_it, bv)

src/solvers/refinement/string_builtin_function.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,12 @@ std::vector<mp_integer> string_concatenation_builtin_functiont::eval(
129129
? std::max(std::min(args_value[1], input2_size), start_index)
130130
: input2_size;
131131

132-
std::vector<mp_integer> result(input1_value);
133-
result.insert(
134-
result.end(),
132+
std::vector<mp_integer> eval_result(input1_value);
133+
eval_result.insert(
134+
eval_result.end(),
135135
input2_value.begin() + numeric_cast_v<std::size_t>(start_index),
136136
input2_value.begin() + numeric_cast_v<std::size_t>(end_index));
137-
return result;
137+
return eval_result;
138138
}
139139

140140
string_constraintst string_concatenation_builtin_functiont::constraints(
@@ -458,12 +458,12 @@ std::vector<mp_integer> string_insertion_builtin_functiont::eval(
458458
? std::max(std::min(args_value[2], input2_size), mp_integer(0))
459459
: input2_size;
460460

461-
std::vector<mp_integer> result(input1_value);
462-
result.insert(
463-
result.begin() + numeric_cast_v<std::size_t>(offset),
461+
std::vector<mp_integer> eval_result(input1_value);
462+
eval_result.insert(
463+
eval_result.begin() + numeric_cast_v<std::size_t>(offset),
464464
input2_value.begin() + numeric_cast_v<std::size_t>(start),
465465
input2_value.begin() + numeric_cast_v<std::size_t>(end));
466-
return result;
466+
return eval_result;
467467
}
468468

469469
optionalt<exprt> string_insertion_builtin_functiont::eval(
@@ -634,8 +634,8 @@ string_builtin_function_with_no_evalt::string_builtin_function_with_no_evalt(
634634
string_constraintst string_builtin_function_with_no_evalt::constraints(
635635
string_constraint_generatort &generator) const
636636
{
637-
auto pair = generator.add_axioms_for_function_application(
638-
generator.fresh_symbol, function_application);
637+
auto pair =
638+
generator.add_axioms_for_function_application(function_application);
639639
pair.second.existential.push_back(equal_exprt(pair.first, return_code));
640640
return pair.second;
641641
}

src/solvers/refinement/string_constraint_generator.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ class string_constraint_generatort final
127127
explicit string_constraint_generatort(const namespacet &ns);
128128

129129
std::pair<exprt, string_constraintst> add_axioms_for_function_application(
130-
symbol_generatort &fresh_symbol,
131130
const function_application_exprt &expr);
132131

133132
symbol_generatort fresh_symbol;
@@ -150,7 +149,6 @@ class string_constraint_generatort final
150149
/// string pointers.
151150
/// \deprecated Not tested.
152151
std::pair<symbol_exprt, string_constraintst> add_axioms_for_intern(
153-
symbol_generatort &fresh_symbol,
154152
const function_application_exprt &f);
155153

156154
exprt associate_array_to_pointer(const function_application_exprt &f);
@@ -161,7 +159,6 @@ class string_constraint_generatort final
161159
// The specification is partial: the actual value is not actually computed
162160
// but we ensure that hash codes of equal strings are equal.
163161
std::pair<exprt, string_constraintst> add_axioms_for_hash_code(
164-
symbol_generatort &fresh_symbol,
165162
const function_application_exprt &f,
166163
array_poolt &pool);
167164

src/solvers/refinement/string_constraint_generator_comparison.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,16 @@ std::pair<exprt, string_constraintst> add_axioms_for_equals_ignore_case(
182182
/// These axioms are, for each string `s` on which hash was called:
183183
/// * \f$ hash(str)=hash(s) \lor |str| \ne |s|
184184
/// \lor (|str|=|s| \land \exists i<|s|.\ s[i]\ne str[i]) \f$
185-
/// \param fresh_symbol: generator of fresh symbols
186185
/// \param f: function application with argument refined_string `str`
187186
/// \param pool: pool of arrays representing strings
188187
/// \return integer expression `hash(str)`
189188
std::pair<exprt, string_constraintst>
190189
string_constraint_generatort::add_axioms_for_hash_code(
191-
symbol_generatort &fresh_symbol,
192190
const function_application_exprt &f,
193191
array_poolt &pool)
194192
{
195193
PRECONDITION(f.arguments().size() == 1);
196-
string_constraintst constraints;
194+
string_constraintst hash_constraints;
197195
const array_string_exprt str = get_string_expr(pool, f.arguments()[0]);
198196
const typet &return_type = f.type();
199197
const typet &index_type = str.length().type();
@@ -212,9 +210,9 @@ string_constraint_generatort::add_axioms_for_hash_code(
212210
and_exprt(
213211
notequal_exprt(str[i], it.first[i]),
214212
and_exprt(length_gt(str, i), is_positive(i))));
215-
constraints.existential.push_back(or_exprt(c1, or_exprt(c2, c3)));
213+
hash_constraints.existential.push_back(or_exprt(c1, or_exprt(c2, c3)));
216214
}
217-
return {hash, std::move(constraints)};
215+
return {hash, std::move(hash_constraints)};
218216
}
219217

220218
/// Lexicographic comparison of two strings
@@ -302,17 +300,15 @@ std::pair<exprt, string_constraintst> add_axioms_for_compare_to(
302300
/// Add axioms stating that the return value for two equal string should be the
303301
/// same
304302
/// \deprecated never tested
305-
/// \param fresh_symbol: generator of fresh symbols
306303
/// \param f: function application with one string argument
307304
/// \return a string expression
308305
DEPRECATED("never tested")
309306
std::pair<symbol_exprt, string_constraintst>
310307
string_constraint_generatort::add_axioms_for_intern(
311-
symbol_generatort &fresh_symbol,
312308
const function_application_exprt &f)
313309
{
314310
PRECONDITION(f.arguments().size() == 1);
315-
string_constraintst constraints;
311+
string_constraintst intern_constraints;
316312
const array_string_exprt str = get_string_expr(array_pool, f.arguments()[0]);
317313
// For now we only enforce content equality and not pointer equality
318314
const typet &return_type=f.type();
@@ -330,14 +326,14 @@ string_constraint_generatort::add_axioms_for_intern(
330326
exprt::operandst disj;
331327
for(auto it : intern_of_string)
332328
disj.push_back(equal_exprt(intern, it.second));
333-
constraints.existential.push_back(disjunction(disj));
329+
intern_constraints.existential.push_back(disjunction(disj));
334330

335331
// WARNING: the specification may be incomplete or incorrect
336332
for(auto it : intern_of_string)
337333
if(it.second!=str)
338334
{
339335
symbol_exprt i = fresh_symbol("index_intern", index_type);
340-
constraints.existential.push_back(or_exprt(
336+
intern_constraints.existential.push_back(or_exprt(
341337
equal_exprt(it.second, intern),
342338
or_exprt(
343339
notequal_exprt(str.length(), it.first.length()),
@@ -348,5 +344,5 @@ string_constraint_generatort::add_axioms_for_intern(
348344
and_exprt(length_gt(str, i), is_positive(i)))))));
349345
}
350346

351-
return {intern, std::move(constraints)};
347+
return {intern, std::move(intern_constraints)};
352348
}

src/solvers/refinement/string_constraint_generator_float.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,14 @@ std::pair<exprt, string_constraintst> add_axioms_for_fractional_part(
337337
/// \todo For now we only consider single precision.
338338
/// \param fresh_symbol: generator of fresh symbols
339339
/// \param res: string expression representing the float in scientific notation
340-
/// \param f: a float expression, which is positive
340+
/// \param float_expr: a float expression, which is positive
341341
/// \param array_pool: pool of arrays representing strings
342342
/// \param ns: namespace
343343
/// \return a integer expression different from 0 to signal an exception
344344
std::pair<exprt, string_constraintst> add_axioms_from_float_scientific_notation(
345345
symbol_generatort &fresh_symbol,
346346
const array_string_exprt &res,
347-
const exprt &f,
347+
const exprt &float_expr,
348348
array_poolt &array_pool,
349349
const namespacet &ns)
350350
{
@@ -359,13 +359,13 @@ std::pair<exprt, string_constraintst> add_axioms_from_float_scientific_notation(
359359
exprt round_to_zero_expr=from_integer(ieee_floatt::ROUND_TO_ZERO, int_type);
360360

361361
// `bin_exponent` is $e$ in the formulas
362-
exprt bin_exponent=get_exponent(f, float_spec);
362+
exprt bin_exponent = get_exponent(float_expr, float_spec);
363363

364364
// $m$ from the formula is a value between 0.0 and 2.0 represented
365365
// with values in the range 0x000000 0xFFFFFF so 1 corresponds to 0x800000.
366366
// `bin_significand_int` represents $m * 0x800000$
367-
exprt bin_significand_int=
368-
get_significand(f, float_spec, unsignedbv_typet(32));
367+
exprt bin_significand_int =
368+
get_significand(float_expr, float_spec, unsignedbv_typet(32));
369369
// `bin_significand` represents $m$ and is obtained
370370
// by multiplying `binary_significand_as_int` by
371371
// 1/0x800000 = 2^-23 = 1.1920928955078125 * 10^-7
@@ -375,7 +375,8 @@ std::pair<exprt, string_constraintst> add_axioms_from_float_scientific_notation(
375375

376376
// This is a first approximation of the exponent that will adjust
377377
// if the fraction we get is greater than 10
378-
exprt dec_exponent_estimate=estimate_decimal_exponent(f, float_spec);
378+
exprt dec_exponent_estimate =
379+
estimate_decimal_exponent(float_expr, float_spec);
379380

380381
// Table for values of $2^x / 10^(floor(log_10(2)*x))$ where x=Range[0,128]
381382
std::vector<double> two_power_e_over_ten_power_d_table(
@@ -422,10 +423,12 @@ std::pair<exprt, string_constraintst> add_axioms_from_float_scientific_notation(
422423
int_type);
423424
array_exprt conversion_factor_table(
424425
array_typet(float_type, conversion_factor_table_size));
425-
for(const auto &f : two_power_e_over_ten_power_d_table_negatives)
426-
conversion_factor_table.copy_to_operands(constant_float(f, float_spec));
427-
for(const auto &f : two_power_e_over_ten_power_d_table)
428-
conversion_factor_table.copy_to_operands(constant_float(f, float_spec));
426+
for(const auto &negative : two_power_e_over_ten_power_d_table_negatives)
427+
conversion_factor_table.copy_to_operands(
428+
constant_float(negative, float_spec));
429+
for(const auto &positive : two_power_e_over_ten_power_d_table)
430+
conversion_factor_table.copy_to_operands(
431+
constant_float(positive, float_spec));
429432

430433
// The index in the table, corresponding to exponent e is e+128
431434
plus_exprt shifted_index(bin_exponent, from_integer(128, int_type));
@@ -460,7 +463,7 @@ std::pair<exprt, string_constraintst> add_axioms_from_float_scientific_notation(
460463
minus_exprt fractional_part(
461464
dec_significand, floatbv_of_int_expr(dec_significand_int, float_spec));
462465

463-
// shifted_float is floor(f * 1e5)
466+
// shifted_float is floor(float_expr * 1e5)
464467
exprt shifting=constant_float(1e5, float_spec);
465468
exprt shifted_float=
466469
round_expr_to_zero(floatbv_mult(fractional_part, shifting));
@@ -469,7 +472,7 @@ std::pair<exprt, string_constraintst> add_axioms_from_float_scientific_notation(
469472
// the exponent notation.
470473
exprt max_non_exponent_notation=from_integer(100000, shifted_float.type());
471474

472-
// fractional_part_shifted is floor(f * 100000) % 100000
475+
// fractional_part_shifted is floor(float_expr * 100000) % 100000
473476
const mod_exprt fractional_part_shifted(
474477
shifted_float, max_non_exponent_notation);
475478

src/solvers/refinement/string_constraint_generator_main.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,12 +363,10 @@ optionalt<exprt> string_constraint_generatort::make_array_pointer_association(
363363
/// strings contained in this call are converted to objects of type
364364
/// `string_exprt`, through adding axioms. Axioms are then added to enforce that
365365
/// the result corresponds to the function application.
366-
/// \param fresh_symbol: generator of fresh symbols
367366
/// \param expr: an expression containing a function application
368367
/// \return expression corresponding to the result of the function application
369368
std::pair<exprt, string_constraintst>
370369
string_constraint_generatort::add_axioms_for_function_application(
371-
symbol_generatort &fresh_symbol,
372370
const function_application_exprt &expr)
373371
{
374372
const irep_idt &id = get_function_name(expr);
@@ -396,7 +394,7 @@ string_constraint_generatort::add_axioms_for_function_application(
396394
else if(id==ID_cprover_string_contains_func)
397395
return add_axioms_for_contains(fresh_symbol, expr, array_pool);
398396
else if(id==ID_cprover_string_hash_code_func)
399-
return add_axioms_for_hash_code(fresh_symbol, expr, array_pool);
397+
return add_axioms_for_hash_code(expr, array_pool);
400398
else if(id==ID_cprover_string_index_of_func)
401399
return add_axioms_for_index_of(fresh_symbol, expr, array_pool);
402400
else if(id==ID_cprover_string_last_index_of_func)
@@ -463,7 +461,7 @@ string_constraint_generatort::add_axioms_for_function_application(
463461
else if(id==ID_cprover_string_replace_func)
464462
return add_axioms_for_replace(fresh_symbol, expr, array_pool);
465463
else if(id==ID_cprover_string_intern_func)
466-
return add_axioms_for_intern(fresh_symbol, expr);
464+
return add_axioms_for_intern(expr);
467465
else if(id==ID_cprover_string_format_func)
468466
return add_axioms_for_format(fresh_symbol, expr, array_pool, message, ns);
469467
else if(id == ID_cprover_string_constrain_characters_func)

src/solvers/refinement/string_refinement.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,8 @@ decision_proceduret::resultt string_refinementt::dec_solve()
738738
// Initial try without index set
739739
const auto get = [this](const exprt &expr) { return this->get(expr); };
740740
dependencies.clean_cache();
741-
const decision_proceduret::resultt res=supert::dec_solve();
742-
if(res==resultt::D_SATISFIABLE)
741+
const decision_proceduret::resultt initial_result = supert::dec_solve();
742+
if(initial_result == resultt::D_SATISFIABLE)
743743
{
744744
bool satisfied;
745745
std::vector<exprt> counter_examples;
@@ -762,23 +762,23 @@ decision_proceduret::resultt string_refinementt::dec_solve()
762762
else
763763
{
764764
debug() << "check_SAT: got UNSAT or ERROR" << eom;
765-
return res;
765+
return initial_result;
766766
}
767767

768768
initial_index_set(index_sets, ns, axioms);
769769
update_index_set(index_sets, ns, current_constraints);
770770
current_constraints.clear();
771-
const auto instances =
771+
const auto initial_instances =
772772
generate_instantiations(index_sets, axioms, not_contain_witnesses);
773-
for(const auto &instance : instances)
773+
for(const auto &instance : initial_instances)
774774
add_lemma(instance);
775775

776776
while((loop_bound_--)>0)
777777
{
778778
dependencies.clean_cache();
779-
const decision_proceduret::resultt res=supert::dec_solve();
779+
const decision_proceduret::resultt refined_result = supert::dec_solve();
780780

781-
if(res==resultt::D_SATISFIABLE)
781+
if(refined_result == resultt::D_SATISFIABLE)
782782
{
783783
bool satisfied;
784784
std::vector<exprt> counter_examples;
@@ -833,8 +833,9 @@ decision_proceduret::resultt string_refinementt::dec_solve()
833833
}
834834
else
835835
{
836-
debug() << "check_SAT: default return " << static_cast<int>(res) << eom;
837-
return res;
836+
debug() << "check_SAT: default return "
837+
<< static_cast<int>(refined_result) << eom;
838+
return refined_result;
838839
}
839840
}
840841
debug() << "string_refinementt::dec_solve reached the maximum number"

0 commit comments

Comments
 (0)