Skip to content

Commit a0308a5

Browse files
committed
Stop generating nondet pointees for function pointers
when building the entry point. Because that leads to declaring function-type objects and then assigning values to them. Rather we should simply initialise the function pointer with NONDET(fptr_type) and let the function-pointer removal find the candidates.
1 parent 077b5ee commit a0308a5

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <assert.h>
2+
3+
typedef int (*other_function_type)(int n);
4+
5+
void foo(other_function_type other_function)
6+
{
7+
// returning from the function call is unreachable -> the following assertion
8+
// should succeed
9+
assert(other_function(4) > 5);
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
main.c
3+
--function foo --pointer-check
4+
^\[foo.assertion.1\] line \d+ assertion other_function\(4\) > 5: SUCCESS$
5+
^\[foo.pointer_dereference.8\] line \d+ invalid function pointer: FAILURE$
6+
^EXIT=10$
7+
^SIGNAL=0$
8+
^VERIFICATION FAILED
9+
--
10+
^warning: ignoring

src/ansi-c/c_nondet_symbol_factory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void symbol_factoryt::gen_nondet_init(
4848
return;
4949
}
5050

51-
if(type.id()==ID_pointer)
51+
if(type.id() == ID_pointer && to_pointer_type(type).subtype().id() != ID_code)
5252
{
5353
// dereferenced type
5454
const pointer_typet &pointer_type=to_pointer_type(type);

src/goto-programs/remove_function_pointers.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,12 @@ void remove_function_pointerst::remove_function_pointer(
408408
goto_programt::make_goto(call, equal_exprt(pointer, casted_address)));
409409
}
410410

411-
// fall-through
412-
if(add_safety_assertion)
413-
{
414-
goto_programt::targett t =
415-
new_code_gotos.add(goto_programt::make_assertion(false_exprt()));
416-
t->source_location.set_property_class("pointer dereference");
417-
t->source_location.set_comment("invalid function pointer");
418-
}
411+
// fall-through: always on
412+
goto_programt::targett t =
413+
new_code_gotos.add(goto_programt::make_assertion(false_exprt()));
414+
t->source_location.set_property_class("pointer dereference");
415+
t->source_location.set_comment("invalid function pointer");
416+
419417
new_code_gotos.add(goto_programt::make_assumption(false_exprt()));
420418

421419
goto_programt new_code;

0 commit comments

Comments
 (0)