Skip to content

Commit 991611b

Browse files
author
thk123
committed
Removing handlers for the cases can't generate
Since I do not know the code that can be written to trigger these cases, it is safer to not blindly optimize them (instead they will fall through to the old case of all matching functions). It still matches all the cases outlined in the regressions folder.
1 parent c419218 commit 991611b

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <stdio.h>
2+
3+
void f1 (void) { printf("%i", 1); }
4+
void f2 (void) { printf("%i", 2); }
5+
void f3 (void) { printf("%i", 3); }
6+
void f4 (void) { printf("%i", 4); }
7+
void f5 (void) { printf("%i", 5); }
8+
void f6 (void) { printf("%i", 6); }
9+
void f7 (void) { printf("%i", 7); }
10+
void f8 (void) { printf("%i", 8); }
11+
void f9 (void) { printf("%i", 9); }
12+
13+
typedef void(*void_fp)(void);
14+
15+
// There is a basic check that excludes all functions that aren't used anywhere
16+
// This ensures that check can't work in this example
17+
const void_fp fp_all[] = {f1, f2 ,f3, f4, f5 ,f6, f7, f8, f9};
18+
19+
void func()
20+
{
21+
// There isn't an obvious reason to write this code, but perhaps some
22+
// code can get transformed into this so we should still handle it.
23+
(*(&f2))();
24+
}
25+
26+
void main()
27+
{
28+
func();
29+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CORE
2+
main.c
3+
--show-goto-functions
4+
5+
^Removing function pointers and virtual functions$
6+
^\s*f2();
7+
--
8+
^warning: ignoring

src/goto-programs/remove_function_pointers.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -698,17 +698,14 @@ void remove_function_pointerst::remove_function_pointer(
698698

699699
const exprt &pointer=function.op0();
700700

701-
exprt precise_call;
702701
functionst functions;
703702
bool found_functions=false;
704-
if(try_get_precise_call(pointer, precise_call))
705-
{
706-
to_code_function_call(target->code).function()=precise_call;
707-
return;
708-
}
709703

710704
const c_qualifierst pointer_qualifers(pointer.type());
711705

706+
// This can happen for example with
707+
// (*(&f2))();
708+
// In this case we don't need constant check - implict
712709
found_functions=found_functions||try_get_from_address_of(pointer, functions);
713710

714711
// If it is a symbol (except in the case where the symbol is the function
@@ -719,8 +716,6 @@ void remove_function_pointerst::remove_function_pointer(
719716
found_functions||try_get_call_from_symbol(pointer, functions);
720717
}
721718

722-
found_functions=found_functions||try_get_call_from_index(pointer, functions);
723-
724719
if(functions.size()==1)
725720
{
726721
to_code_function_call(target->code).function()=functions.front();

0 commit comments

Comments
 (0)