cprover
jdiff_parse_options.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: JDIFF Command Line Option Processing
4 
5 Author: Peter Schrammel
6 
7 \*******************************************************************/
8 
11 
12 #include "jdiff_parse_options.h"
13 
14 #include <cstdlib> // exit()
15 #include <fstream>
16 #include <iostream>
17 #include <memory>
18 
19 #include <util/config.h>
20 #include <util/exit_codes.h>
21 #include <util/make_unique.h>
22 #include <util/options.h>
23 #include <util/version.h>
24 
25 #include <langapi/language.h>
26 
33 #include <goto-programs/loop_ids.h>
34 #include <goto-programs/mm_io.h>
48 
49 #include <goto-instrument/cover.h>
50 
52 
56 
57 #include <langapi/mode.h>
58 
59 #include "java_syntactic_diff.h"
61 #include <goto-diff/goto_diff.h>
62 #include <goto-diff/unified_diff.h>
63 
64 jdiff_parse_optionst::jdiff_parse_optionst(int argc, const char **argv)
67  argc,
68  argv,
69  std::string("JDIFF ") + CBMC_VERSION)
70 {
71 }
72 
74 {
75  if(config.set(cmdline))
76  {
77  usage_error();
78  exit(1);
79  }
80 
81  // TODO: improve this when language front ends have been
82  // disentangled from command line parsing
83  // we always require these options
84  cmdline.set("no-lazy-methods");
85  cmdline.set("no-refine-strings");
87 
88  if(cmdline.isset("cover"))
89  parse_cover_options(cmdline, options);
90 
91  if(cmdline.isset("mm"))
92  options.set_option("mm", cmdline.get_value("mm"));
93 
94  // all checks supported by goto_check
96 
97  if(cmdline.isset("debug-level"))
98  options.set_option("debug-level", cmdline.get_value("debug-level"));
99 
100  if(cmdline.isset("unwindset"))
101  options.set_option("unwindset", cmdline.get_value("unwindset"));
102 
103  // constant propagation
104  if(cmdline.isset("no-propagation"))
105  options.set_option("propagation", false);
106  else
107  options.set_option("propagation", true);
108 
109  // check array bounds
110  if(cmdline.isset("bounds-check"))
111  options.set_option("bounds-check", true);
112  else
113  options.set_option("bounds-check", false);
114 
115  // check division by zero
116  if(cmdline.isset("div-by-zero-check"))
117  options.set_option("div-by-zero-check", true);
118  else
119  options.set_option("div-by-zero-check", false);
120 
121  // check overflow/underflow
122  if(cmdline.isset("signed-overflow-check"))
123  options.set_option("signed-overflow-check", true);
124  else
125  options.set_option("signed-overflow-check", false);
126 
127  // check overflow/underflow
128  if(cmdline.isset("unsigned-overflow-check"))
129  options.set_option("unsigned-overflow-check", true);
130  else
131  options.set_option("unsigned-overflow-check", false);
132 
133  // check overflow/underflow
134  if(cmdline.isset("float-overflow-check"))
135  options.set_option("float-overflow-check", true);
136  else
137  options.set_option("float-overflow-check", false);
138 
139  // check for NaN (not a number)
140  if(cmdline.isset("nan-check"))
141  options.set_option("nan-check", true);
142  else
143  options.set_option("nan-check", false);
144 
145  // check pointers
146  if(cmdline.isset("pointer-check"))
147  options.set_option("pointer-check", true);
148  else
149  options.set_option("pointer-check", false);
150 
151  // check for memory leaks
152  if(cmdline.isset("memory-leak-check"))
153  options.set_option("memory-leak-check", true);
154  else
155  options.set_option("memory-leak-check", false);
156 
157  // check assertions
158  if(cmdline.isset("no-assertions"))
159  options.set_option("assertions", false);
160  else
161  options.set_option("assertions", true);
162 
163  // use assumptions
164  if(cmdline.isset("no-assumptions"))
165  options.set_option("assumptions", false);
166  else
167  options.set_option("assumptions", true);
168 
169  // magic error label
170  if(cmdline.isset("error-label"))
171  options.set_option("error-label", cmdline.get_values("error-label"));
172 
173  options.set_option("show-properties", cmdline.isset("show-properties"));
174 }
175 
178 {
179  if(cmdline.isset("version"))
180  {
181  std::cout << CBMC_VERSION << '\n';
182  return CPROVER_EXIT_SUCCESS;
183  }
184 
185  //
186  // command line options
187  //
188 
189  optionst options;
190  get_command_line_options(options);
193 
194  //
195  // Print a banner
196  //
197  log.status() << "JDIFF version " << CBMC_VERSION << " " << sizeof(void *) * 8
198  << "-bit " << config.this_architecture() << " "
200 
201  if(cmdline.args.size() != 2)
202  {
203  log.error() << "Please provide two programs to compare" << messaget::eom;
205  }
206 
208 
209  goto_modelt goto_model1 =
211  if(process_goto_program(options, goto_model1))
213  goto_modelt goto_model2 =
215  if(process_goto_program(options, goto_model2))
217 
218  if(cmdline.isset("show-loops"))
219  {
220  show_loop_ids(ui_message_handler.get_ui(), goto_model1);
221  show_loop_ids(ui_message_handler.get_ui(), goto_model2);
222  return CPROVER_EXIT_SUCCESS;
223  }
224 
225  if(
226  cmdline.isset("show-goto-functions") ||
227  cmdline.isset("list-goto-functions"))
228  {
230  goto_model1, ui_message_handler, cmdline.isset("list-goto-functions"));
232  goto_model2, ui_message_handler, cmdline.isset("list-goto-functions"));
233  return CPROVER_EXIT_SUCCESS;
234  }
235 
236  if(
237  cmdline.isset("change-impact") || cmdline.isset("forward-impact") ||
238  cmdline.isset("backward-impact"))
239  {
240  impact_modet impact_mode =
241  cmdline.isset("forward-impact")
243  : (cmdline.isset("backward-impact") ? impact_modet::BACKWARD
246  goto_model1, goto_model2, impact_mode, cmdline.isset("compact-output"));
247 
248  return CPROVER_EXIT_SUCCESS;
249  }
250 
251  if(cmdline.isset("unified") || cmdline.isset('u'))
252  {
253  unified_difft u(goto_model1, goto_model2);
254  u();
255  u.output(std::cout);
256 
257  return CPROVER_EXIT_SUCCESS;
258  }
259 
261  goto_model1, goto_model2, options, ui_message_handler);
262  sd();
263  sd.output_functions();
264 
265  return CPROVER_EXIT_SUCCESS;
266 }
267 
269  const optionst &options,
270  goto_modelt &goto_model)
271 {
272  {
273  // remove function pointers
274  log.status() << "Removing function pointers and virtual functions"
275  << messaget::eom;
277  ui_message_handler, goto_model, cmdline.isset("pointer-check"));
278 
279  // Java virtual functions -> explicit dispatch tables:
280  remove_virtual_functions(goto_model);
281 
282  // remove Java throw and catch
283  // This introduces instanceof, so order is important:
285 
286  // Java instanceof -> clsid comparison:
287  class_hierarchyt class_hierarchy(goto_model.symbol_table);
288  remove_instanceof(goto_model, class_hierarchy, ui_message_handler);
289 
290  mm_io(goto_model);
291 
292  // instrument library preconditions
293  instrument_preconditions(goto_model);
294 
295  // remove returns, gcc vectors, complex
296  remove_returns(goto_model);
297  remove_vector(goto_model);
298  remove_complex(goto_model);
299  rewrite_union(goto_model);
300 
301  // add generic checks
302  log.status() << "Generic Property Instrumentation" << messaget::eom;
303  goto_check(options, goto_model);
304 
305  // checks don't know about adjusted float expressions
306  adjust_float_expressions(goto_model);
307 
308  // recalculate numbers, etc.
309  goto_model.goto_functions.update();
310 
311  // add loop ids
313 
314  // remove skips such that trivial GOTOs are deleted and not considered
315  // for coverage annotation:
316  remove_skip(goto_model);
317 
318  // instrument cover goals
319  if(cmdline.isset("cover"))
320  {
321  const auto cover_config =
322  get_cover_config(options, goto_model.symbol_table, ui_message_handler);
323  if(instrument_cover_goals(cover_config, goto_model, ui_message_handler))
324  return true;
325  }
326 
327  // label the assertions
328  // This must be done after adding assertions and
329  // before using the argument of the "property" option.
330  // Do not re-label after using the property slicer because
331  // this would cause the property identifiers to change.
332  label_properties(goto_model);
333 
334  // remove any skips introduced since coverage instrumentation
335  remove_skip(goto_model);
336  goto_model.goto_functions.update();
337  }
338 
339  return false;
340 }
341 
344 {
345  // clang-format off
346  std::cout << '\n' << banner_string("JDIFF", CBMC_VERSION) << '\n'
347  << align_center_with_border("Copyright (C) 2016-2018") << '\n'
348  << align_center_with_border("Daniel Kroening, Peter Schrammel") << '\n' // NOLINT(*)
349  << align_center_with_border("kroening@kroening.com") << '\n'
350  <<
351  "\n"
352  "Usage: Purpose:\n"
353  "\n"
354  " jdiff [-?] [-h] [--help] show help\n"
355  " jdiff old new jars to be compared\n"
356  "\n"
357  "Diff options:\n"
360  " --syntactic do syntactic diff (default)\n"
361  " -u | --unified output unified diff\n"
362  " --change-impact | \n"
363  " --forward-impact |\n"
364  // NOLINTNEXTLINE(whitespace/line_length)
365  " --backward-impact output unified diff with forward&backward/forward/backward dependencies\n"
366  " --compact-output output dependencies in compact mode\n"
367  "\n"
368  "Program instrumentation options:\n"
370  " --cover CC create test-suite with coverage criterion CC\n" // NOLINT(*)
371  "Java Bytecode frontend options:\n"
373  "Other options:\n"
374  " --version show version and exit\n"
375  " --json-ui use JSON-formatted output\n"
377  "\n";
378  // clang-format on
379 }
cmdlinet::args
argst args
Definition: cmdline.h:91
jdiff_parse_optionst::doit
virtual int doit()
invoke main modules
Definition: jdiff_parse_options.cpp:177
cover.h
Coverage Instrumentation.
HELP_SHOW_GOTO_FUNCTIONS
#define HELP_SHOW_GOTO_FUNCTIONS
Definition: show_goto_functions.h:26
impact_modet
impact_modet
Definition: change_impact.h:18
string_abstraction.h
String Abstraction.
JDIFF_OPTIONS
#define JDIFF_OPTIONS
Definition: jdiff_parse_options.h:29
PARSE_OPTIONS_GOTO_CHECK
#define PARSE_OPTIONS_GOTO_CHECK(cmdline, options)
Definition: goto_check.h:61
rewrite_union.h
Symbolic Execution.
unified_difft::output
void output(std::ostream &os) const
Definition: unified_diff.cpp:367
jdiff_parse_optionst::get_command_line_options
void get_command_line_options(optionst &options)
Definition: jdiff_parse_options.cpp:73
class_hierarchyt
Non-graph-based representation of the class hierarchy.
Definition: class_hierarchy.h:43
parse_options_baset::ui_message_handler
ui_message_handlert ui_message_handler
Definition: parse_options.h:42
parse_options_baset
Definition: parse_options.h:20
java_bytecode_language.h
JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP
#define JAVA_BYTECODE_LANGUAGE_OPTIONS_HELP
Definition: java_bytecode_language.h:55
parse_java_language_options
void parse_java_language_options(const cmdlinet &cmd, optionst &options)
Parse options that are java bytecode specific.
Definition: java_bytecode_language.cpp:56
remove_exceptions_using_instanceof
void remove_exceptions_using_instanceof(symbol_table_baset &symbol_table, goto_functionst &goto_functions, message_handlert &message_handler)
removes throws/CATCH-POP/CATCH-PUSH
Definition: remove_exceptions.cpp:633
cmdlinet::isset
virtual bool isset(char option) const
Definition: cmdline.cpp:29
impact_modet::BACKWARD
@ BACKWARD
goto_inline.h
Function Inlining.
optionst
Definition: options.h:23
messaget::M_STATISTICS
@ M_STATISTICS
Definition: message.h:171
mm_io
void mm_io(const exprt &mm_io_r, const exprt &mm_io_w, goto_functionst::goto_functiont &goto_function, const namespacet &ns)
Definition: mm_io.cpp:32
messaget::status
mstreamt & status() const
Definition: message.h:414
instrument_preconditions.h
remove_skip
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
Definition: remove_skip.cpp:85
remove_virtual_functions.h
Functions for replacing virtual function call with a static function calls in functions,...
remove_virtual_functions
void remove_virtual_functions(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
Remove virtual function calls from all functions in the specified list and replace them with their mo...
Definition: remove_virtual_functions.cpp:723
change_impact
void change_impact(const goto_modelt &model_old, const goto_modelt &model_new, impact_modet impact_mode, bool compact_output)
Definition: change_impact.cpp:745
goto_modelt
Definition: goto_model.h:26
mode.h
show_loop_ids
void show_loop_ids(ui_message_handlert::uit ui, const goto_modelt &goto_model)
Definition: loop_ids.cpp:19
options.h
Options.
goto_check
void goto_check(const irep_idt &function_identifier, goto_functionst::goto_functiont &goto_function, const namespacet &ns, const optionst &options)
Definition: goto_check.cpp:2231
optionst::set_option
void set_option(const std::string &option, const bool value)
Definition: options.cpp:28
messaget::eom
static eomt eom
Definition: message.h:297
instrument_cover_goals
static void instrument_cover_goals(const irep_idt &function_id, goto_programt &goto_program, const cover_instrumenterst &instrumenters, const irep_idt &mode, message_handlert &message_handler, const cover_instrumenter_baset::assertion_factoryt &make_assertion)
Applies instrumenters to given goto program.
Definition: cover.cpp:37
impact_modet::BOTH
@ BOTH
version.h
string_instrumentation.h
String Abstraction.
unified_difft
Definition: unified_diff.h:31
label_properties
void label_properties(goto_modelt &goto_model)
Definition: set_properties.cpp:43
cmdlinet::set
virtual void set(const std::string &option, bool value=true)
Set option option to value, or true if the value is omitted.
Definition: cmdline.cpp:57
remove_instanceof
void remove_instanceof(const irep_idt &function_identifier, goto_programt::targett target, goto_programt &goto_program, symbol_table_baset &symbol_table, const class_hierarchyt &class_hierarchy, message_handlert &message_handler)
Replace an instanceof in the expression or guard of the passed instruction of the given function body...
Definition: remove_instanceof.cpp:299
ui_message_handlert::get_ui
virtual uit get_ui() const
Definition: ui_message.h:31
parse_options_baset::usage_error
virtual void usage_error()
Definition: parse_options.cpp:47
remove_vector
static void remove_vector(typet &)
removes vector data type
Definition: remove_vector.cpp:166
unified_diff.h
Unified diff (using LCSS) of goto functions.
remove_complex.h
Remove the 'complex' data type by compilation into structs.
set_properties.h
Set the properties to check.
get_cover_config
cover_configt get_cover_config(const optionst &options, const symbol_tablet &symbol_table, message_handlert &message_handler)
Build data structures controlling coverage from command-line options.
Definition: cover.cpp:176
goto_difft::output_functions
virtual void output_functions() const
Output diff result.
Definition: goto_diff_base.cpp:21
CBMC_VERSION
const char * CBMC_VERSION
make_unique.h
messaget::error
mstreamt & error() const
Definition: message.h:399
initialize_goto_model.h
Initialize a Goto Program.
goto_diff.h
GOTO-DIFF Base Class.
banner_string
std::string banner_string(const std::string &front_end, const std::string &version)
Definition: parse_options.cpp:163
mm_io.h
Perform Memory-mapped I/O instrumentation.
instrument_preconditions
void instrument_preconditions(const goto_modelt &goto_model, goto_programt &goto_program)
Definition: instrument_preconditions.cpp:90
jdiff_parse_options.h
JDIFF Command Line Option Processing.
show_properties.h
Show the properties.
jdiff_parse_optionst::help
virtual void help()
display command line help
Definition: jdiff_parse_options.cpp:343
cmdlinet::get_value
std::string get_value(char option) const
Definition: cmdline.cpp:47
java_syntactic_diff.h
Syntactic GOTO-DIFF for Java.
rewrite_union
void rewrite_union(exprt &expr)
We rewrite u.c for unions u into byte_extract(u, 0), and { .c = v } into byte_update(NIL,...
Definition: rewrite_union.cpp:66
language.h
Abstract interface to support a programming language.
HELP_SHOW_PROPERTIES
#define HELP_SHOW_PROPERTIES
Definition: show_properties.h:29
configt::this_operating_system
static irep_idt this_operating_system()
Definition: config.cpp:1402
show_goto_functions
void show_goto_functions(const namespacet &ns, ui_message_handlert &ui_message_handler, const goto_functionst &goto_functions, bool list_only)
Definition: show_goto_functions.cpp:26
parse_cover_options
void parse_cover_options(const cmdlinet &cmdline, optionst &options)
Parses coverage-related command line options.
Definition: cover.cpp:142
impact_modet::FORWARD
@ FORWARD
jdiff_parse_optionst::jdiff_parse_optionst
jdiff_parse_optionst(int argc, const char **argv)
Definition: jdiff_parse_options.cpp:64
goto_functionst::compute_loop_numbers
void compute_loop_numbers()
Definition: goto_functions.cpp:52
read_goto_binary.h
Read Goto Programs.
CPROVER_EXIT_INCORRECT_TASK
#define CPROVER_EXIT_INCORRECT_TASK
The command line is correctly structured but cannot be carried out due to missing files,...
Definition: exit_codes.h:49
remove_vector.h
Remove the 'vector' data type by compilation into arrays.
remove_complex
static void remove_complex(typet &)
removes complex data type
Definition: remove_complex.cpp:231
remove_returns.h
Replace function returns by assignments to global variables.
remove_exceptions.h
Remove function exceptional returns.
remove_unused_functions.h
Unused function removal.
config
configt config
Definition: config.cpp:24
remove_instanceof.h
Remove Instance-of Operators.
parse_options_baset::log
messaget log
Definition: parse_options.h:43
configt::this_architecture
static irep_idt this_architecture()
Definition: config.cpp:1302
goto_modelt::goto_functions
goto_functionst goto_functions
GOTO functions.
Definition: goto_model.h:33
jdiff_parse_optionst::register_languages
void register_languages()
Definition: jdiff_languages.cpp:18
HELP_GOTO_CHECK
#define HELP_GOTO_CHECK
Definition: goto_check.h:45
configt::set
bool set(const cmdlinet &cmdline)
Definition: config.cpp:798
exit_codes.h
Document and give macros for the exit codes of CPROVER binaries.
remove_returns
void remove_returns(symbol_table_baset &symbol_table, goto_functionst &goto_functions)
removes returns
Definition: remove_returns.cpp:256
java_syntactic_difft
Definition: java_syntactic_diff.h:18
goto_functionst::update
void update()
Definition: goto_functions.h:81
jdiff_parse_optionst::process_goto_program
bool process_goto_program(const optionst &options, goto_modelt &goto_model)
Definition: jdiff_parse_options.cpp:268
change_impact.h
Data and control-dependencies of syntactic diff.
config.h
loop_ids.h
Loop IDs.
adjust_float_expressions
void adjust_float_expressions(exprt &expr, const exprt &rounding_mode)
Replaces arithmetic operations and typecasts involving floating point numbers with their equivalent f...
Definition: adjust_float_expressions.cpp:78
add_failed_symbols.h
Pointer Dereferencing.
CPROVER_EXIT_INTERNAL_ERROR
#define CPROVER_EXIT_INTERNAL_ERROR
An error has been encountered during processing the requested analysis.
Definition: exit_codes.h:45
initialize_goto_model
goto_modelt initialize_goto_model(const std::vector< std::string > &files, message_handlert &message_handler, const optionst &options)
Definition: initialize_goto_model.cpp:59
goto_convert_functions.h
Goto Programs with Functions.
CPROVER_EXIT_SUCCESS
#define CPROVER_EXIT_SUCCESS
Success indicates the required analysis has been performed without error.
Definition: exit_codes.h:16
messaget::eval_verbosity
static unsigned eval_verbosity(const std::string &user_input, const message_levelt default_verbosity, message_handlert &dest)
Parse a (user-)provided string as a verbosity level and set it as the verbosity of dest.
Definition: message.cpp:104
remove_skip.h
Program Transformation.
adjust_float_expressions.h
Symbolic Execution.
remove_function_pointers
bool remove_function_pointers(message_handlert &_message_handler, symbol_tablet &symbol_table, const goto_functionst &goto_functions, goto_programt &goto_program, const irep_idt &function_id, bool add_safety_assertion, bool only_remove_const_fps)
Definition: remove_function_pointers.cpp:519
cmdlinet::get_values
const std::list< std::string > & get_values(const std::string &option) const
Definition: cmdline.cpp:108
remove_function_pointers.h
Remove Indirect Function Calls.
parse_options_baset::cmdline
cmdlinet cmdline
Definition: parse_options.h:28
goto_modelt::symbol_table
symbol_tablet symbol_table
Symbol table.
Definition: goto_model.h:30
align_center_with_border
std::string align_center_with_border(const std::string &text)
Utility for displaying help centered messages borderered by "* *".
Definition: parse_options.cpp:150
HELP_TIMESTAMP
#define HELP_TIMESTAMP
Definition: timestamper.h:14