Skip to content

Revert "Do lowering of java_new as a function-level pass" #1793

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

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
3 changes: 0 additions & 3 deletions src/clobber/clobber_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Author: Daniel Kroening, [email protected]
#include <goto-programs/link_to_library.h>
#include <goto-programs/goto_inline.h>
#include <goto-programs/xml_goto_trace.h>
#include <goto-programs/remove_java_new.h>

#include <goto-instrument/dump_c.h>

Expand Down Expand Up @@ -214,8 +213,6 @@ bool clobber_parse_optionst::process_goto_program(
goto_modelt &goto_model)
{
{
remove_java_new(goto_model, get_message_handler());

// do partial inlining
status() << "Partial Inlining" << eom;
goto_partial_inline(goto_model, get_message_handler());
Expand Down
3 changes: 0 additions & 3 deletions src/goto-analyzer/goto_analyzer_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Author: Daniel Kroening, [email protected]
#include <goto-programs/read_goto_binary.h>
#include <goto-programs/goto_inline.h>
#include <goto-programs/link_to_library.h>
#include <goto-programs/remove_java_new.h>

#include <analyses/is_threaded.h>
#include <analyses/goto_check.h>
Expand Down Expand Up @@ -745,8 +744,6 @@ bool goto_analyzer_parse_optionst::process_goto_program(
link_to_library(goto_model, ui_message_handler);
#endif

remove_java_new(goto_model, get_message_handler());

// remove function pointers
status() << "Removing function pointers and virtual functions" << eom;
remove_function_pointers(
Expand Down
3 changes: 0 additions & 3 deletions src/goto-diff/goto_diff_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Author: Peter Schrammel
#include <goto-programs/string_instrumentation.h>
#include <goto-programs/loop_ids.h>
#include <goto-programs/link_to_library.h>
#include <goto-programs/remove_java_new.h>

#include <pointer-analysis/add_failed_symbols.h>

Expand Down Expand Up @@ -412,8 +411,6 @@ bool goto_diff_parse_optionst::process_goto_program(
{
namespacet ns(symbol_table);

remove_java_new(goto_model, get_message_handler());

// Remove inline assembler; this needs to happen before
// adding the library.
remove_asm(goto_model);
Expand Down
1 change: 0 additions & 1 deletion src/goto-programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ SRC = basic_blocks.cpp \
remove_exceptions.cpp \
remove_function_pointers.cpp \
remove_instanceof.cpp \
remove_java_new.cpp \
remove_returns.cpp \
remove_skip.cpp \
remove_static_init_loops.cpp \
Expand Down
37 changes: 37 additions & 0 deletions src/goto-programs/builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,43 @@ void goto_convertt::do_cpp_new(
dest.destructive_append(tmp_initializer);
}

void goto_convertt::do_java_new(
const exprt &lhs,
const side_effect_exprt &rhs,
goto_programt &dest)
{
PRECONDITION(!lhs.is_nil());
PRECONDITION(rhs.operands().empty());
PRECONDITION(rhs.type().id() == ID_pointer);
source_locationt location=rhs.source_location();
typet object_type=rhs.type().subtype();

// build size expression
exprt object_size=size_of_expr(object_type, ns);
CHECK_RETURN(object_size.is_not_nil());

// we produce a malloc side-effect, which stays
side_effect_exprt malloc_expr(ID_allocate);
malloc_expr.copy_to_operands(object_size);
// could use true and get rid of the code below
malloc_expr.copy_to_operands(false_exprt());
malloc_expr.type()=rhs.type();

goto_programt::targett t_n=dest.add_instruction(ASSIGN);
t_n->code=code_assignt(lhs, malloc_expr);
t_n->source_location=location;

// zero-initialize the object
dereference_exprt deref(lhs, object_type);
exprt zero_object=
zero_initializer(object_type, location, ns, get_message_handler());
set_class_identifier(
to_struct_expr(zero_object), ns, to_symbol_type(object_type));
goto_programt::targett t_i=dest.add_instruction(ASSIGN);
t_i->code=code_assignt(deref, zero_object);
t_i->source_location=location;
}

void goto_convertt::do_java_new_array(
const exprt &lhs,
const side_effect_exprt &rhs,
Expand Down
5 changes: 4 additions & 1 deletion src/goto-programs/goto_convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,10 @@ void goto_convertt::convert_assign(
else if(rhs.id()==ID_side_effect &&
rhs.get(ID_statement)==ID_java_new)
{
copy(code, ASSIGN, dest);
Forall_operands(it, rhs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can use range based for loop here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to stick with a plain revert there

clean_expr(*it, dest);

do_java_new(lhs, to_side_effect_expr(rhs), dest);
}
else if(rhs.id()==ID_side_effect &&
rhs.get(ID_statement)==ID_java_new_array)
Expand Down
5 changes: 5 additions & 0 deletions src/goto-programs/goto_convert_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ class goto_convertt:public messaget
const side_effect_exprt &rhs,
goto_programt &dest);

void do_java_new(
const exprt &lhs,
const side_effect_exprt &rhs,
goto_programt &dest);

void do_java_new_array(
const exprt &lhs,
const side_effect_exprt &rhs,
Expand Down
105 changes: 0 additions & 105 deletions src/goto-programs/remove_java_new.cpp

This file was deleted.

29 changes: 0 additions & 29 deletions src/goto-programs/remove_java_new.h

This file was deleted.

5 changes: 1 addition & 4 deletions src/jbmc/jbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Author: Daniel Kroening, [email protected]
#include <goto-programs/show_goto_functions.h>
#include <goto-programs/show_symbol_table.h>
#include <goto-programs/show_properties.h>
#include <goto-programs/remove_java_new.h>

#include <goto-symex/adjust_float_expressions.h>

Expand Down Expand Up @@ -735,9 +734,7 @@ bool jbmc_parse_optionst::process_goto_functions(
{
try
{
remove_java_new(goto_model, get_message_handler());

status() << "Removal of virtual functions" << eom;
status() << "Running GOTO functions transformation passes" << eom;
// remove catch and throw (introduces instanceof but request it is removed)
remove_exceptions(
goto_model, remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);
Expand Down
4 changes: 0 additions & 4 deletions unit/pointer-analysis/custom_value_set_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Author: Chris Smowton, [email protected]
#include <langapi/mode.h>
#include <goto-programs/initialize_goto_model.h>
#include <goto-programs/goto_inline.h>
#include <goto-programs/remove_java_new.h>
#include <java_bytecode/java_bytecode_language.h>
#include <java_bytecode/java_types.h>
#include <pointer-analysis/value_set_analysis.h>
Expand Down Expand Up @@ -184,9 +183,6 @@ SCENARIO("test_value_set_analysis",

namespacet ns(goto_model.symbol_table);

// VSA doesn't currently support java_new as an allocator
remove_java_new(goto_model, null_output);

// Fully inline the test program, to avoid VSA conflating
// constructor callsites confusing the results we're trying to check:
goto_function_inline(goto_model, TEST_FUNCTION_NAME, null_output);
Expand Down