Skip to content

Commit e106cf8

Browse files
authored
Merge pull request diffblue#1793 from smowton/smowton/cleanup/remove-java-new-lowering-pass
Revert "Do lowering of java_new as a function-level pass"
2 parents 52dfc36 + 31da890 commit e106cf8

11 files changed

+47
-153
lines changed

src/clobber/clobber_parse_options.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Author: Daniel Kroening, [email protected]
3232
#include <goto-programs/link_to_library.h>
3333
#include <goto-programs/goto_inline.h>
3434
#include <goto-programs/xml_goto_trace.h>
35-
#include <goto-programs/remove_java_new.h>
3635

3736
#include <goto-instrument/dump_c.h>
3837

@@ -214,8 +213,6 @@ bool clobber_parse_optionst::process_goto_program(
214213
goto_modelt &goto_model)
215214
{
216215
{
217-
remove_java_new(goto_model, get_message_handler());
218-
219216
// do partial inlining
220217
status() << "Partial Inlining" << eom;
221218
goto_partial_inline(goto_model, get_message_handler());

src/goto-analyzer/goto_analyzer_parse_options.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Author: Daniel Kroening, [email protected]
3737
#include <goto-programs/read_goto_binary.h>
3838
#include <goto-programs/goto_inline.h>
3939
#include <goto-programs/link_to_library.h>
40-
#include <goto-programs/remove_java_new.h>
4140

4241
#include <analyses/is_threaded.h>
4342
#include <analyses/goto_check.h>
@@ -745,8 +744,6 @@ bool goto_analyzer_parse_optionst::process_goto_program(
745744
link_to_library(goto_model, ui_message_handler);
746745
#endif
747746

748-
remove_java_new(goto_model, get_message_handler());
749-
750747
// remove function pointers
751748
status() << "Removing function pointers and virtual functions" << eom;
752749
remove_function_pointers(

src/goto-diff/goto_diff_parse_options.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Author: Peter Schrammel
3737
#include <goto-programs/string_instrumentation.h>
3838
#include <goto-programs/loop_ids.h>
3939
#include <goto-programs/link_to_library.h>
40-
#include <goto-programs/remove_java_new.h>
4140

4241
#include <pointer-analysis/add_failed_symbols.h>
4342

@@ -412,8 +411,6 @@ bool goto_diff_parse_optionst::process_goto_program(
412411
{
413412
namespacet ns(symbol_table);
414413

415-
remove_java_new(goto_model, get_message_handler());
416-
417414
// Remove inline assembler; this needs to happen before
418415
// adding the library.
419416
remove_asm(goto_model);

src/goto-programs/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ SRC = basic_blocks.cpp \
4545
remove_exceptions.cpp \
4646
remove_function_pointers.cpp \
4747
remove_instanceof.cpp \
48-
remove_java_new.cpp \
4948
remove_returns.cpp \
5049
remove_skip.cpp \
5150
remove_static_init_loops.cpp \

src/goto-programs/builtin_functions.cpp

+37
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,43 @@ void goto_convertt::do_cpp_new(
540540
dest.destructive_append(tmp_initializer);
541541
}
542542

543+
void goto_convertt::do_java_new(
544+
const exprt &lhs,
545+
const side_effect_exprt &rhs,
546+
goto_programt &dest)
547+
{
548+
PRECONDITION(!lhs.is_nil());
549+
PRECONDITION(rhs.operands().empty());
550+
PRECONDITION(rhs.type().id() == ID_pointer);
551+
source_locationt location=rhs.source_location();
552+
typet object_type=rhs.type().subtype();
553+
554+
// build size expression
555+
exprt object_size=size_of_expr(object_type, ns);
556+
CHECK_RETURN(object_size.is_not_nil());
557+
558+
// we produce a malloc side-effect, which stays
559+
side_effect_exprt malloc_expr(ID_allocate);
560+
malloc_expr.copy_to_operands(object_size);
561+
// could use true and get rid of the code below
562+
malloc_expr.copy_to_operands(false_exprt());
563+
malloc_expr.type()=rhs.type();
564+
565+
goto_programt::targett t_n=dest.add_instruction(ASSIGN);
566+
t_n->code=code_assignt(lhs, malloc_expr);
567+
t_n->source_location=location;
568+
569+
// zero-initialize the object
570+
dereference_exprt deref(lhs, object_type);
571+
exprt zero_object=
572+
zero_initializer(object_type, location, ns, get_message_handler());
573+
set_class_identifier(
574+
to_struct_expr(zero_object), ns, to_symbol_type(object_type));
575+
goto_programt::targett t_i=dest.add_instruction(ASSIGN);
576+
t_i->code=code_assignt(deref, zero_object);
577+
t_i->source_location=location;
578+
}
579+
543580
void goto_convertt::do_java_new_array(
544581
const exprt &lhs,
545582
const side_effect_exprt &rhs,

src/goto-programs/goto_convert.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,10 @@ void goto_convertt::convert_assign(
766766
else if(rhs.id()==ID_side_effect &&
767767
rhs.get(ID_statement)==ID_java_new)
768768
{
769-
copy(code, ASSIGN, dest);
769+
Forall_operands(it, rhs)
770+
clean_expr(*it, dest);
771+
772+
do_java_new(lhs, to_side_effect_expr(rhs), dest);
770773
}
771774
else if(rhs.id()==ID_side_effect &&
772775
rhs.get(ID_statement)==ID_java_new_array)

src/goto-programs/goto_convert_class.h

+5
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@ class goto_convertt:public messaget
142142
const side_effect_exprt &rhs,
143143
goto_programt &dest);
144144

145+
void do_java_new(
146+
const exprt &lhs,
147+
const side_effect_exprt &rhs,
148+
goto_programt &dest);
149+
145150
void do_java_new_array(
146151
const exprt &lhs,
147152
const side_effect_exprt &rhs,

src/goto-programs/remove_java_new.cpp

-105
This file was deleted.

src/goto-programs/remove_java_new.h

-29
This file was deleted.

src/jbmc/jbmc_parse_options.cpp

+1-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ Author: Daniel Kroening, [email protected]
4444
#include <goto-programs/show_goto_functions.h>
4545
#include <goto-programs/show_symbol_table.h>
4646
#include <goto-programs/show_properties.h>
47-
#include <goto-programs/remove_java_new.h>
4847

4948
#include <goto-symex/adjust_float_expressions.h>
5049

@@ -735,9 +734,7 @@ bool jbmc_parse_optionst::process_goto_functions(
735734
{
736735
try
737736
{
738-
remove_java_new(goto_model, get_message_handler());
739-
740-
status() << "Removal of virtual functions" << eom;
737+
status() << "Running GOTO functions transformation passes" << eom;
741738
// remove catch and throw (introduces instanceof but request it is removed)
742739
remove_exceptions(
743740
goto_model, remove_exceptions_typest::REMOVE_ADDED_INSTANCEOF);

unit/pointer-analysis/custom_value_set_analysis.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Author: Chris Smowton, [email protected]
1212
#include <langapi/mode.h>
1313
#include <goto-programs/initialize_goto_model.h>
1414
#include <goto-programs/goto_inline.h>
15-
#include <goto-programs/remove_java_new.h>
1615
#include <java_bytecode/java_bytecode_language.h>
1716
#include <java_bytecode/java_types.h>
1817
#include <pointer-analysis/value_set_analysis.h>
@@ -186,9 +185,6 @@ SCENARIO("test_value_set_analysis",
186185

187186
namespacet ns(goto_model.symbol_table);
188187

189-
// VSA doesn't currently support java_new as an allocator
190-
remove_java_new(goto_model, null_output);
191-
192188
// Fully inline the test program, to avoid VSA conflating
193189
// constructor callsites confusing the results we're trying to check:
194190
goto_function_inline(goto_model, TEST_FUNCTION_NAME, null_output);

0 commit comments

Comments
 (0)