Skip to content

Commit 79df541

Browse files
authored
Merge pull request #7605 from tautschnig/bugfixes/fpr-nil
Function-pointer removal: fix interaction with slice-global-inits
2 parents 9cdd34f + c2cd54d commit 79df541

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
int foo(void)
2+
{
3+
}
4+
5+
const int (*const fptrs[])(void) = {&foo};
6+
7+
void unused()
8+
{
9+
const int (*const fp)(void) = fptrs[0];
10+
(*fp)();
11+
}
12+
13+
int main()
14+
{
15+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--remove-function-pointers --slice-global-inits
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
int foo()
2+
{
3+
}
4+
5+
int main()
6+
{
7+
int (*fp)() = &foo;
8+
(*fp)();
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--slice-global-inits
4+
^VERIFICATION SUCCESSFUL$
5+
^EXIT=0$
6+
^SIGNAL=0$
7+
--
8+
^warning: ignoring

src/goto-instrument/goto_instrument_parse_options.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,8 @@ void goto_instrument_parse_optionst::instrument_goto_program()
14811481

14821482
if(cmdline.isset("slice-global-inits"))
14831483
{
1484+
do_indirect_call_and_rtti_removal();
1485+
14841486
log.status() << "Slicing away initializations of unused global variables"
14851487
<< messaget::eom;
14861488
slice_global_inits(goto_model, ui_message_handler);

src/goto-programs/remove_const_function_pointers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ exprt remove_const_function_pointerst::replace_const_symbols(
7474
{
7575
const symbolt &symbol =
7676
symbol_table.lookup_ref(to_symbol_expr(expression).get_identifier());
77-
if(symbol.type.id()!=ID_code)
77+
if(symbol.type.id() != ID_code && symbol.value.is_not_nil())
7878
{
7979
const exprt &symbol_value=symbol.value;
8080
return replace_const_symbols(symbol_value);

0 commit comments

Comments
 (0)