Skip to content

Fix based on review comments #5

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

Open
wants to merge 17 commits into
base: invariant_cleanup-goto_programs-jr
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion regression/goto-instrument/replace-calls-03/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CORE
main.c
--replace-calls f:g
Functions f and g are not type-compatible
^EXIT=11$
^EXIT=1$
^SIGNAL=0$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/goto-instrument/replace-calls-04/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CORE
main.c
--replace-calls f:g
Functions f and g are not type-compatible
^EXIT=11$
^EXIT=1$
^SIGNAL=0$
--
^warning: ignoring
2 changes: 1 addition & 1 deletion regression/goto-instrument/replace-calls-05/test.desc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ CORE
main.c
--replace-calls f:g --replace-calls h:f
Function f cannot both be replaced and be a replacement
^EXIT=11$
^EXIT=1$
^SIGNAL=0$
--
^warning: ignoring
29 changes: 15 additions & 14 deletions src/goto-programs/lazy_goto_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <langapi/language.h>

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

//! @cond Doxygen_suppress_Lambda_in_initializer_list
lazy_goto_modelt::lazy_goto_modelt(
Expand Down Expand Up @@ -94,8 +95,8 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)
const std::vector<std::string> &files=cmdline.args;
if(files.empty())
{
msg.error() << "Please provide a program" << messaget::eom;
throw 0;
throw invalid_user_input_exceptiont(
"no program provided", "cbmc file.c ...");
}

std::vector<std::string> binaries, sources;
Expand All @@ -122,9 +123,8 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)

if(!infile)
{
msg.error() << "failed to open input file `" << filename
<< '\'' << messaget::eom;
throw 0;
throw system_exceptiont(
"failed to open input file `" + filename + '\'');
}

language_filet &lf=add_language_file(filename);
Expand All @@ -135,8 +135,8 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)
source_locationt location;
location.set_file(filename);
msg.error().source_location=location;
msg.error() << "failed to figure out type of file" << messaget::eom;
throw 0;
throw incorrect_goto_program_exceptiont(
"failed to figure out type of file", location);
}

languaget &language=*lf.language;
Expand All @@ -147,8 +147,7 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)

if(language.parse(infile, filename))
{
msg.error() << "PARSING ERROR" << messaget::eom;
throw 0;
throw deserialization_exceptiont("language parsing failed");
}

lf.get_modules();
Expand All @@ -158,8 +157,8 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)

if(language_files.typecheck(symbol_table))
{
msg.error() << "CONVERSION ERROR" << messaget::eom;
throw 0;
throw deserialization_exceptiont(
"type-checking of interface/files/modules failed");
}
}

Expand All @@ -168,7 +167,10 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)
msg.status() << "Reading GOTO program from file" << messaget::eom;

if(read_object_and_link(file, *goto_model, message_handler))
throw 0;
{
throw deserialization_exceptiont(
"failed to read object or link in file `" + file + '\'');
}
}

bool binaries_provided_start =
Expand Down Expand Up @@ -203,8 +205,7 @@ void lazy_goto_modelt::initialize(const cmdlinet &cmdline)

if(entry_point_generation_failed)
{
msg.error() << "SUPPORT FUNCTION GENERATION ERROR" << messaget::eom;
throw 0;
throw deserialization_exceptiont("failed to generate entry point");
}

// stupid hack
Expand Down
25 changes: 15 additions & 10 deletions src/goto-programs/link_goto_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Author: Michael Tautschnig, Daniel Kroening
#include <util/rename_symbol.h>

#include <linking/linking_class.h>
#include <util/exception_utils.h>

#include "goto_model.h"

Expand Down Expand Up @@ -171,15 +172,19 @@ void link_goto_model(
message_handler);

if(linking.typecheck_main())
throw 0;

