Skip to content

Commit 2e7f785

Browse files
Merge pull request diffblue#1895 from romainbrenguier/dependency-graph#TG-2582
Computation of dependency graph for strings [TG-2605]
2 parents 86b3e87 + 123541f commit 2e7f785

18 files changed

+1221
-343
lines changed
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CORE
22
MemberTest.class
3-
--refine-strings --verbosity 10 --string-max-length 29 --java-assume-inputs-non-null --function MemberTest.main
4-
^EXIT=0$
3+
--refine-strings --verbosity 10 --string-max-length 45 --string-max-input-length 31 --function MemberTest.main
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
6+
^VERIFICATION FAILED$
77
--
88
non equal types
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
public class MemberTest {
22
String foo;
3+
34
public void main() {
4-
// Causes this function to be ignored if string-max-length is
5-
// less than 40
5+
if (foo == null)
6+
return;
7+
8+
// This would prevent anything from happening if we were to add a
9+
// constraints on strings being smaller than 40
610
String t = new String("0123456789012345678901234567890123456789");
7-
assert foo != null && foo.length() < 30;
11+
12+
if (foo.length() >= 30)
13+
// This should not happen when string-max-input length is smaller
14+
// than 30
15+
assert false;
816
}
917
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
MemberTest.class
3+
--refine-strings --verbosity 10 --string-max-length 45 --string-max-input-length 20 --function MemberTest.main
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
non equal types
Binary file not shown.

regression/strings-smoke-tests/max_input_length/Test.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
public class Test {
22
public static void main(String s) {
3-
// This prevent anything from happening if string-max-length is smaller
4-
// than 40
5-
String t = new String("0123456789012345678901234567890123456789");
3+
// This prevent anything from happening if we were to add a constraints on strings
4+
// being smaller than 40
5+
String t = new String("0123456789012345678901234567890123456789");
66
if (s.length() >= 30)
77
// This should not happen when string-max-input length is smaller
88
// than 30

regression/strings-smoke-tests/max_input_length/test.desc

-8
This file was deleted.

src/solvers/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ SRC = $(BOOLEFORCE_SRC) \
179179
refinement/refine_arithmetic.cpp \
180180
refinement/refine_arrays.cpp \
181181
refinement/string_refinement.cpp \
182+
refinement/string_refinement_util.cpp \
182183
refinement/string_constraint_generator_code_points.cpp \
183184
refinement/string_constraint_generator_comparison.cpp \
184185
refinement/string_constraint_generator_concat.cpp \

src/solvers/refinement/string_constraint_generator.h

+66-20
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,62 @@ Author: Romain Brenguier, [email protected]
2727
#include <util/constexpr.def>
2828
#include <solvers/refinement/string_constraint.h>
2929

30+
/// Generation of fresh symbols of a given type
31+
class symbol_generatort final
32+
{
33+
public:
34+
symbol_exprt
35+
operator()(const irep_idt &prefix, const typet &type = bool_typet());
36+
37+
private:
38+
unsigned symbol_count = 0;
39+
};
40+
41+
/// Correspondance between arrays and pointers string representations
42+
class array_poolt final
43+
{
44+
public:
45+
explicit array_poolt(symbol_generatort &symbol_generator)
46+
: fresh_symbol(symbol_generator)
47+
{
48+
}
49+
50+
const std::unordered_map<exprt, array_string_exprt, irep_hash> &
51+
get_arrays_of_pointers() const
52+
{
53+
return arrays_of_pointers;
54+
}
55+
56+
exprt get_length(const array_string_exprt &s) const;
57+
58+
void insert(const exprt &pointer_expr, array_string_exprt &array);
59+
60+
array_string_exprt find(const exprt &pointer, const exprt &length);
61+
62+
array_string_exprt find(const refined_string_exprt &str);
63+
64+
/// Converts a struct containing a length and pointer to an array.
65+
/// This allows to get a string expression from arguments of a string
66+
/// builtion function, because string arguments in these function calls
67+
/// are given as a struct containing a length and pointer to an array.
68+
array_string_exprt of_argument(const exprt &arg);
69+
70+
private:
71+
// associate arrays to char pointers
72+
std::unordered_map<exprt, array_string_exprt, irep_hash> arrays_of_pointers;
73+
74+
// associate length to arrays of infinite size
75+
std::unordered_map<array_string_exprt, symbol_exprt, irep_hash>
76+
length_of_array;
77+
78+
// generates fresh symbols
79+
symbol_generatort &fresh_symbol;
80+
81+
array_string_exprt make_char_array_for_char_pointer(
82+
const exprt &char_pointer,
83+
const typet &char_array_type);
84+
};
85+
3086
class string_constraint_generatort final
3187
{
3288
public:
@@ -69,22 +125,22 @@ class string_constraint_generatort final
69125
return index_exprt(witness.at(c), univ_val);
70126
}
71127

72-
symbol_exprt fresh_symbol(
73-
const irep_idt &prefix, const typet &type=bool_typet());
74-
symbol_exprt fresh_univ_index(const irep_idt &prefix, const typet &type);
75-
76-
77128
exprt add_axioms_for_function_application(
78129
const function_application_exprt &expr);
79130

131+
symbol_generatort fresh_symbol;
132+
133+
symbol_exprt fresh_univ_index(const irep_idt &prefix, const typet &type);
134+
80135
symbol_exprt fresh_exist_index(const irep_idt &prefix, const typet &type);
81136

82-
const std::map<exprt, array_string_exprt> &get_arrays_of_pointers() const
83-
{
84-
return arrays_of_pointers_;
85-
}
137+
array_poolt array_pool;
86138

87-
exprt get_length_of_string_array(const array_string_exprt &s) const;
139+
/// Associate array to pointer, and array to length
140+
/// \return an expression if the given function application is one of
141+
/// associate pointer and associate length
142+
optionalt<exprt>
143+
make_array_pointer_association(const function_application_exprt &expr);
88144

89145
// Type used by primitives to signal errors
90146
const signedbv_typet get_return_code_type()
@@ -99,9 +155,6 @@ class string_constraint_generatort final
99155
array_string_exprt get_string_expr(const exprt &expr);
100156
plus_exprt plus_exprt_with_overflow_check(const exprt &op1, const exprt &op2);
101157

102-
array_string_exprt associate_char_array_to_char_pointer(
103-
const exprt &char_pointer,
104-
const typet &char_array_type);
105158

106159
static constant_exprt constant_char(int i, const typet &char_type);
107160

@@ -349,7 +402,6 @@ class string_constraint_generatort final
349402
std::map<string_not_contains_constraintt, symbol_exprt> witness;
350403
private:
351404
std::set<array_string_exprt> created_strings;
352-
unsigned symbol_count=0;
353405
const messaget message;
354406

355407
std::vector<exprt> lemmas;
@@ -364,12 +416,6 @@ class string_constraint_generatort final
364416

365417
// Pool used for the intern method
366418
std::map<array_string_exprt, symbol_exprt> intern_of_string;
367-
368-
// associate arrays to char pointers
369-
std::map<exprt, array_string_exprt> arrays_of_pointers_;
370-
371-
// associate length to arrays of infinite size
372-
std::map<array_string_exprt, symbol_exprt> length_of_array_;
373419
};
374420

375421
exprt is_digit_with_radix(

0 commit comments

Comments
 (0)