Skip to content

Commit 7293aca

Browse files
Merge pull request #4554 from romainbrenguier/clean-up/string-intern
Remove cprover_string_intern handling in the solver
2 parents d6eae52 + 524c13f commit 7293aca

11 files changed

+33
-77
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
CORE
22
test_intern.class
3-
--max-nondet-string-length 1000 --function test_intern.main
3+
--max-nondet-string-length 1000 --function test_intern.testPass --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --unwind 10
44
^EXIT=0$
55
^SIGNAL=0$
6-
^\[.*assertion.1\].* line 9.* SUCCESS$
6+
^\[.*assertion.1\].* line 12.* SUCCESS$
77
--
88
non equal types
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
test_intern.class
3+
--max-nondet-string-length 1000 --function test_intern.testFail --cp `../../../../scripts/format_classpath.sh . ../../../lib/java-models-library/target/core-models.jar` --unwind 10
4+
^EXIT=10$
5+
^SIGNAL=0$
6+
^\[.*assertion.1\].* line 24.* FAILURE$
7+
--
8+
non equal types
Binary file not shown.
Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
public class test_intern
22
{
3-
public static void main()
4-
{
5-
String s1 = "abc";
6-
String s3 = "abc";
7-
String x = s1.intern();
8-
String y = s3.intern();
9-
assert(x == y);
3+
public static void testPass()
4+
{
5+
// Arrange
6+
String s1 = "abc";
7+
String s2 = "abc";
8+
// Act
9+
String x = s1.intern();
10+
String y = s2.intern();
11+
// Assert
12+
assert(x == y);
13+
}
14+
15+
public static void testFail()
16+
{
17+
// Arrange
18+
String s1 = "abc";
19+
String s2 = "abd";
20+
// Act
21+
String x = s1.intern();
22+
String y = s2.intern();
23+
// Assert
24+
assert(x == y);
1025
}
1126
}

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,9 +1532,6 @@ void java_string_library_preprocesst::initialize_conversion_table()
15321532
cprover_equivalent_to_java_function
15331533
["java::java.lang.String.indexOf:(Ljava/lang/String;I)I"]=
15341534
ID_cprover_string_index_of_func;
1535-
cprover_equivalent_to_java_function
1536-
["java::java.lang.String.intern:()Ljava/lang/String;"]=
1537-
ID_cprover_string_intern_func;
15381535
cprover_equivalent_to_java_function
15391536
["java::java.lang.String.isEmpty:()Z"]=
15401537
ID_cprover_string_is_empty_func;

src/solvers/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,6 @@ allocates a new string before calling a primitive.
518518
Pointer to char array association
519519
is now handled by `string_constraint_generatort`, there is no need for
520520
explicit conversion.
521-
* `cprover_string_intern` : Never tested.
522521
* `cprover_string_is_empty` :
523522
Should use `cprover_string_length(s) == 0` instead.
524523
* `cprover_string_is_suffix` : Should use `cprover_string_is_prefix` with an

src/solvers/strings/string_constraint_generator.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@ class string_constraint_generatort final
7171
make_array_pointer_association(const function_application_exprt &expr);
7272

7373
private:
74-
/// Add axioms corresponding to the String.intern java function
75-
/// \todo This does not work at the moment because of the way we treat
76-
/// string pointers.
77-
/// \deprecated Not tested.
78-
std::pair<symbol_exprt, string_constraintst>
79-
add_axioms_for_intern(const function_application_exprt &f);
80-
8174
exprt associate_array_to_pointer(const function_application_exprt &f);
8275

8376
exprt associate_length_to_array(const function_application_exprt &f);
@@ -95,9 +88,6 @@ class string_constraint_generatort final
9588
// To each string on which hash_code was called we associate a symbol
9689
// representing the return value of the hash_code function.
9790
std::map<array_string_exprt, exprt> hash_code_of_string;
98-
99-
// Pool used for the intern method
100-
std::map<array_string_exprt, symbol_exprt> intern_of_string;
10191
};
10292

10393
// Type used by primitives to signal errors

src/solvers/strings/string_constraint_generator_comparison.cpp

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -297,53 +297,3 @@ std::pair<exprt, string_constraintst> add_axioms_for_compare_to(
297297

298298
return {res, std::move(constraints)};
299299
}
300-
301-
/// Add axioms stating that the return value for two equal string should be the
302-
/// same
303-
/// \deprecated never tested
304-
/// \param f: function application with one string argument
305-
/// \return a string expression
306-
DEPRECATED(SINCE(2017, 10, 5, "never tested"))
307-
std::pair<symbol_exprt, string_constraintst>
308-
string_constraint_generatort::add_axioms_for_intern(
309-
const function_application_exprt &f)
310-
{
311-
PRECONDITION(f.arguments().size() == 1);
312-
string_constraintst intern_constraints;
313-
const array_string_exprt str = get_string_expr(array_pool, f.arguments()[0]);
314-
// For now we only enforce content equality and not pointer equality
315-
const typet &return_type = f.type();
316-
const typet index_type = str.length().type();
317-
318-
auto pair = intern_of_string.insert(
319-
std::make_pair(str, fresh_symbol("pool", return_type)));
320-
const symbol_exprt intern = pair.first->second;
321-
322-
// intern(str)=s_0 || s_1 || ...
323-
// for each string s.
324-
// intern(str)=intern(s) || |str|!=|s|
325-
// || (|str|==|s| &&exists i<|s|. s[i]!=str[i])
326-
327-
exprt::operandst disj;
328-
for(auto it : intern_of_string)
329-
disj.push_back(equal_exprt(intern, it.second));
330-
intern_constraints.existential.push_back(disjunction(disj));
331-
332-
// WARNING: the specification may be incomplete or incorrect
333-
for(auto it : intern_of_string)
334-
if(it.second != str)
335-
{
336-
symbol_exprt i = fresh_symbol("index_intern", index_type);
337-
intern_constraints.existential.push_back(or_exprt(
338-
equal_exprt(it.second, intern),
339-
or_exprt(
340-
notequal_exprt(str.length(), it.first.length()),
341-
and_exprt(
342-
equal_exprt(str.length(), it.first.length()),
343-
and_exprt(
344-
notequal_exprt(str[i], it.first[i]),
345-
and_exprt(length_gt(str, i), is_positive(i)))))));
346-
}
347-
348-
return {intern, std::move(intern_constraints)};
349-
}

src/solvers/strings/string_constraint_generator_main.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,6 @@ string_constraint_generatort::add_axioms_for_function_application(
307307
return add_axioms_for_delete_char_at(fresh_symbol, expr, array_pool);
308308
else if(id == ID_cprover_string_replace_func)
309309
return add_axioms_for_replace(fresh_symbol, expr, array_pool);
310-
else if(id == ID_cprover_string_intern_func)
311-
return add_axioms_for_intern(expr);
312310
else if(id == ID_cprover_string_format_func)
313311
return add_axioms_for_format(fresh_symbol, expr, array_pool, message, ns);
314312
else if(id == ID_cprover_string_constrain_characters_func)

src/util/irep_ids.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ IREP_ID_ONE(cprover_string_endswith_func)
612612
IREP_ID_ONE(cprover_string_format_func)
613613
IREP_ID_ONE(cprover_string_hash_code_func)
614614
IREP_ID_ONE(cprover_string_index_of_func)
615-
IREP_ID_ONE(cprover_string_intern_func)
616615
IREP_ID_ONE(cprover_string_insert_func)
617616
IREP_ID_ONE(cprover_string_insert_int_func)
618617
IREP_ID_ONE(cprover_string_insert_long_func)

0 commit comments

Comments
 (0)