Skip to content

Commit 58d5980

Browse files
authored
Merge pull request #1740 from smowton/smowton/feature/adjust_float_expressions_per_function
JBMC: adjust float expressions per function
2 parents bfd4f50 + c91ff69 commit 58d5980

9 files changed

+83
-36
lines changed

src/analyses/goto_check.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1753,10 +1753,11 @@ void goto_checkt::goto_check(
17531753
void goto_check(
17541754
const namespacet &ns,
17551755
const optionst &options,
1756+
const irep_idt &mode,
17561757
goto_functionst::goto_functiont &goto_function)
17571758
{
17581759
goto_checkt goto_check(ns, options);
1759-
goto_check.goto_check(goto_function, irep_idt());
1760+
goto_check.goto_check(goto_function, mode);
17601761
}
17611762

17621763
void goto_check(

src/analyses/goto_check.h

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ void goto_check(
2626
void goto_check(
2727
const namespacet &ns,
2828
const optionst &options,
29+
const irep_idt &mode,
2930
goto_functionst::goto_functiont &goto_function);
3031

3132
void goto_check(

src/goto-programs/convert_nondet.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@ void convert_nondet(
130130
}
131131
}
132132

133+
void convert_nondet(
134+
goto_model_functiont &function,
135+
message_handlert &message_handler,
136+
const object_factory_parameterst &object_factory_parameters)
137+
{
138+
convert_nondet(
139+
function.get_goto_function().body,
140+
function.get_symbol_table(),
141+
message_handler,
142+
object_factory_parameters);
143+
144+
function.compute_location_numbers();
145+
}
146+
133147
void convert_nondet(
134148
goto_functionst &goto_functions,
135149
symbol_tablet &symbol_table,

src/goto-programs/convert_nondet.h

+12
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Reuben Thomas, [email protected]
1717
class goto_functionst;
1818
class symbol_tablet;
1919
class goto_modelt;
20+
class goto_model_functiont;
2021
class message_handlert;
2122
struct object_factory_parameterst;
2223

@@ -38,4 +39,15 @@ void convert_nondet(
3839
message_handlert &,
3940
const object_factory_parameterst &object_factory_parameters);
4041

42+
/// Replace calls to nondet library functions with an internal nondet
43+
/// representation.
44+
/// \param function: goto program to modify
45+
/// \param message_handler: For error logging.
46+
/// \param object_factory_parameters: Parameters for the generation of nondet
47+
/// objects.
48+
void convert_nondet(
49+
goto_model_functiont &function,
50+
message_handlert &message_handler,
51+
const object_factory_parameterst &object_factory_parameters);
52+
4153
#endif

src/goto-programs/lazy_goto_model.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ class lazy_goto_modelt : public can_produce_functiont
6464
message_handlert &message_handler)
6565
{
6666
return lazy_goto_modelt(
67-
[&handler] (goto_model_functiont &fun, const can_produce_functiont &cpf) { // NOLINT(*)
68-
handler.process_goto_function(fun, cpf);
67+
[&handler, &options]
68+
(goto_model_functiont &fun, const can_produce_functiont &cpf) { // NOLINT(*)
69+
handler.process_goto_function(fun, cpf, options);
6970
},
7071
[&handler, &options] (goto_modelt &goto_model) -> bool { // NOLINT(*)
7172
return handler.process_goto_functions(goto_model, options);

src/goto-programs/replace_java_nondet.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ static void replace_java_nondet(goto_programt &goto_program)
235235
}
236236
}
237237

238+
void replace_java_nondet(goto_model_functiont &function)
239+
{
240+
goto_programt &program = function.get_goto_function().body;
241+
replace_java_nondet(program);
242+
243+
function.compute_location_numbers();
244+
245+
remove_skip(program);
246+
}
247+
238248
void replace_java_nondet(goto_functionst &goto_functions)
239249
{
240250
for(auto &goto_program : goto_functions.function_map)

src/goto-programs/replace_java_nondet.h

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Author: Reuben Thomas, [email protected]
1414

1515
class goto_modelt;
1616
class goto_functionst;
17+
class goto_model_functiont;
1718

1819
/// Replace calls to nondet library functions with an internal nondet
1920
/// representation.
@@ -22,4 +23,9 @@ void replace_java_nondet(goto_modelt &);
2223

2324
void replace_java_nondet(goto_functionst &);
2425

26+
/// Replace calls to nondet library functions with an internal nondet
27+
/// representation in a single function.
28+
/// \param function: The goto program to modify.
29+
void replace_java_nondet(goto_model_functiont &function);
30+
2531
#endif

src/jbmc/jbmc_parse_options.cpp

+33-32
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,11 @@ int jbmc_parse_optionst::get_goto_program(
643643

644644
void jbmc_parse_optionst::process_goto_function(
645645
goto_model_functiont &function,
646-
const can_produce_functiont &available_functions)
646+
const can_produce_functiont &available_functions,
647+
const optionst &options)
647648
{
648649
symbol_tablet &symbol_table = function.get_symbol_table();
650+
namespacet ns(symbol_table);
649651
goto_functionst::goto_functiont &goto_function = function.get_goto_function();
650652
try
651653
{
@@ -664,6 +666,36 @@ void jbmc_parse_optionst::process_goto_function(
664666
};
665667

666668
remove_returns(function, function_is_stub);
669+
670+
replace_java_nondet(function);
671+
672+
// Similar removal of java nondet statements:
673+
// TODO Should really get this from java_bytecode_language somehow, but we
674+
// don't have an instance of that here.
675+
object_factory_parameterst factory_params;
676+
factory_params.max_nondet_array_length=
677+
cmdline.isset("java-max-input-array-length")
678+
? std::stoul(cmdline.get_value("java-max-input-array-length"))
679+
: MAX_NONDET_ARRAY_LENGTH_DEFAULT;
680+
factory_params.max_nondet_string_length=
681+
cmdline.isset("string-max-input-length")
682+
? std::stoul(cmdline.get_value("string-max-input-length"))
683+
: MAX_NONDET_STRING_LENGTH;
684+
factory_params.max_nondet_tree_depth=
685+
cmdline.isset("java-max-input-tree-depth")
686+
? std::stoul(cmdline.get_value("java-max-input-tree-depth"))
687+
: MAX_NONDET_TREE_DEPTH;
688+
689+
convert_nondet(
690+
function,
691+
get_message_handler(),
692+
factory_params);
693+
694+
// add generic checks
695+
goto_check(ns, options, ID_java, function.get_goto_function());
696+
697+
// checks don't know about adjusted float expressions
698+
adjust_float_expressions(goto_function, ns);
667699
}
668700

669701
catch(const char *e)
@@ -701,37 +733,6 @@ bool jbmc_parse_optionst::process_goto_functions(
701733
// instrument library preconditions
702734
instrument_preconditions(goto_model);
703735

704-
// Similar removal of java nondet statements:
705-
// TODO Should really get this from java_bytecode_language somehow, but we
706-
// don't have an instance of that here.
707-
object_factory_parameterst factory_params;
708-
factory_params.max_nondet_array_length=
709-
cmdline.isset("java-max-input-array-length")
710-
? std::stoul(cmdline.get_value("java-max-input-array-length"))
711-
: MAX_NONDET_ARRAY_LENGTH_DEFAULT;
712-
factory_params.max_nondet_string_length=
713-
cmdline.isset("string-max-input-length")
714-
? std::stoul(cmdline.get_value("string-max-input-length"))
715-
: MAX_NONDET_STRING_LENGTH;
716-
factory_params.max_nondet_tree_depth=
717-
cmdline.isset("java-max-input-tree-depth")
718-
? std::stoul(cmdline.get_value("java-max-input-tree-depth"))
719-
: MAX_NONDET_TREE_DEPTH;
720-
721-
replace_java_nondet(goto_model);
722-
723-
convert_nondet(
724-
goto_model,
725-
get_message_handler(),
726-
factory_params);
727-
728-
// add generic checks
729-
status() << "Generic Property Instrumentation" << eom;
730-
goto_check(options, goto_model);
731-
732-
// checks don't know about adjusted float expressions
733-
adjust_float_expressions(goto_model);
734-
735736
// ignore default/user-specified initialization
736737
// of variables with static lifetime
737738
if(cmdline.isset("nondet-static"))

src/jbmc/jbmc_parse_options.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ class jbmc_parse_optionst:
8686

8787
void process_goto_function(
8888
goto_model_functiont &function,
89-
const can_produce_functiont &);
89+
const can_produce_functiont &,
90+
const optionst &);
9091
bool process_goto_functions(goto_modelt &goto_model, const optionst &options);
9192

9293
protected:

0 commit comments

Comments
 (0)