-
Notifications
You must be signed in to change notification settings - Fork 273
Improvements to code contracts [depends-on: #2646, #2676, blocks: #2712] #2677
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
Changes from all commits
4d87ce9
7f891d0
10e55d8
e7fc244
55c66a5
d2be8ef
d4e5821
208a4fe
02eb459
63b2af3
2ec8f88
d9480d4
522c765
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
int foo() | ||
__CPROVER_ensures(__CPROVER_forall {int i; 1 == 1}) | ||
{ | ||
return 1; | ||
} | ||
|
||
int bar() | ||
__CPROVER_ensures(__CPROVER_forall {int i; 1 == 1} && | ||
__CPROVER_return_value == 1) | ||
{ | ||
return 1; | ||
} | ||
|
||
int main() { | ||
foo(); | ||
bar(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
CORE | ||
main.c | ||
|
||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
-- | ||
^warning: ignoring | ||
^CONVERSION ERROR$ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
KNOWNBUG | ||
CORE | ||
main.c | ||
--apply-code-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
Applying code contracts currently also checks them. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
CORE | ||
main.c | ||
--apply-code-contracts | ||
--check-code-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
--check-code-contracts not implemented yet. | ||
--apply-code-contracts is the current name for the flag. This should be | ||
updated as the flag changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
CORE | ||
main.c | ||
--apply-code-contracts | ||
--check-code-contracts | ||
^\[main.assertion.1\] assertion x == 0: SUCCESS$ | ||
^\[foo.1\] : FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
-- | ||
--check-code-contracts not implemented yet. | ||
--apply-code-contracts is the current name for the flag. This should be | ||
updated as the flag changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
KNOWNBUG | ||
CORE | ||
main.c | ||
--check-code-contracts | ||
^\[main.assertion.1\] assertion y == 0: FAILURE$ | ||
^\[main.assertion.2\] assertion z == 1: SUCCESS$ | ||
^\[foo.1\] : SUCCESS$ | ||
^VERIFICATION SUCCESSFUL$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
-- | ||
Contract checking does not properly havoc function calls. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.c | ||
--check-code-contracts | ||
^EXIT=0$ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
CORE | ||
main.c | ||
--apply-code-contracts | ||
--check-code-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
--check-code-contracts not implemented yet. | ||
--apply-code-contracts is the current name for the flag. This should be | ||
updated as the flag changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
CORE | ||
main.c | ||
--apply-code-contracts | ||
--check-code-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
--check-code-contracts not implemented yet. | ||
--apply-code-contracts is the current name for the flag. This should be | ||
updated as the flag changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
CORE | ||
main.c | ||
--apply-code-contracts | ||
--check-code-contracts | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
-- | ||
--check-code-contracts not implemented yet. | ||
--apply-code-contracts is the current name for the flag. This should be | ||
updated as the flag changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,9 @@ | ||
CORE | ||
main.c | ||
--apply-code-contracts | ||
--check-code-contracts | ||
^\[main.1\] Loop invariant violated before entry: SUCCESS$ | ||
^\[main.2\] Loop invariant not preserved: SUCCESS$ | ||
^\[main.assertion.1\] assertion r == 0: FAILURE$ | ||
^VERIFICATION FAILED$ | ||
-- | ||
-- | ||
--check-code-contracts not implemented yet. | ||
--apply-code-contracts is the current name for the flag. This should be | ||
updated as the flag changes. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
KNOWNBUG | ||
CORE | ||
main.c | ||
--full-slice | ||
^EXIT=0$ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
static void f(int *x) { *x = 5; } | ||
static void g(int *x) { assert(*x == 5); } | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int *x = (int*)malloc(sizeof(int)); | ||
f(x); | ||
g(x); | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
KNOWNBUG | ||
main.c | ||
--full-slice --add-library | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
Data dependencies across function calls are still not working correctly. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,7 +175,9 @@ void dep_graph_domaint::data_dependencies( | |
{ | ||
bool found=false; | ||
for(const auto &wr : w_range.second) | ||
{ | ||
for(const auto &r_range : r_ranges) | ||
{ | ||
if(!found && | ||
may_be_def_use_pair(wr.first, wr.second, | ||
r_range.first, r_range.second)) | ||
|
@@ -184,6 +186,8 @@ void dep_graph_domaint::data_dependencies( | |
data_deps.insert(w_range.first); | ||
found=true; | ||
} | ||
} | ||
} | ||
} | ||
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. The change to this file appears unrelated. |
||
|
||
dep_graph.reaching_definitions()[to].clear_cache(it->first); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,8 +128,6 @@ void rw_range_sett::get_objects_dereference( | |
{ | ||
const exprt &pointer=deref.pointer(); | ||
get_objects_rec(get_modet::READ, pointer); | ||
if(mode!=get_modet::READ) | ||
get_objects_rec(mode, pointer); | ||
} | ||
|
||
void rw_range_sett::get_objects_byte_extract( | ||
|
@@ -414,16 +412,19 @@ void rw_range_sett::get_objects_typecast( | |
|
||
void rw_range_sett::get_objects_address_of(const exprt &object) | ||
{ | ||
if(object.id() == ID_string_constant || | ||
if(object.id() == ID_symbol || | ||
object.id() == ID_string_constant || | ||
object.id() == ID_label || | ||
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. The ID_symbol case overrides the case below. |
||
object.id() == ID_array || | ||
object.id() == ID_null_object) | ||
// constant, nothing to do | ||
{ | ||
return; | ||
else if(object.id()==ID_symbol) | ||
get_objects_rec(get_modet::READ, object); | ||
} | ||
else if(object.id()==ID_dereference) | ||
{ | ||
get_objects_rec(get_modet::READ, object); | ||
} | ||
else if(object.id()==ID_index) | ||
{ | ||
const index_exprt &index=to_index_expr(object); | ||
|
@@ -524,6 +525,11 @@ void rw_range_sett::get_objects_rec( | |
get_objects_array(mode, to_array_expr(expr), range_start, size); | ||
else if(expr.id()==ID_struct) | ||
get_objects_struct(mode, to_struct_expr(expr), range_start, size); | ||
else if(expr.id()==ID_dynamic_object) | ||
{ | ||
const auto obj_instance = to_dynamic_object_expr(expr).get_instance(); | ||
add(mode, "goto_rw::dynamic_object-" + std::to_string(obj_instance), 0, -1); | ||
} | ||
else if(expr.id()==ID_symbol) | ||
{ | ||
const symbol_exprt &symbol=to_symbol_expr(expr); | ||
|
@@ -564,11 +570,6 @@ void rw_range_sett::get_objects_rec( | |
{ | ||
// dereferencing may yield some weird ones, ignore these | ||
} | ||
else if(mode==get_modet::LHS_W) | ||
{ | ||
forall_operands(it, expr) | ||
get_objects_rec(mode, *it); | ||
} | ||
else | ||
throw "rw_range_sett: assignment to `"+expr.id_string()+"' not handled"; | ||
} | ||
|
@@ -605,6 +606,8 @@ void rw_range_set_value_sett::get_objects_dereference( | |
exprt object=deref; | ||
dereference(target, object, ns, value_sets); | ||
|
||
PRECONDITION(object.is_not_nil()); | ||
|
||
range_spect new_size= | ||
to_range_spect(pointer_offset_bits(object.type(), ns)); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2141,7 +2141,7 @@ exprt c_typecheck_baset::do_special_functions( | |
throw 0; | ||
} | ||
|
||
exprt dynamic_object_expr=exprt(ID_dynamic_object, expr.type()); | ||
exprt dynamic_object_expr=exprt(ID_is_dynamic_object, expr.type()); | ||
dynamic_object_expr.operands()=expr.arguments(); | ||
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. Use is_dynamic_object_exprt, which you are adding. |
||
dynamic_object_expr.add_source_location()=source_location; | ||
|
||
|
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.
Is this not redundant with the above?