Skip to content

Commit 4779b25

Browse files
Get rid of calls to plus_exprt_with_overflow
This function is adding assumptions on the values of integers which may lead to contradiction. It is better to deal with overflows at the level of the specification of the builtin functions instead.
1 parent c40b836 commit 4779b25

4 files changed

+31
-39
lines changed

src/solvers/refinement/string_constraint_generator_code_points.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,11 @@ exprt string_constraint_generatort::add_axioms_for_code_point_at(
128128
const symbol_exprt result = fresh_symbol("char", return_type);
129129
const exprt index1 = from_integer(1, str.length().type());
130130
const exprt &char1=str[pos];
131-
const exprt &char2=str[plus_exprt_with_overflow_check(pos, index1)];
131+
const exprt &char2 = str[plus_exprt(pos, index1)];
132132
const typecast_exprt char1_as_int(char1, return_type);
133133
const typecast_exprt char2_as_int(char2, return_type);
134134
const exprt pair = pair_value(char1_as_int, char2_as_int, return_type);
135-
const exprt is_low =
136-
is_low_surrogate(str[plus_exprt_with_overflow_check(pos, index1)]);
135+
const exprt is_low = is_low_surrogate(str[plus_exprt(pos, index1)]);
137136
const and_exprt return_pair(is_high_surrogate(str[pos]), is_low);
138137

139138
lemmas.push_back(implies_exprt(return_pair, equal_exprt(result, pair)));
@@ -210,8 +209,8 @@ exprt string_constraint_generatort::add_axioms_for_offset_by_code_point(
210209
const typet &return_type=f.type();
211210
const symbol_exprt result = fresh_symbol("offset_by_code_point", return_type);
212211

213-
const exprt minimum = plus_exprt_with_overflow_check(index, offset);
214-
const exprt maximum = plus_exprt_with_overflow_check(minimum, offset);
212+
const exprt minimum = plus_exprt(index, offset);
213+
const exprt maximum = plus_exprt(minimum, offset);
215214
lemmas.push_back(binary_relation_exprt(result, ID_le, maximum));
216215
lemmas.push_back(binary_relation_exprt(result, ID_ge, minimum));
217216

src/solvers/refinement/string_constraint_generator_indexof.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of(
352352
lemmas.push_back(a3);
353353

354354
const exprt index1 = from_integer(1, index_type);
355-
const exprt from_index_plus_one =
356-
plus_exprt_with_overflow_check(from_index, index1);
355+
const plus_exprt from_index_plus_one(from_index, index1);
357356
const if_exprt end_index(
358357
binary_relation_exprt(from_index_plus_one, ID_le, str.length()),
359358
from_index_plus_one,

src/solvers/refinement/string_constraint_generator_testing.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ exprt string_constraint_generatort::add_axioms_for_is_prefix(
3636
symbol_exprt isprefix=fresh_boolean("isprefix");
3737
const typet &index_type=str.length().type();
3838

39-
implies_exprt a1(
40-
isprefix,
41-
str.axiom_for_length_ge(plus_exprt_with_overflow_check(
42-
prefix.length(), offset)));
43-
lemmas.push_back(a1);
39+
// Axiom 1.
40+
lemmas.push_back(
41+
implies_exprt(
42+
isprefix, str.axiom_for_length_ge(plus_exprt(prefix.length(), offset))));
4443

4544
symbol_exprt qvar=fresh_univ_index("QA_isprefix", index_type);
4645
string_constraintt a2(

src/solvers/refinement/string_constraint_generator_transformation.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ exprt string_constraint_generatort::add_axioms_for_trim(
175175
const symbol_exprt idx = fresh_exist_index("index_trim", index_type);
176176
const exprt space_char = from_integer(' ', char_type);
177177

178-
exprt a1=str.axiom_for_length_ge(
179-
plus_exprt_with_overflow_check(idx, res.length()));
180-
lemmas.push_back(a1);
178+
// Axiom 1.
179+
lemmas.push_back(str.axiom_for_length_ge(plus_exprt(idx, res.length())));
181180

182181
binary_relation_exprt a2(idx, ID_ge, from_integer(0, index_type));
183182
lemmas.push_back(a2);
@@ -197,32 +196,31 @@ exprt string_constraint_generatort::add_axioms_for_trim(
197196
string_constraintt a6(n, idx, non_print);
198197
constraints.push_back(a6);
199198

200-
symbol_exprt n2=fresh_univ_index("QA_index_trim2", index_type);
201-
minus_exprt bound(str.length(), plus_exprt_with_overflow_check(idx,
202-
res.length()));
203-
binary_relation_exprt eqn2(
204-
str[plus_exprt(idx, plus_exprt(res.length(), n2))],
205-
ID_le,
206-
space_char);
207-
208-
string_constraintt a7(n2, bound, eqn2);
209-
constraints.push_back(a7);
199+
// Axiom 7.
200+
constraints.push_back([&] { // NOLINT
201+
const symbol_exprt n2 = fresh_univ_index("QA_index_trim2", index_type);
202+
const minus_exprt bound(minus_exprt(str.length(), idx), res.length());
203+
const binary_relation_exprt eqn2(
204+
str[plus_exprt(idx, plus_exprt(res.length(), n2))], ID_le, space_char);
205+
return string_constraintt(n2, bound, eqn2);
206+
}());
210207

211208
symbol_exprt n3=fresh_univ_index("QA_index_trim3", index_type);
212209
equal_exprt eqn3(res[n3], str[plus_exprt(n3, idx)]);
213210
string_constraintt a8(n3, res.length(), eqn3);
214211
constraints.push_back(a8);
215212

216-
minus_exprt index_before(
217-
plus_exprt_with_overflow_check(idx, res.length()),
218-
from_integer(1, index_type));
219-
binary_relation_exprt no_space_before(str[index_before], ID_gt, space_char);
220-
or_exprt a9(
221-
equal_exprt(idx, str.length()),
222-
and_exprt(
223-
binary_relation_exprt(str[idx], ID_gt, space_char),
224-
no_space_before));
225-
lemmas.push_back(a9);
213+
// Axiom 9.
214+
lemmas.push_back([&] {
215+
const plus_exprt index_before(
216+
idx, minus_exprt(res.length(), from_integer(1, index_type)));
217+
const binary_relation_exprt no_space_before(
218+
str[index_before], ID_gt, space_char);
219+
return or_exprt(
220+
equal_exprt(idx, str.length()),
221+
and_exprt(
222+
binary_relation_exprt(str[idx], ID_gt, space_char), no_space_before));
223+
}());
226224
return from_integer(0, f.type());
227225
}
228226

@@ -511,10 +509,7 @@ exprt string_constraint_generatort::add_axioms_for_delete_char_at(
511509
const array_string_exprt str = get_string_expr(f.arguments()[2]);
512510
exprt index_one=from_integer(1, str.length().type());
513511
return add_axioms_for_delete(
514-
res,
515-
str,
516-
f.arguments()[3],
517-
plus_exprt_with_overflow_check(f.arguments()[3], index_one));
512+
res, str, f.arguments()[3], plus_exprt(f.arguments()[3], index_one));
518513
}
519514

520515
/// Add axioms stating that `res` corresponds to the input `str`

0 commit comments

Comments
 (0)