Skip to content

Commit 86c8181

Browse files
committed
Enable the function-pointer fall-back assertion by default
Function pointer removal may be done implicitly as required by some other operation that the user intended to do. If so, the user would not know that they need to specify --pointer-check at that point. Therefore, enable the `ASSERT(false)` in the `else` branch of function pointer removal unconditionally.
1 parent 04895f3 commit 86c8181

File tree

14 files changed

+26
-45
lines changed

14 files changed

+26
-45
lines changed

jbmc/src/jdiff/jdiff_parse_options.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,7 @@ bool jdiff_parse_optionst::process_goto_program(
172172
// remove function pointers
173173
log.status() << "Removing function pointers and virtual functions"
174174
<< messaget::eom;
175-
remove_function_pointers(
176-
ui_message_handler, goto_model, cmdline.isset("pointer-check"), false);
175+
remove_function_pointers(ui_message_handler, goto_model, false);
177176

178177
// Java virtual functions -> explicit dispatch tables:
179178
remove_virtual_functions(goto_model);

regression/cbmc-concurrency/pthread_join1/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ main.c
55
^SIGNAL=0$
66
^\[main\.assertion\.1\] line 21 assertion i==1: FAILURE$
77
^\[main\.assertion\.2\] line 22 assertion i==2: SUCCESS$
8-
^\*\* 1 of 2 failed
8+
^\*\* 1 of 3 failed
99
--
1010
^warning: ignoring

regression/cbmc-library/pthread_cond_wait-01/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ main.c
33
--bounds-check
44
^EXIT=10$
55
^SIGNAL=0$
6-
^\*\* 1 of 2 failed
6+
^\*\* 1 of 3 failed
77
^VERIFICATION FAILED$
88
--
99
^warning: ignoring
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
CORE
22
main.c
33

4-
^EXIT=0$
4+
^EXIT=10$
55
^SIGNAL=0$
66
\[f2.assertion.1\] line [0-9]+ assertion 0: SUCCESS
7+
\[main.pointer_dereference.1\] line 28 dereferenced function pointer must be f2: FAILURE$
78
\[main.assertion.1\] line [0-9]+ assertion x == 1: SUCCESS
89
\[main.assertion.2\] line [0-9]+ assertion x == 2: SUCCESS
9-
^VERIFICATION SUCCESSFUL$
10+
^VERIFICATION FAILED$
1011
--
1112
^warning: ignoring

regression/cbmc/Linking7/member-name-mismatch.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ module2.c
66
^VERIFICATION FAILED$
77
line 21 assertion \*g\.a == 42: SUCCESS
88
line 22 assertion \*g\.c == 41: FAILURE
9-
^\*\* 1 of 2 failed
9+
^\*\* 1 of 3 failed
1010
--
1111
^warning: ignoring

regression/cbmc/Linking7/test.desc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.c
44
^EXIT=10$
55
^SIGNAL=0$
66
^VERIFICATION FAILED$
7-
^\*\* 1 of 2 failed
7+
^\*\* 1 of 3 failed
88
line 21 assertion \*g\.a == 42: SUCCESS
99
line 22 assertion \*g\.b == 41: FAILURE
1010
--

regression/goto-instrument/value-set-fi-fp-removal4/test.desc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
CORE
22
test.c
33
--value-set-fi-fp-removal
4-
^EXIT=0$
4+
^EXIT=10$
55
^SIGNAL=0$
66
^file test.c line 20 function main: replacing function pointer by 2 possible targets$
7+
\[main.pointer_dereference.1\] line 20 dereferenced function pointer must be one of \[(g, f|f, g)\]: FAILURE$
8+
--
79
--
810
This test checks that the value-set-fi-based function pointer removal
911
precisely identifies the function to call for a particular function pointer

regression/goto-instrument/value-set-fi-fp-removal5/test.desc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
CORE
22
test.c
33
--value-set-fi-fp-removal
4-
^EXIT=0$
4+
^EXIT=10$
55
^SIGNAL=0$
66
^file test.c line 19 function main: replacing function pointer by 0 possible targets$
7+
\[main.pointer_dereference.1\] line 19 no candidates for dereferenced function pointer: FAILURE$
8+
--
79
--
810
This test checks that the value-set-fi-based function pointer removal
911
precisely identifies the function to call for a particular function pointer

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -945,8 +945,7 @@ void goto_instrument_parse_optionst::do_indirect_call_and_rtti_removal(
945945
function_pointer_removal_done=true;
946946

947947
log.status() << "Function Pointer Removal" << messaget::eom;
948-
remove_function_pointers(
949-
ui_message_handler, goto_model, cmdline.isset("pointer-check"), false);
948+
remove_function_pointers(ui_message_handler, goto_model, false);
950949
log.status() << "Virtual function removal" << messaget::eom;
951950
remove_virtual_functions(goto_model);
952951
log.status() << "Cleaning inline assembler statements" << messaget::eom;
@@ -969,7 +968,6 @@ void goto_instrument_parse_optionst::do_remove_const_function_pointers_only()
969968
remove_function_pointers(
970969
ui_message_handler,
971970
goto_model,
972-
cmdline.isset("pointer-check"),
973971
true); // abort if we can't resolve via const pointers
974972
}
975973

src/goto-instrument/value_set_fi_fp_removal.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ void value_set_fi_fp_removal(
7575
f.second.body,
7676
f.first,
7777
target,
78-
functions,
79-
true);
78+
functions);
8079
}
8180
}
8281
}

