Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct types of format argument allocation #1206

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions regression/strings-smoke-tests/java_format/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ test.class
^\[.*assertion.1\].* line 6.* SUCCESS$
^\[.*assertion.2\].* line 7.* FAILURE$
--
^ignoring
12 changes: 0 additions & 12 deletions regression/strings-smoke-tests/java_format/test_warning.desc

This file was deleted.

1 change: 1 addition & 0 deletions regression/strings-smoke-tests/java_format2/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ test.class
^\[.*assertion.1\].* line 6.* SUCCESS$
^\[.*assertion.2\].* line 7.* FAILURE$
--
^warning
13 changes: 0 additions & 13 deletions regression/strings-smoke-tests/java_format2/test_warning.desc

This file was deleted.

1 change: 1 addition & 0 deletions regression/strings-smoke-tests/java_format3/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ test.class
^\[.*assertion.1\].* line 7.* SUCCESS$
^\[.*assertion.2\].* line 9.* FAILURE$
--
^warning
13 changes: 0 additions & 13 deletions regression/strings-smoke-tests/java_format3/test_warning.desc

This file was deleted.

21 changes: 7 additions & 14 deletions src/java_bytecode/java_object_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class java_object_factoryt
/// allocate_object() and also in the library preprocessing for allocating
/// strings.
/// \param target_expr: expression to which the necessary memory will be
/// allocated
/// allocated, its type should be pointer to `allocate_type`
/// \param allocate_type: type of the object allocated
/// \param symbol_table: symbol table
/// \param loc: location in the source
Expand Down Expand Up @@ -243,32 +243,27 @@ exprt allocate_dynamic_object(
/// and which takes care of creating the associated declarations.
/// \param target_expr: expression to which the necessary memory will be
/// allocated
/// \param allocate_type: type of the object allocated
/// \param symbol_table: symbol table
/// \param loc: location in the source
/// \param output_code: code block to which the necessary code is added
/// \param cast_needed: Boolean flags saying where we need to cast the malloc
/// site
/// \return Expression representing the malloc site allocated.
exprt allocate_dynamic_object_with_decl(
void allocate_dynamic_object_with_decl(
const exprt &target_expr,
const typet &allocate_type,
symbol_tablet &symbol_table,
const source_locationt &loc,
code_blockt &output_code,
bool cast_needed)
code_blockt &output_code)
{
std::vector<const symbolt *> symbols_created;

code_blockt tmp_block;
exprt result=allocate_dynamic_object(
const typet &allocate_type=target_expr.type().subtype();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the only functional change? It's hard to see there is a lot of refactoring in the same commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's right

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separating into two commits would be helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes I will try to do that next time. it just seemed natural to remove the argument made unused by this change in the same commit.

// We will not use the malloc site and can safely ignore it
(void) allocate_dynamic_object(
target_expr,
allocate_type,
symbol_table,
loc,
tmp_block,
symbols_created,
cast_needed);
false);

// Add the following code to output_code for each symbol that's been created:
// <type> <identifier>;
Expand All @@ -281,8 +276,6 @@ exprt allocate_dynamic_object_with_decl(

for(const exprt &code : tmp_block.operands())
output_code.add(to_code(code));

return result;
}

/// Installs a new symbol in the symbol table, pushing the corresponding symbolt
Expand Down
6 changes: 2 additions & 4 deletions src/java_bytecode/java_object_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,10 @@ exprt allocate_dynamic_object(
std::vector<const symbolt *> &symbols_created,
bool cast_needed=false);

exprt allocate_dynamic_object_with_decl(
void allocate_dynamic_object_with_decl(
const exprt &target_expr,
const typet &allocate_type,
symbol_tablet &symbol_table,
const source_locationt &loc,
code_blockt &output_code,
bool cast_needed=false);
code_blockt &output_code);

#endif // CPROVER_JAVA_BYTECODE_JAVA_OBJECT_FACTORY_H
11 changes: 4 additions & 7 deletions src/java_bytecode/java_string_library_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,7 @@ exprt java_string_library_preprocesst::allocate_fresh_string(
{
exprt str=fresh_string(type, loc, symbol_table);
code.add(code_declt(str));
(void) allocate_dynamic_object_with_decl(
str, str.type().subtype(), symbol_table, loc, code, false);
allocate_dynamic_object_with_decl(str, symbol_table, loc, code);
return str;
}

Expand All @@ -594,8 +593,7 @@ exprt java_string_library_preprocesst::allocate_fresh_array(
{
exprt array=fresh_array(type, loc, symbol_table);
code.add(code_declt(array));
(void) allocate_dynamic_object_with_decl(
array, array.type().subtype(), symbol_table, loc, code, false);
allocate_dynamic_object_with_decl(array, symbol_table, loc, code);
return array;
}

Expand Down Expand Up @@ -1389,10 +1387,9 @@ exprt java_string_library_preprocesst::make_argument_for_format(
// arg_i = argv[index]
exprt obj=get_object_at_index(argv, index);
symbolt object_symbol=get_fresh_aux_symbol(
obj.type(), "tmp_object", "tmp_object", loc, ID_java, symbol_table);
obj.type(), "tmp_format_obj", "tmp_format_obj", loc, ID_java, symbol_table);
symbol_exprt arg_i=object_symbol.symbol_expr();
(void) allocate_dynamic_object_with_decl(
arg_i, obj.type(), symbol_table, loc, code, false);
allocate_dynamic_object_with_decl(arg_i, symbol_table, loc, code);
code.add(code_assignt(arg_i, obj));
code.add(code_assumet(not_exprt(equal_exprt(
arg_i, null_pointer_exprt(to_pointer_type(arg_i.type()))))));
Expand Down