Skip to content

User-provided function definitions take precedence over built-ins #4707

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
merged 1 commit into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions regression/cbmc/Function14/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
int nondet_foo()
{
return 42;
}

int main()
{
int x = nondet_foo();
__CPROVER_assert(x == 42, "nondet_foo returns a constant");
}
8 changes: 8 additions & 0 deletions regression/cbmc/Function14/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.c

^EXIT=0$
^SIGNAL=0$
^VERIFICATION SUCCESSFUL$
--
^warning: ignoring
18 changes: 17 additions & 1 deletion src/goto-programs/builtin_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,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")
{
Expand Down Expand Up @@ -702,7 +718,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)
Expand Down