src/goto-programs/process_goto_program.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,7 @@ bool process_goto_program(
4242
// remove function pointers
4343
log.status() << "Removal of function pointers and virtual functions"
4444
<< messaget::eom;
45-
remove_function_pointers(
46-
log.get_message_handler(),
47-
goto_model,
48-
options.get_bool_option("pointer-check"),
49-
false);
45+
remove_function_pointers(log.get_message_handler(), goto_model, false);
5046

5147
mm_io(goto_model);
5248

src/goto-programs/remove_function_pointers.cpp

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class remove_function_pointerst
3737
remove_function_pointerst(
3838
message_handlert &_message_handler,
3939
symbol_tablet &_symbol_table,
40-
bool _add_safety_assertion,
4140
bool only_resolve_const_fps,
4241
const goto_functionst &goto_functions);
4342

@@ -51,7 +50,6 @@ class remove_function_pointerst
5150
message_handlert &message_handler;
5251
const namespacet ns;
5352
symbol_tablet &symbol_table;
54-
bool add_safety_assertion;
5553

5654
// We can optionally halt the FP removal if we aren't able to use
5755
// remove_const_function_pointerst to successfully narrow to a small
@@ -81,13 +79,11 @@ class remove_function_pointerst
8179
remove_function_pointerst::remove_function_pointerst(
8280
message_handlert &_message_handler,
8381
symbol_tablet &_symbol_table,
84-
bool _add_safety_assertion,
8582
bool only_resolve_const_fps,
8683
const goto_functionst &goto_functions)
8784
: message_handler(_message_handler),
8885
ns(_symbol_table),
8986
symbol_table(_symbol_table),
90-
add_safety_assertion(_add_safety_assertion),
9187
only_resolve_const_fps(only_resolve_const_fps)
9288
{
9389
for(const auto &s : symbol_table.symbols)
@@ -343,8 +339,7 @@ void remove_function_pointerst::remove_function_pointer(
343339
goto_program,
344340
function_id,
345341
target,
346-
functions,
347-
add_safety_assertion);
342+
functions);
348343
}
349344

350345
static std::string function_pointer_assertion_comment(
@@ -385,8 +380,7 @@ void remove_function_pointer(
385380
goto_programt &goto_program,
386381
const irep_idt &function_id,
387382
goto_programt::targett target,
388-
const std::unordered_set<symbol_exprt, irep_hash> &functions,
389-
const bool add_safety_assertion)
383+
const std::unordered_set<symbol_exprt, irep_hash> &functions)
390384
{
391385
const exprt &function = target->call_function();
392386
const exprt &pointer = to_dereference_expr(function).pointer();
@@ -430,14 +424,11 @@ void remove_function_pointer(
430424
}
431425

432426
// fall-through
433-
if(add_safety_assertion)
434-
{
435-
goto_programt::targett t =
436-
new_code_gotos.add(goto_programt::make_assertion(false_exprt()));
437-
t->source_location_nonconst().set_property_class("pointer dereference");
438-
t->source_location_nonconst().set_comment(
439-
function_pointer_assertion_comment(functions));
440-
}
427+
goto_programt::targett t =
428+
new_code_gotos.add(goto_programt::make_assertion(false_exprt()));
429+
t->source_location_nonconst().set_property_class("pointer dereference");
430+
t->source_location_nonconst().set_comment(
431+
function_pointer_assertion_comment(functions));
441432
new_code_gotos.add(goto_programt::make_assumption(false_exprt()));
442433

443434
goto_programt new_code;
@@ -542,13 +533,11 @@ void remove_function_pointerst::operator()(goto_functionst &functions)
542533
void remove_function_pointers(
543534
message_handlert &_message_handler,
544535
goto_modelt &goto_model,
545-
bool add_safety_assertion,
546536
bool only_remove_const_fps)
547537
{
548538
remove_function_pointerst rfp(
549539
_message_handler,
550540
goto_model.symbol_table,
551-
add_safety_assertion,
552541
only_remove_const_fps,
553542
goto_model.goto_functions);
554543

src/goto-programs/remove_function_pointers.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ class symbol_tablet;
2828
void remove_function_pointers(
2929
message_handlert &_message_handler,
3030
goto_modelt &goto_model,
31-
bool add_safety_assertion,
3231
bool only_remove_const_fps);
3332

3433
/// Replace a call to a dynamic function at location
@@ -40,16 +39,13 @@ void remove_function_pointers(
4039
/// \param function_id: Name of function containing the target
4140
/// \param target: location with function call with function pointer
4241
/// \param functions: The set of functions to consider
43-
/// \param add_safety_assertion: Iff true, include an assertion that the
44-
// pointer matches one of the candidate functions
4542
void remove_function_pointer(
4643
message_handlert &message_handler,
4744
symbol_tablet &symbol_table,
4845
goto_programt &goto_program,
4946
const irep_idt &function_id,
5047
goto_programt::targett target,
51-
const std::unordered_set<symbol_exprt, irep_hash> &functions,
52-
const bool add_safety_assertion);
48+
const std::unordered_set<symbol_exprt, irep_hash> &functions);
5349

5450
/// Returns true iff \p call_type can be converted to produce a function call of
5551
/// the same type as \p function_type.

src/goto-programs/restrict_function_pointers.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ static void restrict_function_pointer(
7979
goto_program,
8080
function_id,
8181
location,
82-
candidates,
83-
true);
82+
candidates);
8483
}
8584
} // namespace
8685

0 commit comments

Comments
 (0)