Merge pull request #4707 from tautschnig/nondet-body-fix

User-provided function definitions take precedence over built-ins
This commit is contained in:
Michael Tautschnig 2019-05-30 13:22:21 +01:00 committed by GitHub
commit 1ec7061391
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -0,0 +1,10 @@
int nondet_foo()
{
return 42;
}
int main()
{
int x = nondet_foo();
__CPROVER_assert(x == 42, "nondet_foo returns a constant");
}

View File

@ -0,0 +1,8 @@
CORE
main.c
^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring

View File

@ -651,6 +651,22 @@ void goto_convertt::do_function_call_symbol(
throw 0;
}
// User-provided function definitions always take precedence over built-ins.
// Front-ends do not (yet) consistently set ID_C_incomplete, thus also test
// whether the symbol actually has some non-nil value (which might be
// "compiled").
if(!symbol->type.get_bool(ID_C_incomplete) && symbol->value.is_not_nil())
{
do_function_call_symbol(*symbol);
code_function_callt function_call(lhs, function, arguments);
function_call.add_source_location() = function.source_location();
copy(function_call, FUNCTION_CALL, dest);
return;
}
if(identifier==CPROVER_PREFIX "assume" ||
identifier=="__VERIFIER_assume")
{
@ -706,7 +722,7 @@ void goto_convertt::do_function_call_symbol(
a->source_location.set("user-provided", true);
}
else if(
identifier == "assert" && symbol->type.get_bool(ID_C_incomplete) &&
identifier == "assert" &&
to_code_type(symbol->type).return_type() == signed_int_type())
{
if(arguments.size()!=1)