Skip to content

unreachable_instructions now passes down function identifier [blocks: #3126] #3840

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions src/goto-analyzer/unreachable_instructions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,38 +65,27 @@ static void build_dead_map_from_ai(

static void output_dead_plain(
const namespacet &ns,
const irep_idt &function_identifier,
const goto_programt &goto_program,
const dead_mapt &dead_map,
std::ostream &os)
{
assert(!goto_program.instructions.empty());
goto_programt::const_targett end_function=
goto_program.instructions.end();
--end_function;
assert(end_function->is_end_function());

os << "\n*** " << end_function->function << " ***\n";
os << "\n*** " << function_identifier << " ***\n";

for(dead_mapt::const_iterator it=dead_map.begin();
it!=dead_map.end();
++it)
goto_program.output_instruction(ns, "", os, *it->second);
goto_program.output_instruction(ns, function_identifier, os, *it->second);
}

static void add_to_xml(
const irep_idt &function_identifier,
const goto_programt &goto_program,
const dead_mapt &dead_map,
xmlt &dest)
{
PRECONDITION(!goto_program.instructions.empty());
goto_programt::const_targett end_function=
goto_program.instructions.end();
--end_function;
DATA_INVARIANT(end_function->is_end_function(),
"The last instruction in a goto-program must be END_FUNCTION");

xmlt &x = dest.new_element("function");
x.set_attribute("name", id2string(end_function->function));
x.set_attribute("name", id2string(function_identifier));

for(dead_mapt::const_iterator it=dead_map.begin();
it!=dead_map.end();
Expand All @@ -113,6 +102,7 @@ static void add_to_xml(

static void add_to_json(
const namespacet &ns,
const irep_idt &function_identifier,
const goto_programt &goto_program,
const dead_mapt &dead_map,
json_arrayt &dest)
Expand All @@ -125,7 +115,7 @@ static void add_to_json(
"The last instruction in a goto-program must be END_FUNCTION");

json_objectt entry(
{{"function", json_stringt(end_function->function)},
{{"function", json_stringt(function_identifier)},
{"fileName",
json_stringt(concat_dir_file(
id2string(end_function->source_location.get_working_directory()),
Expand Down Expand Up @@ -192,9 +182,9 @@ void unreachable_instructions(
if(!dead_map.empty())
{
if(!json)
output_dead_plain(ns, goto_program, dead_map, os);
output_dead_plain(ns, f_it->first, goto_program, dead_map, os);
else
add_to_json(ns, goto_program, dead_map, json_result);
add_to_json(ns, f_it->first, goto_program, dead_map, json_result);
}
}

Expand Down Expand Up @@ -226,16 +216,16 @@ bool static_unreachable_instructions(
{
if(options.get_bool_option("json"))
{
add_to_json(ns, f_it->second.body, dead_map, json_result);
add_to_json(ns, f_it->first, f_it->second.body, dead_map, json_result);
}
else if(options.get_bool_option("xml"))
{
add_to_xml(f_it->second.body, dead_map, xml_result);
add_to_xml(f_it->first, f_it->second.body, dead_map, xml_result);
}
else
{
// text or console
output_dead_plain(ns, f_it->second.body, dead_map, out);
output_dead_plain(ns, f_it->first, f_it->second.body, dead_map, out);
}
}
}
Expand Down