Skip to content

Cleanup error handling of cbmc/ folder #2703

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

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cbmc/bmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Author: Daniel Kroening, [email protected]
#include <chrono>
#include <iostream>

#include <util/exception_utils.h>
#include <util/exit_codes.h>

#include <langapi/language_util.h>
Expand Down Expand Up @@ -214,9 +215,8 @@ void bmct::get_memory_model()
memory_model=util_make_unique<memory_model_psot>(ns);
else
{
error() << "Invalid memory model " << mm
<< " -- use one of sc, tso, pso" << eom;
throw "invalid memory model";
throw invalid_user_input_exceptiont(
"invalid parameter " + mm, "--mm", "try values of sc, tso, pso");
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/cbmc/bmc_cover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ bool bmc_covert::operator()()
cover_goals.add(l);
}

INVARIANT(
cover_goals.size() == goal_map.size(), "we add coverage for each goal");
INVARIANT(cover_goals.size() == goal_map.size(),
"we add coverage for each goal");


status() << "Running " << solver.decision_procedure_text() << eom;
Expand Down
40 changes: 29 additions & 11 deletions src/cbmc/cbmc_solvers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ Author: Daniel Kroening, [email protected]
#include <fstream>
#include <iostream>
#include <memory>
#include <string>

#include <util/exception_utils.h>
#include <util/make_unique.h>
#include <util/unicode.h>
#include <util/version.h>
Expand Down Expand Up @@ -164,8 +166,10 @@ std::unique_ptr<cbmc_solverst::solvert> cbmc_solverst::get_smt2(
{
if(solver==smt2_dect::solvert::GENERIC)
{
error() << "please use --outfile" << eom;
throw 0;
throw invalid_user_input_exceptiont(
"required filename not provided",
"--outfile",
"provide a filename with --outfile");
}

auto smt2_dec = util_make_unique<smt2_dect>(
Expand Down Expand Up @@ -207,8 +211,8 @@ std::unique_ptr<cbmc_solverst::solvert> cbmc_solverst::get_smt2(

if(!*out)
{
error() << "failed to open " << filename << eom;
throw 0;
throw invalid_user_input_exceptiont(
"failed to open file: " + filename, "--outfile");
}

auto smt2_conv = util_make_unique<smt2_convt>(
Expand All @@ -232,18 +236,32 @@ void cbmc_solverst::no_beautification()
{
if(options.get_bool_option("beautify"))
{
error() << "sorry, this solver does not support beautification" << eom;
throw 0;
throw invalid_user_input_exceptiont(
"the chosen solver does not support beautification", "--beautify");
}
}

void cbmc_solverst::no_incremental_check()
{
if(options.get_bool_option("all-properties") ||
options.get_option("cover")!="" ||
options.get_option("incremental-check")!="")
const bool all_properties = options.get_bool_option("all-properties");
const bool cover = options.is_set("cover");
const bool incremental_check = options.is_set("incremental-check");

if(all_properties)
{
throw invalid_user_input_exceptiont(
"the chosen solver does not support incremental solving",
"--all_properties");
}
else if(cover)
{
throw invalid_user_input_exceptiont(
"the chosen solver does not support incremental solving", "--cover");
}
else if(incremental_check)
{
error() << "sorry, this solver does not support incremental solving" << eom;
throw 0;
throw invalid_user_input_exceptiont(
"the chosen solver does not support incremental solving",
"--incremental-check");
}
}
4 changes: 2 additions & 2 deletions src/cbmc/cbmc_solvers.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ class cbmc_solverst:public messaget

prop_convt &prop_conv() const
{
PRECONDITION(prop_conv_ptr!=nullptr);
PRECONDITION(prop_conv_ptr != nullptr);
return *prop_conv_ptr;
}

propt &prop() const
{
PRECONDITION(prop_ptr!=nullptr);
PRECONDITION(prop_ptr != nullptr);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is still in the wrong commit, fixing up a change from an earlier commit.

return *prop_ptr;
}

Expand Down
4 changes: 4 additions & 0 deletions src/util/exception_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ Author: Fotis Koutoulakis, [email protected]

class invalid_user_input_exceptiont
{
/// The reason this exception was generated.
std::string reason;
/// The full command line option (not the argument) that got
/// erroneous input.
std::string option;
/// In case we have samples of correct input to the option.
std::string correct_input;

public:
Expand Down