From 22b162879dd7718749c88d39b9fe217508d8df34 Mon Sep 17 00:00:00 2001 From: Michael Tautschnig Date: Mon, 12 Mar 2018 13:16:37 +0000 Subject: [PATCH] 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. --- .../reachable-functions-basic-json/test.desc | 1 + .../unreachable-functions-basic-json/test.desc | 1 + src/goto-analyzer/unreachable_instructions.cpp | 18 +++++++++++++++--- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/regression/goto-analyzer/reachable-functions-basic-json/test.desc b/regression/goto-analyzer/reachable-functions-basic-json/test.desc index 56938b7514e..c7c9455ee76 100644 --- a/regression/goto-analyzer/reachable-functions-basic-json/test.desc +++ b/regression/goto-analyzer/reachable-functions-basic-json/test.desc @@ -6,4 +6,5 @@ CORE "function": "obviously_dead",$ "function": "not_obviously_dead",$ -- +"last line":[[:space:]]*$ ^warning: ignoring diff --git a/regression/goto-analyzer/unreachable-functions-basic-json/test.desc b/regression/goto-analyzer/unreachable-functions-basic-json/test.desc index 1a343aab6f1..8828b4bbb17 100644 --- a/regression/goto-analyzer/unreachable-functions-basic-json/test.desc +++ b/regression/goto-analyzer/unreachable-functions-basic-json/test.desc @@ -6,4 +6,5 @@ CORE "function": "not_called", "last line": 6 -- +"last line":[[:space:]]*$ ^warning: ignoring diff --git a/src/goto-analyzer/unreachable_instructions.cpp b/src/goto-analyzer/unreachable_instructions.cpp index 81fe0c608ec..0e783baaba5 100644 --- a/src/goto-analyzer/unreachable_instructions.cpp +++ b/src/goto-analyzer/unreachable_instructions.cpp @@ -325,9 +325,21 @@ static void list_functions( goto_programt::const_targett end_function= goto_program.instructions.end(); - --end_function; - assert(end_function->is_end_function()); - last_location=end_function->source_location; + + // find the last instruction with a line number + // TODO(tautschnig): #918 will eventually ensure that every instruction + // has such + do + { + --end_function; + last_location = end_function->source_location; + } + while( + end_function != goto_program.instructions.begin() && + last_location.get_line().empty()); + + if(last_location.get_line().empty()) + last_location = decl.location; } else // completely ignore functions without a body, both for