Skip to content

Commit 65e28b0

Browse files
codebyzebromainbrenguier
authored andcommitted
Stop preprocessing String.equals
String.equals currently handled by CBMC, this removes support within CBMC so that String.equals will be handled by a model instead. CProverString.equals is provided by JBMC instead of String.equals.
1 parent 3206b3a commit 65e28b0

File tree

2 files changed

+0
-81
lines changed

2 files changed

+0
-81
lines changed

jbmc/src/java_bytecode/java_string_library_preprocess.cpp

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -939,72 +939,6 @@ java_string_library_preprocesst::string_literal_to_string_expr(
939939
ID_cprover_string_literal_func, {expr}, loc, symbol_table, code);
940940
}
941941

942-
/// Used to provide code for the Java String.equals(Object) function.
943-
/// \param type: type of the function call
944-
/// \param loc: location in the program_invocation_name
945-
/// \param symbol_table: symbol table
946-
/// \param function_id: unused
947-
/// \return Code corresponding to:
948-
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
949-
/// IF arg->@class_identifier == "java.lang.String"
950-
/// THEN
951-
/// string_expr1 = {this->length; *this->data}
952-
/// string_expr2 = {arg->length; *arg->data}
953-
/// bool string_equals_tmp = cprover_string_equal(string_expr1, string_expr2)
954-
/// return string_equals_tmp
955-
/// ELSE
956-
/// return false
957-
/// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
958-
codet java_string_library_preprocesst::make_equals_function_code(
959-
const java_method_typet &type,
960-
const source_locationt &loc,
961-
const irep_idt &function_id,
962-
symbol_table_baset &symbol_table)
963-
{
964-
const typet &return_type = type.return_type();
965-
exprt::operandst ops;
966-
for(const auto &p : type.parameters())
967-
{
968-
symbol_exprt sym(p.get_identifier(), p.type());
969-
ops.push_back(sym);
970-
}
971-
972-
code_ifthenelset code;
973-
code.cond() = [&] {
974-
const member_exprt class_identifier(
975-
checked_dereference(ops[1], ops[1].type().subtype()),
976-
"@class_identifier",
977-
string_typet());
978-
return equal_exprt(
979-
class_identifier,
980-
constant_exprt("java::java.lang.String", string_typet()));
981-
}();
982-
983-
code.then_case() = [&] {
984-
code_blockt instance_case;
985-
// Check content equality
986-
const symbolt string_equals_sym = get_fresh_aux_symbol(
987-
return_type,
988-
id2string(function_id),
989-
"str_eq",
990-
loc,
991-
ID_java,
992-
symbol_table);
993-
const symbol_exprt string_equals = string_equals_sym.symbol_expr();
994-
instance_case.add(code_declt(string_equals), loc);
995-
const exprt::operandst args =
996-
process_equals_function_operands(ops, loc, symbol_table, instance_case);
997-
const auto fun_app = make_function_application(
998-
ID_cprover_string_equal_func, args, return_type, symbol_table);
999-
instance_case.add(code_assignt(string_equals, fun_app), loc);
1000-
instance_case.add(code_returnt(string_equals), loc);
1001-
return instance_case;
1002-
}();
1003-
1004-
code.else_case() = code_returnt(from_integer(false, return_type));
1005-
return code;
1006-
}
1007-
1008942
/// Provide code for the String.valueOf(F) function.
1009943
/// \param type: type of the function call
1010944
/// \param loc: location in the program_invocation_name
@@ -2028,15 +1962,6 @@ void java_string_library_preprocesst::initialize_conversion_table()
20281962
cprover_equivalent_to_java_function
20291963
["java::java.lang.String.endsWith:(Ljava/lang/String;)Z"]=
20301964
ID_cprover_string_endswith_func;
2031-
2032-
conversion_table["java::java.lang.String.equals:(Ljava/lang/Object;)Z"] =
2033-
std::bind(
2034-
&java_string_library_preprocesst::make_equals_function_code,
2035-
this,
2036-
std::placeholders::_1,
2037-
std::placeholders::_2,
2038-
std::placeholders::_3,
2039-
std::placeholders::_4);
20401965
cprover_equivalent_to_java_function
20411966
["java::java.lang.String.equalsIgnoreCase:(Ljava/lang/String;)Z"]=
20421967
ID_cprover_string_equals_ignore_case_func;

jbmc/src/java_bytecode/java_string_library_preprocess.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,6 @@ class java_string_library_preprocesst:public messaget
145145
// A set tells us what java types should be considered as string objects
146146
std::unordered_set<irep_idt> string_types;
147147

148-
codet make_equals_function_code(
149-
const java_method_typet &type,
150-
const source_locationt &loc,
151-
const irep_idt &function_id,
152-
symbol_table_baset &symbol_table);
153-
154148
codet make_float_to_string_code(
155149
const java_method_typet &type,
156150
const source_locationt &loc,

0 commit comments

Comments
 (0)