forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Convert assert calls to INVARIANTs #4
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
chrisr-diffblue
merged 1 commit into
chrisr-diffblue:cbmc-bookworm
from
hannes-steffenhagen-diffblue:fix-convert-asserts-to-invariants
Jul 6, 2018
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
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 |
---|---|---|
|
@@ -34,7 +34,8 @@ Author: Daniel Kroening, [email protected] | |
/// \return An smt2_dect::solvert giving the solver to use. | ||
smt2_dect::solvert cbmc_solverst::get_smt2_solver_type() const | ||
{ | ||
assert(options.get_bool_option("smt2")); | ||
// we shouldn't get here if this option isn't set | ||
PRECONDITION(options.get_bool_option("smt2")); | ||
|
||
smt2_dect::solvert s=smt2_dect::solvert::GENERIC; | ||
|
||
|
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 |
---|---|---|
|
@@ -139,15 +139,17 @@ goto_program_coverage_recordt::goto_program_coverage_recordt( | |
const symex_coveraget::coveraget &coverage): | ||
coverage_recordt("method") | ||
{ | ||
assert(gf_it->second.body_available()); | ||
PRECONDITION(gf_it->second.body_available()); | ||
|
||
// identify the file name, inlined functions aren't properly | ||
// accounted for | ||
goto_programt::const_targett end_function= | ||
--gf_it->second.body.instructions.end(); | ||
assert(end_function->is_end_function()); | ||
INVARIANT(end_function->is_end_function(), | ||
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. Could use |
||
"Last instruction in a function body is end function"); | ||
file_name=end_function->source_location.get_file(); | ||
assert(!file_name.empty()); | ||
INVARIANT(!file_name.empty(), | ||
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. Could use |
||
"Should have a valid source location"); | ||
|
||
// compute the maximum coverage of individual source-code lines | ||
coverage_lines_mapt coverage_lines_map; | ||
|
@@ -260,11 +262,14 @@ void goto_program_coverage_recordt::compute_coverage_lines( | |
for(const auto &cov : c_entry->second) | ||
std::cerr << cov.second.succ->location_number << '\n'; | ||
} | ||
assert(c_entry->second.size()==1 || is_branch); | ||
INVARIANT(c_entry->second.size()==1 || is_branch, | ||
"Instructions other than branch instructions have exactly 1 successor"); | ||
|
||
for(const auto &cov : c_entry->second) | ||
{ | ||
assert(cov.second.num_executions>0); | ||
INVARIANT(cov.second.num_executions>0, | ||
// FIXME I don't know what this means | ||
"Number of executions most be positive"); | ||
|
||
if(entry.first->second.hits==0) | ||
++lines_covered; | ||
|
@@ -275,7 +280,8 @@ void goto_program_coverage_recordt::compute_coverage_lines( | |
if(is_branch) | ||
{ | ||
auto cond_entry=entry.first->second.conditions.find(it); | ||
assert(cond_entry!=entry.first->second.conditions.end()); | ||
INVARIANT(cond_entry!=entry.first->second.conditions.end(), | ||
"Branch should have condition"); | ||
|
||
if(it->get_target()==cov.second.succ) | ||
{ | ||
|
@@ -439,7 +445,7 @@ bool symex_coveraget::generate_report( | |
const goto_functionst &goto_functions, | ||
const std::string &path) const | ||
{ | ||
assert(!path.empty()); | ||
PRECONDITION(!path.empty()); | ||
|
||
if(path=="-") | ||
return output_report(goto_functions, std::cout); | ||
|
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.
Hm this is not really a precondition of the function. I think in general it is fine to use
INVARIANT
even as the first statement in a function. But in the rest of the cbmc code base there are lots ofPRECONDITION
statements too that IMO should beINVARIANTS
s instead.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.
Can you explain what you mean by "not a precondition"? While the value in here isn't really needed for anything in the function, it's certainly something that should be true when we enter this function right?
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.
Hm I'm probably interpreting preconditions to narrowly. I basically took the view that a precondition is something that absolutely needs to hold when calling a function for it not to crash or produce garbage output. Like a function that unconditionally dereferences a pointer would have
ptr != nullptr
as a precondition, or a function that converts a string representing a binary number to an integer needs to get a string that contains only characters'0'
and'1'
(if it does not have built-in checks for this).But currently in the codebase we have several preconditions that are more of the kind "here's something that happens to hold when we enter this function as it's currently used but it's not necessarily related to the function itself". Technically the functions could be used in different ways in the future and for those uses the preconditions might not apply anymore.
But the present case above seems somewhat like a corner case so I don't mind if we leave it as a
PRECONDITION
.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.
Yeah, but we should probably dig up what the intended meaning is and get everyone to agree to it.