Skip to content

Commit e3f9294

Browse files
Get rid of default axioms for strings
These default axioms where too strict and where applied even for strings that may never be creted in the actual program. This could for instance lead to problematic contradiction for a Java object which could be casted either to a string or an int: the axiom added there would apply both on the string and on the integer.
1 parent 91a97a9 commit e3f9294

File tree

2 files changed

+4
-26
lines changed

2 files changed

+4
-26
lines changed

src/solvers/refinement/string_constraint_generator.h

-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ class string_constraint_generatort final
184184
array_string_exprt
185185
char_array_of_pointer(const exprt &pointer, const exprt &length);
186186

187-
void add_default_axioms(const array_string_exprt &s);
188187
exprt axiom_for_is_positive_index(const exprt &x);
189188

190189
void add_constraint_on_characters(

src/solvers/refinement/string_constraint_generator_main.cpp

+4-25
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ array_string_exprt string_constraint_generatort::fresh_string(
172172
symbol_exprt content = fresh_symbol("string_content", array_type);
173173
array_string_exprt str = to_array_string_expr(content);
174174
created_strings.insert(str);
175-
add_default_axioms(str);
176175
return str;
177176
}
178177

@@ -279,7 +278,7 @@ exprt string_constraint_generatort::associate_array_to_pointer(
279278

280279
const exprt &pointer_expr = f.arguments()[1];
281280
array_pool.insert(pointer_expr, array_expr);
282-
add_default_axioms(to_array_string_expr(array_expr));
281+
created_strings.emplace(to_array_string_expr(array_expr));
283282
return from_integer(0, f.type());
284283
}
285284

@@ -319,27 +318,6 @@ void string_constraint_generatort::clear_constraints()
319318
not_contains_constraints.clear();
320319
}
321320

322-
/// adds standard axioms about the length of the string and its content: * its
323-
/// length should be positive * it should not exceed max_string_length * if
324-
/// force_printable_characters is true then all characters should belong to the
325-
/// range of ASCII characters between ' ' and '~'
326-
/// \param s: a string expression
327-
/// \return a string expression that is linked to the argument through axioms
328-
/// that are added to the list
329-
void string_constraint_generatort::add_default_axioms(
330-
const array_string_exprt &s)
331-
{
332-
// If `s` was already added we do nothing.
333-
if(!created_strings.insert(s).second)
334-
return;
335-
336-
const exprt index_zero = from_integer(0, s.length().type());
337-
lemmas.push_back(s.axiom_for_length_ge(index_zero));
338-
339-
if(max_string_length!=std::numeric_limits<size_t>::max())
340-
lemmas.push_back(s.axiom_for_length_le(max_string_length));
341-
}
342-
343321
/// Add constraint on characters of a string.
344322
///
345323
/// This constraint is
@@ -409,13 +387,14 @@ array_string_exprt array_poolt::find(const exprt &pointer, const exprt &length)
409387
}
410388

411389
/// Adds creates a new array if it does not already exists
412-
/// \todo This should be replaced by associate_char_array_to_char_pointer
390+
/// \todo This should be replaced
391+
/// by array_poolt.make_char_array_for_char_pointer
413392
array_string_exprt string_constraint_generatort::char_array_of_pointer(
414393
const exprt &pointer,
415394
const exprt &length)
416395
{
417396
const array_string_exprt array = array_pool.find(pointer, length);
418-
add_default_axioms(array);
397+
created_strings.insert(array);
419398
return array;
420399
}
421400

0 commit comments

Comments
 (0)