Skip to content

Commit 1ec7061

Browse files
authored
Merge pull request #4707 from tautschnig/nondet-body-fix
User-provided function definitions take precedence over built-ins
2 parents 3f9d063 + c08a090 commit 1ec7061

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

regression/cbmc/Function14/main.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
int nondet_foo()
2+
{
3+
return 42;
4+
}
5+
6+
int main()
7+
{
8+
int x = nondet_foo();
9+
__CPROVER_assert(x == 42, "nondet_foo returns a constant");
10+
}

regression/cbmc/Function14/test.desc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^VERIFICATION SUCCESSFUL$
7+
--
8+
^warning: ignoring

src/goto-programs/builtin_functions.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,22 @@ void goto_convertt::do_function_call_symbol(
651651
throw 0;
652652
}
653653

654+
// User-provided function definitions always take precedence over built-ins.
655+
// Front-ends do not (yet) consistently set ID_C_incomplete, thus also test
656+
// whether the symbol actually has some non-nil value (which might be
657+
// "compiled").
658+
if(!symbol->type.get_bool(ID_C_incomplete) && symbol->value.is_not_nil())
659+
{
660+
do_function_call_symbol(*symbol);
661+
662+
code_function_callt function_call(lhs, function, arguments);
663+
function_call.add_source_location() = function.source_location();
664+
665+
copy(function_call, FUNCTION_CALL, dest);
666+
667+
return;
668+
}
669+
654670
if(identifier==CPROVER_PREFIX "assume" ||
655671
identifier=="__VERIFIER_assume")
656672
{
@@ -706,7 +722,7 @@ void goto_convertt::do_function_call_symbol(
706722
a->source_location.set("user-provided", true);
707723
}
708724
else if(
709-
identifier == "assert" && symbol->type.get_bool(ID_C_incomplete) &&
725+
identifier == "assert" &&
710726
to_code_type(symbol->type).return_type() == signed_int_type())
711727
{
712728
if(arguments.size()!=1)

0 commit comments

Comments
 (0)