Skip to content

Commit 3c69aa1

Browse files
authored
Merge pull request #7011 from tautschnig/bugfixes/6983-take-2
Enable the function-pointer fall-back assertion by default
2 parents a96dea4 + 86c8181 commit 3c69aa1

File tree

14 files changed

+32
-101
lines changed

14 files changed

+32
-101
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"));
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"));
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +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"));
45+
remove_function_pointers(log.get_message_handler(), goto_model, false);
4946

5047
mm_io(goto_model);
5148

src/goto-programs/remove_function_pointers.cpp

Lines changed: 12 additions & 58 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;
@@ -539,53 +530,16 @@ void remove_function_pointerst::operator()(goto_functionst &functions)
539530
functions.compute_location_numbers();
540531
}
541532

542-
bool remove_function_pointers(
543-
message_handlert &_message_handler,
544-
symbol_tablet &symbol_table,
545-
const goto_functionst &goto_functions,
546-
goto_programt &goto_program,
547-
const irep_idt &function_id,
548-
bool add_safety_assertion,
549-
bool only_remove_const_fps)
550-
{
551-
remove_function_pointerst
552-
rfp(
553-
_message_handler,
554-
symbol_table,
555-
add_safety_assertion,
556-
only_remove_const_fps,
557-
goto_functions);
558-
559-
return rfp.remove_function_pointers(goto_program, function_id);
560-
}
561-
562533
void remove_function_pointers(
563534
message_handlert &_message_handler,
564-
symbol_tablet &symbol_table,
565-
goto_functionst &goto_functions,
566-
bool add_safety_assertion,
567-
bool only_remove_const_fps)
568-
{
569-
remove_function_pointerst
570-
rfp(
571-
_message_handler,
572-
symbol_table,
573-
add_safety_assertion,
574-
only_remove_const_fps,
575-
goto_functions);
576-
577-
rfp(goto_functions);
578-
}
579-
580-
void remove_function_pointers(message_handlert &_message_handler,
581535
goto_modelt &goto_model,
582-
bool add_safety_assertion,
583536
bool only_remove_const_fps)
584537
{
585-
remove_function_pointers(
538+
remove_function_pointerst rfp(
586539
_message_handler,
587540
goto_model.symbol_table,
588-
goto_model.goto_functions,
589-
add_safety_assertion,
590-
only_remove_const_fps);
541+
only_remove_const_fps,
542+
goto_model.goto_functions);
543+
544+
rfp(goto_model.goto_functions);
591545
}

src/goto-programs/remove_function_pointers.h

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,7 @@ class symbol_tablet;
2828
void remove_function_pointers(
2929
message_handlert &_message_handler,
3030
goto_modelt &goto_model,
31-
bool add_safety_assertion,
32-
bool only_remove_const_fps=false);
33-
34-
void remove_function_pointers(
35-
message_handlert &_message_handler,
36-
symbol_tablet &symbol_table,
37-
goto_functionst &goto_functions,
38-
bool add_safety_assertion,
39-
bool only_remove_const_fps=false);
40-
41-
bool remove_function_pointers(
42-
message_handlert &_message_handler,
43-
symbol_tablet &symbol_table,
44-
const goto_functionst &goto_functions,
45-
goto_programt &goto_program,
46-
const irep_idt &function_id,
47-
bool add_safety_assertion,
48-
bool only_remove_const_fps = false);
31+
bool only_remove_const_fps);
4932

5033
/// Replace a call to a dynamic function at location
5134
/// target in the given goto-program by a case-split
@@ -56,16 +39,13 @@ bool remove_function_pointers(
5639
/// \param function_id: Name of function containing the target
5740
/// \param target: location with function call with function pointer
5841
/// \param functions: The set of functions to consider
59-
/// \param add_safety_assertion: Iff true, include an assertion that the
60-
// pointer matches one of the candidate functions
6142
void remove_function_pointer(
6243
message_handlert &message_handler,
6344
symbol_tablet &symbol_table,
6445
goto_programt &goto_program,
6546
const irep_idt &function_id,
6647
goto_programt::targett target,
67-
const std::unordered_set<symbol_exprt, irep_hash> &functions,
68-
const bool add_safety_assertion);
48+
const std::unordered_set<symbol_exprt, irep_hash> &functions);
6949

7050
/// Returns true iff \p call_type can be converted to produce a function call of
7151
/// 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)