Skip to content

Commit f41d20d

Browse files
committed
Add a __CPROVER_postcondition builtin
The added builtin function, is transformed into an assert (like __CPROVER_precondition) by the goto-cc pass. The reason why it was added, is to allow an analysis on the AST to extract the postconditions from function bodies, to extend their function contracts.
1 parent 5d2e8b9 commit f41d20d

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

src/ansi-c/cprover_builtin_headers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ void __CPROVER_assume(__CPROVER_bool assumption);
22
void __VERIFIER_assume(__CPROVER_bool assumption);
33
void __CPROVER_assert(__CPROVER_bool assertion, const char *description);
44
void __CPROVER_precondition(__CPROVER_bool precondition, const char *description);
5+
void __CPROVER_postcondition(__CPROVER_bool assertion, const char *description);
56
void __CPROVER_havoc_object(void *);
67
__CPROVER_bool __CPROVER_equal();
78
__CPROVER_bool __CPROVER_same_object(const void *, const void *);

src/ansi-c/library/cprover.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern const void *__CPROVER_memory_leak;
2020
void __CPROVER_assume(__CPROVER_bool assumption) __attribute__((__noreturn__));
2121
void __CPROVER_assert(__CPROVER_bool assertion, const char *description);
2222
void __CPROVER_precondition(__CPROVER_bool assertion, const char *description);
23+
void __CPROVER_postcondition(__CPROVER_bool assertion, const char *description);
2324

2425
__CPROVER_bool __CPROVER_is_zero_string(const void *);
2526
__CPROVER_size_t __CPROVER_zero_string_length(const void *);

src/cpp/library/cprover.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern const void *__CPROVER_memory_leak;
2121
void __CPROVER_assume(__CPROVER_bool assumption) __attribute__((__noreturn__));
2222
void __CPROVER_assert(__CPROVER_bool assertion, const char *description);
2323
void __CPROVER_precondition(__CPROVER_bool assertion, const char *description);
24+
void __CPROVER_postcondition(__CPROVER_bool assertion, const char *description);
2425

2526
// NOLINTNEXTLINE(build/deprecated)
2627
void __CPROVER_input(const char *description, ...);

src/goto-programs/builtin_functions.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,8 @@ void goto_convertt::do_function_call_symbol(
736736
}
737737
}
738738
else if(identifier==CPROVER_PREFIX "assert" ||
739-
identifier==CPROVER_PREFIX "precondition")
739+
identifier==CPROVER_PREFIX "precondition" ||
740+
identifier==CPROVER_PREFIX "postcondition")
740741
{
741742
if(arguments.size()!=2)
742743
{
@@ -747,6 +748,8 @@ void goto_convertt::do_function_call_symbol(
747748

748749
bool is_precondition=
749750
identifier==CPROVER_PREFIX "precondition";
751+
bool is_postcondition=
752+
identifier==CPROVER_PREFIX "postcondition";
750753

751754
const irep_idt description=
752755
get_string_constant(arguments[1]);
@@ -760,6 +763,10 @@ void goto_convertt::do_function_call_symbol(
760763
{
761764
t->source_location.set_property_class(ID_precondition);
762765
}
766+
else if(is_postcondition)
767+
{
768+
t->source_location.set_property_class(ID_postcondition);
769+
}
763770
else
764771
{
765772
t->source_location.set(

src/util/irep_ids.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ IREP_ID_ONE(assume)
8989
IREP_ID_ONE(assert)
9090
IREP_ID_ONE(assertion)
9191
IREP_ID_ONE(precondition)
92+
IREP_ID_ONE(postcondition)
9293
IREP_ID_ONE(precondition_instance)
9394
IREP_ID_ONE(goto)
9495
IREP_ID_ONE(gcc_computed_goto)

0 commit comments

Comments
 (0)