-
Notifications
You must be signed in to change notification settings - Fork 273
RFC: handling of fatal errors #1280
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
Closed
peterschrammel
wants to merge
4
commits into
diffblue:develop
from
peterschrammel:feature/more-exception-types
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,15 +10,14 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <util/arith_tools.h> | ||
#include <util/replace_expr.h> | ||
#include <util/exception_utils.h> | ||
|
||
bvt bv_cbmct::convert_waitfor(const exprt &expr) | ||
{ | ||
if(expr.operands().size()!=4) | ||
{ | ||
error().source_location=expr.find_source_location(); | ||
error() << "waitfor expected to have four operands" << eom; | ||
throw 0; | ||
} | ||
throw input_src_exceptiont( | ||
expr.find_source_location(), | ||
"waitfor expected to have four operands"); | ||
|
||
exprt new_cycle; | ||
const exprt &old_cycle=expr.op0(); | ||
|
@@ -30,11 +29,9 @@ bvt bv_cbmct::convert_waitfor(const exprt &expr) | |
|
||
mp_integer bound_value; | ||
if(to_integer(bound, bound_value)) | ||
{ | ||
error().source_location=expr.find_source_location(); | ||
error() << "waitfor bound must be a constant" << eom; | ||
throw 0; | ||
} | ||
throw input_src_exceptiont( | ||
expr.find_source_location(), | ||
"waitfor bound must be a constant"); | ||
|
||
{ | ||
// constraint: new_cycle>=old_cycle | ||
|
@@ -135,11 +132,9 @@ bvt bv_cbmct::convert_waitfor(const exprt &expr) | |
bvt bv_cbmct::convert_waitfor_symbol(const exprt &expr) | ||
{ | ||
if(expr.operands().size()!=1) | ||
{ | ||
error().source_location=expr.find_source_location(); | ||
error() << "waitfor_symbol expected to have one operand" << eom; | ||
throw 0; | ||
} | ||
throw input_src_exceptiont( | ||
expr.find_source_location(), | ||
"waitfor_symbol expected to have one operand"); | ||
|
||
exprt result; | ||
const exprt &bound=expr.op0(); | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,7 +69,7 @@ Author: Daniel Kroening, [email protected] | |
#include "xml_interface.h" | ||
|
||
cbmc_parse_optionst::cbmc_parse_optionst(int argc, const char **argv): | ||
parse_options_baset(CBMC_OPTIONS, argc, argv), | ||
parse_optionst(CBMC_OPTIONS, argc, argv, ui_message_handler), | ||
xml_interfacet(cmdline), | ||
language_uit(cmdline, ui_message_handler), | ||
ui_message_handler(cmdline, "CBMC " CBMC_VERSION) | ||
|
@@ -80,7 +80,8 @@ ::cbmc_parse_optionst::cbmc_parse_optionst( | |
int argc, | ||
const char **argv, | ||
const std::string &extra_options): | ||
parse_options_baset(CBMC_OPTIONS+extra_options, argc, argv), | ||
parse_optionst( | ||
CBMC_OPTIONS+extra_options, argc, argv, ui_message_handler), | ||
xml_interfacet(cmdline), | ||
language_uit(cmdline, ui_message_handler), | ||
ui_message_handler(cmdline, "CBMC " CBMC_VERSION) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected] | |
#include <fstream> | ||
|
||
#include <util/unicode.h> | ||
#include <util/exception_utils.h> | ||
|
||
#include <solvers/sat/satcheck.h> | ||
#include <solvers/refinement/bv_refinement.h> | ||
|
@@ -205,10 +206,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt1(smt1_dect::solvert solver) | |
if(filename=="") | ||
{ | ||
if(solver==smt1_dect::solvert::GENERIC) | ||
{ | ||
error() << "please use --outfile" << eom; | ||
throw 0; | ||
} | ||
throw ui_exceptiont("please use --outfile"); | ||
|
||
smt1_dect *smt1_dec= | ||
new smt1_dect( | ||
|
@@ -244,10 +242,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt1(smt1_dect::solvert solver) | |
#endif | ||
|
||
if(!out) | ||
{ | ||
error() << "failed to open " << filename << eom; | ||
throw 0; | ||
} | ||
throw system_exceptiont("failed to open "+filename); | ||
|
||
smt1_convt *smt1_conv= | ||
new smt1_convt( | ||
|
@@ -273,10 +268,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt2(smt2_dect::solvert solver) | |
if(filename=="") | ||
{ | ||
if(solver==smt2_dect::solvert::GENERIC) | ||
{ | ||
error() << "please use --outfile" << eom; | ||
throw 0; | ||
} | ||
throw ui_exceptiont("please use --outfile"); | ||
|
||
smt2_dect *smt2_dec= | ||
new smt2_dect( | ||
|
@@ -318,10 +310,7 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt2(smt2_dect::solvert solver) | |
#endif | ||
|
||
if(!*out) | ||
{ | ||
error() << "failed to open " << filename << eom; | ||
throw 0; | ||
} | ||
throw system_exceptiont("failed to open " +filename); | ||
|
||
smt2_convt *smt2_conv= | ||
new smt2_convt( | ||
|
@@ -344,19 +333,14 @@ cbmc_solverst::solvert* cbmc_solverst::get_smt2(smt2_dect::solvert solver) | |
void cbmc_solverst::no_beautification() | ||
{ | ||
if(options.get_bool_option("beautify")) | ||
{ | ||
error() << "sorry, this solver does not support beautification" << eom; | ||
throw 0; | ||
} | ||
throw ui_exceptiont("sorry, this solver does not support beautification"); | ||
} | ||
|
||
void cbmc_solverst::no_incremental_check() | ||
{ | ||
if(options.get_bool_option("all-properties") || | ||
options.get_option("cover")!="" || | ||
options.get_option("incremental-check")!="") | ||
{ | ||
error() << "sorry, this solver does not support incremental solving" << eom; | ||
throw 0; | ||
} | ||
throw ui_exceptiont( | ||
"sorry, this solver does not support incremental solving"); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <util/json.h> | ||
#include <util/json_expr.h> | ||
#include <util/exception_utils.h> | ||
|
||
void bmct::show_vcc_plain(std::ostream &out) | ||
{ | ||
|
@@ -150,7 +151,7 @@ void bmct::show_vcc() | |
{ | ||
of.open(filename); | ||
if(!of) | ||
throw "failed to open file "+filename; | ||
throw system_exceptiont("failed to open file "+filename); | ||
} | ||
|
||
std::ostream &out=have_file?of:std::cout; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Exception helper utilities | ||
|
||
Author: Peter Schrammel, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#ifndef CPROVER_UTIL_EXCEPTION_UTILS_H | ||
#define CPROVER_UTIL_EXCEPTION_UTILS_H | ||
|
||
#include "invariant.h" | ||
|
||
/// A logic error to be used for OS-related errors (I/O etc) | ||
class system_exceptiont: public std::logic_error | ||
{ | ||
public: | ||
system_exceptiont( | ||
const std::string &_reason): | ||
std::logic_error(_reason) | ||
{ | ||
} | ||
}; | ||
|
||
/// A logic error to be used for user interface errors | ||
class ui_exceptiont: public std::logic_error | ||
{ | ||
public: | ||
ui_exceptiont( | ||
const std::string &_reason): | ||
std::logic_error(_reason) | ||
{ | ||
} | ||
}; | ||
|
||
/// A user interface exception with source locations | ||
class input_src_exceptiont: public ui_exceptiont | ||
{ | ||
public: | ||
input_src_exceptiont( | ||
const source_locationt &_source_location, | ||
const std::string &_reason): | ||
ui_exceptiont(_reason), | ||
source_location(_source_location) | ||
{ | ||
} | ||
|
||
source_locationt source_location; | ||
}; | ||
|
||
#endif // CPROVER_UTIL_EXCEPTION_UTILS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ Author: Chris Smowton, [email protected] | |
|
||
\*******************************************************************/ | ||
|
||
#ifndef CPROVER_UTIL_INVARIANT_TYPES_H | ||
#define CPROVER_UTIL_INVARIANT_TYPES_H | ||
#ifndef CPROVER_UTIL_INVARIANT_UTILS_H | ||
#define CPROVER_UTIL_INVARIANT_UTILS_H | ||
|
||
#include "invariant.h" | ||
|
||
|
@@ -45,4 +45,4 @@ std::string pretty_print_invariant_with_irep( | |
#define DATA_INVARIANT_WITH_IREP(CONDITION, DESCRIPTION, IREP) \ | ||
INVARIANT_WITH_IREP((CONDITION), (DESCRIPTION), (IREP)) | ||
|
||
#endif | ||
#endif // CPROVER_UTIL_INVARIANT_UTILS_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ Author: Daniel Kroening, [email protected] | |
\*******************************************************************/ | ||
|
||
#include "parse_options.h" | ||
#include "exception_utils.h" | ||
|
||
#include <iostream> | ||
|
||
|
@@ -65,3 +66,31 @@ int parse_options_baset::main() | |
|
||
return doit(); | ||
} | ||
|
||
int parse_optionst::main() | ||
{ | ||
// catch all exceptions here so that this code is not duplicated | ||
// for each tool | ||
try | ||
{ | ||
return parse_options_baset::main(); | ||
} | ||
catch(const system_exceptiont &e) | ||
{ | ||
message.error() << e.what() << messaget::eom; | ||
} | ||
catch(const input_src_exceptiont &e) | ||
{ | ||
message.error().source_location=e.source_location; | ||
message.error() << e.what() << messaget::eom; | ||
} | ||
catch(const ui_exceptiont &e) | ||
{ | ||
message.error() << e.what() << messaget::eom; | ||
} | ||
catch(const invariant_failedt &e) | ||
{ | ||
message.error() << e.what() << messaget::eom; | ||
} | ||
return 6; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected] | |
#include <string> | ||
|
||
#include "cmdline.h" | ||
#include "message.h" | ||
|
||
class parse_options_baset | ||
{ | ||
|
@@ -35,4 +36,23 @@ class parse_options_baset | |
bool parse_result; | ||
}; | ||
|
||
class parse_optionst: public parse_options_baset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we could remove |
||
{ | ||
public: | ||
parse_optionst( | ||
const std::string &optstring, | ||
int argc, | ||
const char **argv, | ||
message_handlert &message_handler): | ||
parse_options_baset(optstring, argc, argv), | ||
message(message_handler) | ||
{ | ||
} | ||
|
||
int main() override; | ||
|
||
protected: | ||
messaget message; | ||
}; | ||
|
||
#endif // CPROVER_UTIL_PARSE_OPTIONS_H |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since all these exceptions are fatal and shouldn't be caught anywhere else, I wonder whether we should include the exit code in the exceptions. Then the different catch clauses would return via
return e.exit_code()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that could make some sense.