-
Notifications
You must be signed in to change notification settings - Fork 274
CONTRACTS: Allow void function calls in assigns clauses #7214
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
feliperodri
merged 1 commit into
diffblue:develop
from
remi-delmas-3000:contracts-assigns-clause-allow-all-void-function-calls
Oct 7, 2022
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
2 changes: 1 addition & 1 deletion
2
regression/contracts/assigns_enforce_conditional_non_lvalue_target/test.desc
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
2 changes: 1 addition & 1 deletion
2
regression/contracts/assigns_enforce_conditional_non_lvalue_target_list/test.desc
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 |
---|---|---|
|
@@ -13,5 +13,4 @@ int main() | |
{ | ||
int x; | ||
foo(&x); | ||
baz(&x); | ||
} |
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
17 changes: 17 additions & 0 deletions
17
regression/contracts/assigns_enforce_function_calls_ignored/main.c
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
void bar(int *x) | ||
{ | ||
if(x) | ||
__CPROVER_typed_target(x); | ||
} | ||
|
||
int foo(int *x) __CPROVER_assigns(bar(x)) | ||
{ | ||
*x = 0; | ||
return 0; | ||
} | ||
|
||
int main() | ||
{ | ||
int x; | ||
foo(&x); | ||
} |
10 changes: 10 additions & 0 deletions
10
regression/contracts/assigns_enforce_function_calls_ignored/test.desc
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
CORE | ||
main.c | ||
--enforce-contract foo | ||
^call to function 'bar' in assigns clause not supported yet$ | ||
^EXIT=(127|134)$ | ||
^SIGNAL=0$ | ||
-- | ||
-- | ||
Check that void function call expressions in assigns clauses make | ||
instrumentation fail. |
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
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
2 changes: 1 addition & 1 deletion
2
regression/contracts/reject_history_expr_in_assigns_clause/test.desc
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 |
---|---|---|
|
@@ -995,34 +995,34 @@ void c_typecheck_baset::typecheck_spec_assigns_target(exprt &target) | |
else if(can_cast_expr<side_effect_expr_function_callt>(target)) | ||
{ | ||
const auto &funcall = to_side_effect_expr_function_call(target); | ||
if(can_cast_expr<symbol_exprt>(funcall.function())) | ||
if(!can_cast_expr<symbol_exprt>(funcall.function())) | ||
{ | ||
const auto &ident = to_symbol_expr(funcall.function()).get_identifier(); | ||
if( | ||
ident == CPROVER_PREFIX "assignable" || | ||
ident == CPROVER_PREFIX "object_whole" || | ||
ident == CPROVER_PREFIX "object_upto" || | ||
ident == CPROVER_PREFIX "object_from") | ||
{ | ||
for(const auto &argument : funcall.arguments()) | ||
throw_on_side_effects(argument); | ||
return; | ||
} | ||
throw invalid_source_file_exceptiont( | ||
"function pointer calls not allowed in assigns clauses", | ||
target.source_location()); | ||
} | ||
else | ||
|
||
if(target.type().id() != ID_empty) | ||
{ | ||
throw invalid_source_file_exceptiont( | ||
"function pointer calls not allowed in assigns clauses", | ||
"expecting void return type for function '" + | ||
id2string(to_symbol_expr(funcall.function()).get_identifier()) + | ||
"' called in assigns clause", | ||
target.source_location()); | ||
} | ||
|
||
for(const auto &argument : funcall.arguments()) | ||
throw_on_side_effects(argument); | ||
} | ||
else | ||
{ | ||
// if we reach this point the target did not pass the checks | ||
throw invalid_source_file_exceptiont( | ||
"assigns clause target must be a non-void lvalue, a call " | ||
"to " CPROVER_PREFIX | ||
"POINTER_OBJECT or a call to a function returning void", | ||
Comment on lines
+1022
to
+1023
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. Why do we need to remove here all |
||
target.source_location()); | ||
} | ||
// if we reach this point the target did not pass the checks | ||
throw invalid_source_file_exceptiont( | ||
"assigns clause target must be a non-void lvalue or a call to one " | ||
"of " CPROVER_PREFIX "POINTER_OBJECT, " CPROVER_PREFIX | ||
"assignable, " CPROVER_PREFIX "object_whole, " CPROVER_PREFIX | ||
"object_upto, " CPROVER_PREFIX "object_from", | ||
target.source_location()); | ||
} | ||
|
||
void c_typecheck_baset::typecheck_spec_function_pointer_obeys_contract( | ||
|
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
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.
Could we add a regression test to cover this case?