Skip to content

Commit 22b1628

Browse files
committed
goto-analyzer (un)reachable-functions: build valid json output
Some functions do not have a location attached to the END_FUNCTION instruction. This should be fixed (as is discussed in PR#918), but until such a fix is in place this workaround will ensure JSON output is valid by not exclusively relying on the END_FUNCTION location. The regression tests now explicitly test for absence of such invalid JSON.
1 parent 2e7f785 commit 22b1628

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

regression/goto-analyzer/reachable-functions-basic-json/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ CORE
66
"function": "obviously_dead",$
77
"function": "not_obviously_dead",$
88
--
9+
"last line":[[:space:]]*$
910
^warning: ignoring

regression/goto-analyzer/unreachable-functions-basic-json/test.desc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ CORE
66
"function": "not_called",
77
"last line": 6
88
--
9+
"last line":[[:space:]]*$
910
^warning: ignoring

src/goto-analyzer/unreachable_instructions.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,21 @@ static void list_functions(
325325

326326
goto_programt::const_targett end_function=
327327
goto_program.instructions.end();
328-
--end_function;
329-
assert(end_function->is_end_function());
330-
last_location=end_function->source_location;
328+
329+
// find the last instruction with a line number
330+
// TODO(tautschnig): #918 will eventually ensure that every instruction
331+
// has such
332+
do
333+
{
334+
--end_function;
335+
last_location = end_function->source_location;
336+
}
337+
while(
338+
end_function != goto_program.instructions.begin() &&
339+
last_location.get_line().empty());
340+
341+
if(last_location.get_line().empty())
342+
last_location = decl.location;
331343
}
332344
else
333345
// completely ignore functions without a body, both for

0 commit comments

Comments
 (0)