Skip to content

Commit cd04e70

Browse files
committed
JBMC: use simple method stubbing pass
This uses lazy_goto_modelt's support for driver programs supplying method replacements to provide stub implementations of methods whose code is unavailable.
1 parent a6b2cda commit cd04e70

File tree

2 files changed

+55
-19
lines changed

2 files changed

+55
-19
lines changed

src/jbmc/jbmc_parse_options.cpp

+53-19
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Author: Daniel Kroening, [email protected]
4848
#include <goto-instrument/reachability_slicer.h>
4949
#include <goto-instrument/nondet_static.h>
5050

51+
#include <linking/static_lifetime_init.h>
52+
5153
#include <pointer-analysis/add_failed_symbols.h>
5254

5355
#include <langapi/mode.h>
@@ -58,6 +60,7 @@ Author: Daniel Kroening, [email protected]
5860
#include <java_bytecode/remove_instanceof.h>
5961
#include <java_bytecode/remove_java_new.h>
6062
#include <java_bytecode/replace_java_nondet.h>
63+
#include <java_bytecode/simple_method_stubbing.h>
6164

6265
#include <cbmc/version.h>
6366

@@ -522,6 +525,21 @@ int jbmc_parse_optionst::doit()
522525
};
523526
}
524527

528+
object_factory_params.max_nondet_array_length =
529+
cmdline.isset("java-max-input-array-length")
530+
? std::stoul(cmdline.get_value("java-max-input-array-length"))
531+
: MAX_NONDET_ARRAY_LENGTH_DEFAULT;
532+
object_factory_params.max_nondet_string_length =
533+
cmdline.isset("string-max-input-length")
534+
? std::stoul(cmdline.get_value("string-max-input-length"))
535+
: MAX_NONDET_STRING_LENGTH;
536+
object_factory_params.max_nondet_tree_depth =
537+
cmdline.isset("java-max-input-tree-depth")
538+
? std::stoul(cmdline.get_value("java-max-input-tree-depth"))
539+
: MAX_NONDET_TREE_DEPTH;
540+
541+
stub_objects_are_not_null = cmdline.isset("java-assume-inputs-non-null");
542+
525543
if(!cmdline.isset("symex-driven-lazy-loading"))
526544
{
527545
std::unique_ptr<goto_modelt> goto_model_ptr;
@@ -757,23 +775,11 @@ void jbmc_parse_optionst::process_goto_function(
757775
replace_java_nondet(function);
758776

759777
// Similar removal of java nondet statements:
760-
// TODO Should really get this from java_bytecode_language somehow, but we
761-
// don't have an instance of that here.
762-
object_factory_parameterst factory_params;
763-
factory_params.max_nondet_array_length=
764-
cmdline.isset("java-max-input-array-length")
765-
? std::stoul(cmdline.get_value("java-max-input-array-length"))
766-
: MAX_NONDET_ARRAY_LENGTH_DEFAULT;
767-
factory_params.max_nondet_string_length=
768-
cmdline.isset("string-max-input-length")
769-
? std::stoul(cmdline.get_value("string-max-input-length"))
770-
: MAX_NONDET_STRING_LENGTH;
771-
factory_params.max_nondet_tree_depth=
772-
cmdline.isset("java-max-input-tree-depth")
773-
? std::stoul(cmdline.get_value("java-max-input-tree-depth"))
774-
: MAX_NONDET_TREE_DEPTH;
775-
776-
convert_nondet(function, get_message_handler(), factory_params, ID_java);
778+
convert_nondet(
779+
function,
780+
get_message_handler(),
781+
object_factory_params,
782+
ID_java);
777783

778784
// add generic checks
779785
goto_check(ns, options, ID_java, function.get_goto_function());
@@ -1014,7 +1020,9 @@ bool jbmc_parse_optionst::process_goto_functions(
10141020

10151021
bool jbmc_parse_optionst::can_generate_function_body(const irep_idt &name)
10161022
{
1017-
return false;
1023+
static const irep_idt initialize_id = INITIALIZE_FUNCTION;
1024+
1025+
return name != goto_functionst::entry_point() && name != initialize_id;
10181026
}
10191027

10201028
bool jbmc_parse_optionst::generate_function_body(
@@ -1023,7 +1031,33 @@ bool jbmc_parse_optionst::generate_function_body(
10231031
goto_functiont &function,
10241032
bool body_available)
10251033
{
1026-
return false;
1034+
// Provide a simple stub implementation for any function we don't have a
1035+
// bytecode implementation for:
1036+
1037+
if(body_available)
1038+
return false;
1039+
1040+
if(!can_generate_function_body(function_name))
1041+
return false;
1042+
1043+
if(symbol_table.lookup_ref(function_name).mode == ID_java)
1044+
{
1045+
java_generate_simple_method_stub(
1046+
function_name,
1047+
symbol_table,
1048+
stub_objects_are_not_null,
1049+
object_factory_params,
1050+
get_message_handler());
1051+
1052+
goto_convert_functionst converter(symbol_table, get_message_handler());
1053+
converter.convert_function(function_name, function);
1054+
1055+
return true;
1056+
}
1057+
else
1058+
{
1059+
return false;
1060+
}
10271061
}
10281062

10291063
/// display command line help

src/jbmc/jbmc_parse_options.h

+2
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ class jbmc_parse_optionst:
114114
ui_message_handlert ui_message_handler;
115115
std::unique_ptr<cover_configt> cover_config;
116116
path_strategy_choosert path_strategy_chooser;
117+
object_factory_parameterst object_factory_params;
118+
bool stub_objects_are_not_null;
117119

118120
void eval_verbosity();
119121
void get_command_line_options(optionst &);

0 commit comments

Comments
 (0)