Skip to content

Commit d959354

Browse files
Remove use of make_string_length_code
This code was directly accessing the length field of the object instead of calling a builtin_function. This meant the solver was unaware of some code accessing the length of a string and could lead to inconsistencies when the solver decides not to add the constraints specific to this string.
1 parent 3687790 commit d959354

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

src/java_bytecode/java_string_library_preprocess.cpp

+6-38
Original file line numberDiff line numberDiff line change
@@ -1776,28 +1776,6 @@ codet java_string_library_preprocesst::make_init_from_array_code(
17761776
return code;
17771777
}
17781778

1779-
/// Generates code for the String.length method
1780-
/// \param type: type of the function
1781-
/// \param loc: location in the source
1782-
/// \param symbol_table: symbol table
1783-
/// \return Code corresponding to:
1784-
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1785-
/// str_expr = java_string_to_string_expr(this)
1786-
/// str_expr_sym = str_expr
1787-
/// return this->length
1788-
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1789-
codet java_string_library_preprocesst::make_string_length_code(
1790-
const code_typet &type,
1791-
const source_locationt &loc,
1792-
symbol_table_baset &symbol_table)
1793-
{
1794-
code_typet::parameterst params=type.parameters();
1795-
symbol_exprt arg_this(params[0].get_identifier(), params[0].type());
1796-
dereference_exprt deref=
1797-
checked_dereference(arg_this, arg_this.type().subtype());
1798-
return code_returnt(get_length(deref, symbol_table));
1799-
}
1800-
18011779
bool java_string_library_preprocesst::implements_function(
18021780
const irep_idt &function_id) const
18031781
{
@@ -2018,14 +1996,9 @@ void java_string_library_preprocesst::initialize_conversion_table()
20181996
cprover_equivalent_to_java_function
20191997
["java::java.lang.String.lastIndexOf:(Ljava/lang/String;I)I"]=
20201998
ID_cprover_string_last_index_of_func;
2021-
conversion_table
1999+
cprover_equivalent_to_java_function
20222000
["java::java.lang.String.length:()I"]=
2023-
std::bind(
2024-
&java_string_library_preprocesst::make_string_length_code,
2025-
this,
2026-
std::placeholders::_1,
2027-
std::placeholders::_2,
2028-
std::placeholders::_3);
2001+
ID_cprover_string_length_func;
20292002
cprover_equivalent_to_java_function
20302003
["java::org.cprover.CProverString.offsetByCodePoints:(Ljava/lang/"
20312004
"String;II)I"] = ID_cprover_string_offset_by_code_point_func;
@@ -2178,14 +2151,9 @@ void java_string_library_preprocesst::initialize_conversion_table()
21782151
cprover_equivalent_to_java_assign_and_return_function
21792152
["java::org.cprover.CProverString.insert:(Ljava/lang/StringBuilder;ILjava/"
21802153
"lang/String;)Ljava/lang/StringBuilder;"] = ID_cprover_string_insert_func;
2181-
conversion_table
2154+
cprover_equivalent_to_java_function
21822155
["java::java.lang.StringBuilder.length:()I"]=
2183-
std::bind(
2184-
&java_string_library_preprocesst::make_string_length_code,
2185-
this,
2186-
std::placeholders::_1,
2187-
std::placeholders::_2,
2188-
std::placeholders::_3);
2156+
ID_cprover_string_length_func;
21892157
cprover_equivalent_to_java_assign_function
21902158
["java::java.lang.StringBuilder.setCharAt:(IC)V"]=
21912159
ID_cprover_string_char_set_func;
@@ -2283,9 +2251,9 @@ void java_string_library_preprocesst::initialize_conversion_table()
22832251
cprover_equivalent_to_java_assign_and_return_function
22842252
["java::org.cprover.CProverString.insert:(Ljava/lang/StringBuffer;IZ)Ljava/"
22852253
"lang/StringBuffer;"] = ID_cprover_string_insert_bool_func;
2286-
conversion_table
2254+
cprover_equivalent_to_java_function
22872255
["java::java.lang.StringBuffer.length:()I"]=
2288-
conversion_table["java::java.lang.String.length:()I"];
2256+
ID_cprover_string_length_func;
22892257
cprover_equivalent_to_java_assign_function
22902258
["java::org.cprover.CProverString.setCharAt:(Ljava/lang/String;IC)V"] =
22912259
ID_cprover_string_char_set_func;

src/java_bytecode/java_string_library_preprocess.h

-5
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,6 @@ class java_string_library_preprocesst:public messaget
175175
const source_locationt &loc,
176176
symbol_table_baset &symbol_table);
177177

178-
codet make_string_length_code(
179-
const code_typet &type,
180-
const source_locationt &loc,
181-
symbol_table_baset &symbol_table);
182-
183178
codet make_object_get_class_code(
184179
const code_typet &type,
185180
const source_locationt &loc,

0 commit comments

Comments
 (0)