forked from diffblue/cbmc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check side effect of loop contracts during instrumentation
- Loading branch information
Showing
14 changed files
with
188 additions
and
61 deletions.
There are no files selected for viewing
This file contains 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
16 changes: 16 additions & 0 deletions
16
regression/contracts-dfcc/loop_contracts_statement_expression/main.c
This file contains 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,16 @@ | ||
int main() | ||
{ | ||
unsigned i; | ||
|
||
while(i > 1) | ||
__CPROVER_loop_invariant(({ | ||
unsigned b = i >= 1; | ||
goto label; | ||
b = i < 1; | ||
label: | ||
b; | ||
})) | ||
{ | ||
i--; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
regression/contracts-dfcc/loop_contracts_statement_expression/test.desc
This file contains 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,10 @@ | ||
CORE | ||
main.c | ||
--dfcc main --apply-loop-contracts --disable-side-effect-check | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
This test demonstrates a case where the loop invariant | ||
is a side-effect free statement expression. |
16 changes: 16 additions & 0 deletions
16
regression/contracts/loop_contracts_statement_expression/main.c
This file contains 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,16 @@ | ||
int main() | ||
{ | ||
unsigned i; | ||
|
||
while(i > 1) | ||
__CPROVER_loop_invariant(({ | ||
unsigned b = i >= 1; | ||
goto label; | ||
b = i < 1; | ||
label: | ||
b; | ||
})) | ||
{ | ||
i--; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
regression/contracts/loop_contracts_statement_expression/test.desc
This file contains 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,10 @@ | ||
CORE | ||
main.c | ||
--apply-loop-contracts --disable-side-effect-check | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
This test demonstrates a case where the loop invariant | ||
is a side-effect free statement expression. |
This file contains 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 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 |
---|---|---|
|
@@ -11,6 +11,8 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include "instrument_given_invariants.h" | ||
|
||
#include <util/expr_util.h> | ||
|
||
#include <goto-programs/goto_model.h> | ||
|
||
void instrument_given_invariants(goto_functionst::function_mapt::value_type &f) | ||
|
@@ -25,6 +27,15 @@ void instrument_given_invariants(goto_functionst::function_mapt::value_type &f) | |
{ | ||
const auto &invariants = static_cast<const exprt &>( | ||
it->condition().find(ID_C_spec_loop_invariant)); | ||
if(!invariants.is_nil()) | ||
{ | ||
if(has_subexpr(invariants, ID_side_effect)) | ||
{ | ||
throw incorrect_goto_program_exceptiont( | ||
"Loop invariant is not side-effect free.", | ||
it->condition().find_source_location()); | ||
} | ||
} | ||
|
||
for(const auto &invariant : invariants.operands()) | ||
{ | ||
|
This file contains 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 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 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 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 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
Oops, something went wrong.