-
Notifications
You must be signed in to change notification settings - Fork 277
Interpreter: replace assert by invariants #1281
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
kroening
merged 1 commit into
diffblue:develop
from
tautschnig:interpreter-assert-cleanup
Aug 29, 2017
Merged
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ Author: Daniel Kroening, kroening@kroening.com | |
#include <algorithm> | ||
#include <string.h> | ||
|
||
#include <util/invariant.h> | ||
#include <util/std_types.h> | ||
#include <util/symbol_table.h> | ||
#include <util/ieee_float.h> | ||
|
@@ -380,7 +381,9 @@ void interpretert::execute_other() | |
const irep_idt &statement=pc->code.get_statement(); | ||
if(statement==ID_expression) | ||
{ | ||
assert(pc->code.operands().size()==1); | ||
DATA_INVARIANT( | ||
pc->code.operands().size()==1, | ||
"expression statement expected to have one operand"); | ||
mp_vectort rhs; | ||
evaluate(pc->code.op0(), rhs); | ||
} | ||
|
@@ -409,7 +412,7 @@ void interpretert::execute_other() | |
|
||
void interpretert::execute_decl() | ||
{ | ||
assert(pc->code.get_statement()==ID_decl); | ||
PRECONDITION(pc->code.get_statement()==ID_decl); | ||
} | ||
|
||
/// retrieves the member at offset | ||
|
@@ -515,7 +518,7 @@ exprt interpretert::get_value( | |
std::size_t offset) | ||
{ | ||
const typet real_type=ns.follow(type); | ||
assert(!rhs.empty()); | ||
PRECONDITION(!rhs.empty()); | ||
|
||
if(real_type.id()==ID_struct) | ||
{ | ||
|
@@ -807,7 +810,6 @@ void interpretert::execute_function_call() | |
const code_typet::parametert &a=parameters[i]; | ||
exprt symbol_expr(ID_symbol, a.type()); | ||
symbol_expr.set(ID_identifier, a.get_identifier()); | ||
assert(i<argument_values.size()); | ||
assign(evaluate_address(symbol_expr), argument_values[i]); | ||
} | ||
|
||
|
@@ -822,8 +824,8 @@ void interpretert::execute_function_call() | |
if(it!=function_input_vars.end()) | ||
{ | ||
mp_vectort value; | ||
assert(!it->second.empty()); | ||
assert(!it->second.front().return_assignments.empty()); | ||
PRECONDITION(!it->second.empty()); | ||
PRECONDITION(!it->second.front().return_assignments.empty()); | ||
evaluate(it->second.front().return_assignments.back().value, value); | ||
if(return_value_address>0) | ||
{ | ||
|
@@ -1011,7 +1013,8 @@ size_t interpretert::get_size(const typet &type) | |
// overflow behaviour. | ||
exprt size_const=from_integer(i[0], size_expr.type()); | ||
mp_integer size_mp; | ||
assert(!to_integer(size_const, size_mp)); | ||
bool ret=to_integer(size_const, size_mp); | ||
CHECK_RETURN(!ret); | ||
return subtype_size*integer2unsigned(size_mp); | ||
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. A classic. |
||
} | ||
return subtype_size; | ||
|
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
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 |
---|---|---|
|
@@ -12,9 +12,10 @@ Author: Romain Brenguier | |
#ifndef CPROVER_UTIL_SPARSE_VECTOR_H | ||
#define CPROVER_UTIL_SPARSE_VECTOR_H | ||
|
||
#include "invariant.h" | ||
|
||
#include <cstdint> | ||
#include <map> | ||
#include <assert.h> | ||
|
||
template<class T> class sparse_vectort | ||
{ | ||
|
@@ -29,13 +30,13 @@ template<class T> class sparse_vectort | |
|
||
const T &operator[](uint64_t idx) const | ||
{ | ||
assert(idx<_size && "index out of range"); | ||
INVARIANT(idx<_size, "index out of range"); | ||
return underlying[idx]; | ||
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. These are really preconditions... |
||
} | ||
|
||
T &operator[](uint64_t idx) | ||
{ | ||
assert(idx<_size && "index out of range"); | ||
INVARIANT(idx<_size, "index out of range"); | ||
return underlying[idx]; | ||
} | ||
|
||
|
@@ -46,7 +47,7 @@ template<class T> class sparse_vectort | |
|
||
void resize(uint64_t new_size) | ||
{ | ||
assert(new_size>=_size && "sparse vector can't be shrunk (yet)"); | ||
INVARIANT(new_size>=_size, "sparse vector can't be shrunk (yet)"); | ||
_size=new_size; | ||
} | ||
|
||
|
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.
I would actually prefer to_code_expression(pc->code).expression() instead of the invariant/assertion here