Skip to content

Commit c4dafa2

Browse files
committed
goto-analyzer: fix reachable-functions analysis for inline functions
We now only consider functions reachable when they are actually called, and don't automatically consider `inline` functions reachable. Fixes: #5173
1 parent 4fe3ade commit c4dafa2

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdio.h>
2+
3+
int main()
4+
{
5+
return 0;
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE
2+
test.c
3+
--reachable-functions
4+
^test\.c main [0-9]+ [0-9]+$
5+
^<built-in-additions> __CPROVER_initialize [0-9]+ [0-9]+$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
10+
__sputc

src/goto-analyzer/unreachable_instructions.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,12 @@ void unreachable_instructions(
181181

182182
const symbolt &decl = ns.lookup(gf_entry.first);
183183

184-
if(
185-
called.find(decl.name) != called.end() ||
186-
to_code_type(decl.type).get_inlined())
184+
// Only consider functions reachable if they're actually called.
185+
// Previously, functions marked as "inline" were automatically treated as
186+
// reachable, but this caused false positives on systems (like MacOS) where
187+
// system headers contain uncalled inline functions that reference other
188+
// functions, making those referenced functions appear reachable.
189+
if(called.find(decl.name) != called.end())
187190
{
188191
unreachable_instructions(goto_program, dead_map);
189192
}
@@ -314,9 +317,9 @@ static void list_functions(
314317
{
315318
const symbolt &decl = ns.lookup(gf_entry.first);
316319

317-
if(
318-
unreachable == (called.find(decl.name) != called.end() ||
319-
to_code_type(decl.type).get_inlined()))
320+
// Only consider functions reachable if they're actually called.
321+
// See comment in unreachable_instructions() for rationale.
322+
if(unreachable == (called.find(decl.name) != called.end()))
320323
{
321324
continue;
322325
}

0 commit comments

Comments
 (0)