{
throw deserialization_exceptiont(
"failed to rename symbols during typechecking phase of linking");
}
if(link_functions(
dest.symbol_table,
dest.goto_functions,
src.symbol_table,
src.goto_functions,
linking.rename_symbol,
weak_symbols,
linking.object_type_updates))
throw 0;
dest.symbol_table,
dest.goto_functions,
src.symbol_table,
src.goto_functions,
linking.rename_symbol,
weak_symbols,
linking.object_type_updates))
{
throw deserialization_exceptiont("failed to link functions");
}
}
2 changes: 1 addition & 1 deletion src/goto-programs/loop_ids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void show_loop_ids_json(
const goto_programt &goto_program,
json_arrayt &loops)
{
assert(ui==ui_message_handlert::uit::JSON_UI); // use function above
PRECONDITION(ui == ui_message_handlert::uit::JSON_UI); // use function above

forall_goto_program_instructions(it, goto_program)
{
Expand Down
16 changes: 9 additions & 7 deletions src/goto-programs/osx_fat_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ Module: Read Mach-O

#include "osx_fat_reader.h"

#include <cassert>
#include <cstdlib>
#include <util/exception_utils.h>
#include <util/invariant.h>

#ifdef __APPLE__
#include <mach-o/fat.h>
Expand Down Expand Up @@ -46,10 +47,10 @@ osx_fat_readert::osx_fat_readert(std::ifstream &in) :
in.read(reinterpret_cast<char*>(&fh), sizeof(struct fat_header));

if(!in)
throw "failed to read OSX fat header";
throw system_exceptiont("failed to read OSX fat header");

if(!is_osx_fat_magic(reinterpret_cast<char*>(&(fh.magic))))
throw "OSX fat header malformed (magic)"; // NOLINT(readability/throw)
throw deserialization_exceptiont("OSX fat header malformed (magic)");

assert(sizeof(fh.nfat_arch)==4);
unsigned narch=__builtin_bswap32(fh.nfat_arch);
Expand All @@ -61,9 +62,10 @@ osx_fat_readert::osx_fat_readert(std::ifstream &in) :
// NOLINTNEXTLINE(readability/identifiers)
in.read(reinterpret_cast<char*>(&fa), sizeof(struct fat_arch));

assert(sizeof(fa.cputype)==4 &&
sizeof(fa.cpusubtype)==4 &&
sizeof(fa.size)==4);
static_assert(
sizeof(fa.cputype) == 4 && sizeof(fa.cpusubtype) == 4 &&
sizeof(fa.size) == 4,
"This requires a specific fat architecture");
int cputype=__builtin_bswap32(fa.cputype);
int cpusubtype=__builtin_bswap32(fa.cpusubtype);
unsigned size=__builtin_bswap32(fa.size);
Expand All @@ -79,7 +81,7 @@ bool osx_fat_readert::extract_gb(
const std::string &source,
const std::string &dest) const
{
assert(has_gb_arch);
PRECONDITION(has_gb_arch);

return run("lipo", {"lipo", "-thin", "hppa7100LC", "-output", dest, source});
}
2 changes: 1 addition & 1 deletion src/goto-programs/parameter_assignments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void parameter_assignmentst::do_function_calls(

// add x=y for f(y) where x is the parameter

assert(function_call.function().id()==ID_symbol);
PRECONDITION(function_call.function().id() == ID_symbol);

const irep_idt &identifier=
to_symbol_expr(function_call.function()).get_identifier();
Expand Down
27 changes: 14 additions & 13 deletions src/goto-programs/pointer_arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,33 @@ void pointer_arithmetict::read(const exprt &src)
}
else if(src.id()==ID_minus)
{
assert(src.operands().size()==2);
read(src.op0());
const unary_minus_exprt o(src.op1(), src.op1().type());
add_to_offset(o);
auto const &minus_src = to_minus_expr(src);
read(minus_src.op0());
const unary_minus_exprt unary_minus(
minus_src.op1(), minus_src.op1().type());
add_to_offset(unary_minus);
}
else if(src.id()==ID_address_of)
{
assert(src.operands().size()==1);
if(src.op0().id()==ID_index)
auto const &address_of_src = to_address_of_expr(src);
if(address_of_src.op().id() == ID_index)
{
const index_exprt &index_expr=
to_index_expr(src.op0());
const index_exprt &index_expr = to_index_expr(address_of_src.op());

if(index_expr.index().is_zero())
make_pointer(src);
make_pointer(address_of_src);
else
{
add_to_offset(index_expr.index());
// produce &x[0] + i instead of &x[i]
exprt new_src=src;
new_src.op0().op1()=from_integer(0, index_expr.index().type());
make_pointer(new_src);
auto new_address_of_src = address_of_src;
new_address_of_src.op().op1() =
from_integer(0, index_expr.index().type());
make_pointer(new_address_of_src);
}
}
else
make_pointer(src);
make_pointer(address_of_src);
}
else
make_pointer(src);
Expand Down
1 change: 0 additions & 1 deletion src/goto-programs/printf_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ Author: Daniel Kroening, kroening@kroening.com

#include "printf_formatter.h"

#include <cassert>
#include <sstream>

#include <util/c_types.h>
Expand Down
5 changes: 4 additions & 1 deletion src/goto-programs/read_bin_goto_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ static bool read_bin_goto_object_v4(
{
unsigned n=*nit;
rev_target_mapt::const_iterator entry=rev_target_map.find(n);
assert(entry!=rev_target_map.end());
INVARIANT(
entry != rev_target_map.end(),
"something from the target map should also be in the reverse target "
"map");
ins->targets.push_back(entry->second);
}
}
Expand Down
Loading