Skip to content

Commit deb953c

Browse files
Joel Allredromainbrenguier
Joel Allred
authored andcommitted
Fix add_axioms_for_last_index_of (issue diffblue#77)
Add extra constraints to force the 'contains' variable to a correct value if the substring is actually contained.
1 parent b5656c7 commit deb953c

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

src/solvers/refinement/string_constraint_generator_indexof.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,20 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of_string(
155155
symbol_exprt contains=fresh_boolean("contains_substring");
156156

157157
// We add axioms:
158-
// a1 : contains => |substring| >= length &&offset <= from_index
158+
// a1 : contains => |str|-|substring|>=offset && offset<=from_index
159159
// a2 : !contains => offset=-1
160-
// a3 : forall 0 <= witness<substring.length,
160+
// a3 : forall 0<=witness<|substring|,
161161
// contains => str[witness+offset]=substring[witness]
162+
// a4 : forall n:[offset+1[, |str|-|substring|[.
163+
// contains => (exists m:[0,|substring|[. str[n+m]!=substring[m]])
164+
// a5: forall n:[0,|str|-|substring|[.
165+
// !contains => (exists m:[0,|substring|[. str[n+m]!=substring[m])
162166

163167
implies_exprt a1(
164168
contains,
165169
and_exprt(
166-
str.axiom_for_is_longer_than(
167-
plus_exprt_with_overflow_check(substring.length(), offset)),
170+
str.axiom_for_is_longer_than(plus_exprt_with_overflow_check(
171+
substring.length(), offset)),
168172
binary_relation_exprt(offset, ID_le, from_index)));
169173
axioms.push_back(a1);
170174

@@ -174,10 +178,33 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of_string(
174178
axioms.push_back(a2);
175179

176180
symbol_exprt qvar=fresh_univ_index("QA_index_of_string", index_type);
177-
equal_exprt constr3(str[plus_exprt(qvar, offset)], substring[qvar]);
178-
string_constraintt a3(qvar, substring.length(), contains, constr3);
181+
string_constraintt a3(
182+
qvar,
183+
substring.length(),
184+
contains,
185+
equal_exprt(str[plus_exprt(qvar, offset)], substring[qvar]));
179186
axioms.push_back(a3);
180187

188+
string_not_contains_constraintt a4(
189+
plus_exprt_with_overflow_check(offset, from_integer(1, index_type)),
190+
minus_exprt(str.length(), substring.length()),
191+
contains,
192+
from_integer(0, index_type),
193+
substring.length(),
194+
str,
195+
substring);
196+
axioms.push_back(a4);
197+
198+
string_not_contains_constraintt a5(
199+
from_integer(0, index_type),
200+
minus_exprt(str.length(), substring.length()),
201+
not_exprt(contains),
202+
from_integer(0, index_type),
203+
substring.length(),
204+
str,
205+
substring);
206+
axioms.push_back(a5);
207+
181208
return offset;
182209
}
183210

0 commit comments

Comments
 (0)