Skip to content

Commit 2a8ea0f

Browse files
Better specify out-of-bounds case for set_char
1 parent 9415a24 commit 2a8ea0f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/solvers/refinement/string_constraint_generator_transformation.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,12 +398,13 @@ exprt string_constraint_generatort::add_axioms_for_char_set(
398398

399399
/// Add axioms ensuring that the result `res` is similar to input string `str`
400400
/// where the character at index `pos` is set to `char`.
401+
/// If `pos` is out of bounds the string returned unchanged.
401402
///
402403
/// These axioms are:
403-
/// 1. \f$ |{\tt res}| = |{\tt str}|\f$
404-
/// 2. \f$ {\tt res}[{\tt pos}]={\tt char}\f$
405-
/// 3. \f$ \forall i < min(|{\tt res}|, pos). {\tt res}[i] = {\tt str}[i]\f$
406-
/// 4. \f$ \forall pos+1 <= i < |{\tt res}|.\ {\tt res}[i] = {\tt str}[i]\f$
404+
/// 1. res.length = str.length
405+
/// 2. 0 <= pos < res.length ==> res[pos]=char
406+
/// 3. forall i < min(res.length, pos). res[i] = str[i]
407+
/// 4. forall pos+1 <= i < res.length. res[i] = str[i]
407408
/// \return an integer expression which is `1` when `pos` is out of bounds and
408409
/// `0` otherwise
409410
exprt string_constraint_generatort::add_axioms_for_set_char(
@@ -414,7 +415,13 @@ exprt string_constraint_generatort::add_axioms_for_set_char(
414415
{
415416
const binary_relation_exprt out_of_bounds(position, ID_ge, str.length());
416417
lemmas.push_back(equal_exprt(res.length(), str.length()));
417-
lemmas.push_back(equal_exprt(res[position], character));
418+
lemmas.push_back(
419+
implies_exprt(
420+
and_exprt(
421+
binary_relation_exprt(
422+
from_integer(0, position.type()), ID_le, position),
423+
binary_relation_exprt(position, ID_lt, res.length())),
424+
equal_exprt(res[position], character)));
418425
constraints.push_back([&] {
419426
const symbol_exprt q = fresh_univ_index("QA_char_set", position.type());
420427
const equal_exprt a3_body(res[q], str[q]);

0 commit comments

Comments
 (0)