Skip to content

Commit 54e80da

Browse files
author
Daniel Kroening
committed
added __CPROVER_precondtion(c, d)
1 parent 1d81035 commit 54e80da

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

src/ansi-c/ansi_c_internal_additions.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ void ansi_c_internal_additions(std::string &code)
112112
"void __VERIFIER_assume(__CPROVER_bool assumption);\n"
113113
// NOLINTNEXTLINE(whitespace/line_length)
114114
"void __CPROVER_assert(__CPROVER_bool assertion, const char *description);\n"
115+
// NOLINTNEXTLINE(whitespace/line_length)
116+
"void __CPROVER_precondition(__CPROVER_bool precondition, const char *description);\n"
115117
"__CPROVER_bool __CPROVER_equal();\n"
116118
"__CPROVER_bool __CPROVER_same_object(const void *, const void *);\n"
117119
"__CPROVER_bool __CPROVER_invalid_pointer(const void *);\n"

src/ansi-c/library/cprover.h

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern const void *__CPROVER_memory_leak;
1919

2020
void __CPROVER_assume(__CPROVER_bool assumption) __attribute__((__noreturn__));
2121
void __CPROVER_assert(__CPROVER_bool assertion, const char *description);
22+
void __CPROVER_precondition(__CPROVER_bool assertion, const char *description);
2223

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

src/goto-programs/builtin_functions.cpp

+18-5
Original file line numberDiff line numberDiff line change
@@ -1113,7 +1113,8 @@ void goto_convertt::do_function_call_symbol(
11131113
throw 0;
11141114
}
11151115
}
1116-
else if(identifier==CPROVER_PREFIX "assert")
1116+
else if(identifier==CPROVER_PREFIX "assert" ||
1117+
identifier==CPROVER_PREFIX "precondition")
11171118
{
11181119
if(arguments.size()!=2)
11191120
{
@@ -1123,16 +1124,28 @@ void goto_convertt::do_function_call_symbol(
11231124
throw 0;
11241125
}
11251126

1127+
bool is_precondition=
1128+
identifier==CPROVER_PREFIX "precondition";
1129+
11261130
const irep_idt description=
11271131
get_string_constant(arguments[1]);
11281132

11291133
goto_programt::targett t=dest.add_instruction(ASSERT);
11301134
t->guard=arguments[0];
11311135
t->source_location=function.source_location();
1132-
t->source_location.set(
1133-
"user-provided",
1134-
!function.source_location().is_built_in());
1135-
t->source_location.set_property_class(ID_assertion);
1136+
1137+
if(is_precondition)
1138+
{
1139+
t->source_location.set_property_class(ID_precondition);
1140+
}
1141+
else
1142+
{
1143+
t->source_location.set(
1144+
"user-provided",
1145+
!function.source_location().is_built_in());
1146+
t->source_location.set_property_class(ID_assertion);
1147+
}
1148+
11361149
t->source_location.set_comment(description);
11371150

11381151
// let's double-check the type of the argument

src/util/irep_ids.def

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ IREP_ID_ONE(assign_bitor)
9090
IREP_ID_ONE(assume)
9191
IREP_ID_ONE(assert)
9292
IREP_ID_ONE(assertion)
93+
IREP_ID_ONE(precondition)
9394
IREP_ID_ONE(goto)
9495
IREP_ID_ONE(gcc_computed_goto)
9596
IREP_ID_ONE(ifthenelse)

0 commit comments

Comments
 (0)