Skip to content

Commit d697124

Browse files
author
Daniel Kroening
committed
unreachable_instructions now passes down function identifier
1 parent 246da8c commit d697124

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

src/goto-analyzer/unreachable_instructions.cpp

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,38 +65,27 @@ static void build_dead_map_from_ai(
6565

6666
static void output_dead_plain(
6767
const namespacet &ns,
68+
const irep_idt &function_identifier,
6869
const goto_programt &goto_program,
6970
const dead_mapt &dead_map,
7071
std::ostream &os)
7172
{
72-
assert(!goto_program.instructions.empty());
73-
goto_programt::const_targett end_function=
74-
goto_program.instructions.end();
75-
--end_function;
76-
assert(end_function->is_end_function());
77-
78-
os << "\n*** " << end_function->function << " ***\n";
73+
os << "\n*** " << function_identifier << " ***\n";
7974

8075
for(dead_mapt::const_iterator it=dead_map.begin();
8176
it!=dead_map.end();
8277
++it)
83-
goto_program.output_instruction(ns, "", os, *it->second);
78+
goto_program.output_instruction(ns, function_identifier, os, *it->second);
8479
}
8580

8681
static void add_to_xml(
82+
const irep_idt &function_identifier,
8783
const goto_programt &goto_program,
8884
const dead_mapt &dead_map,
8985
xmlt &dest)
9086
{
91-
PRECONDITION(!goto_program.instructions.empty());
92-
goto_programt::const_targett end_function=
93-
goto_program.instructions.end();
94-
--end_function;
95-
DATA_INVARIANT(end_function->is_end_function(),
96-
"The last instruction in a goto-program must be END_FUNCTION");
97-
9887
xmlt &x = dest.new_element("function");
99-
x.set_attribute("name", id2string(end_function->function));
88+
x.set_attribute("name", id2string(function_identifier));
10089

10190
for(dead_mapt::const_iterator it=dead_map.begin();
10291
it!=dead_map.end();
@@ -113,20 +102,21 @@ static void add_to_xml(
113102

114103
static void add_to_json(
115104
const namespacet &ns,
105+
const irep_idt &function_identifier,
116106
const goto_programt &goto_program,
117107
const dead_mapt &dead_map,
118108
json_arrayt &dest)
119109
{
120-
json_objectt &entry=dest.push_back().make_object();
121-
122110
PRECONDITION(!goto_program.instructions.empty());
123111
goto_programt::const_targett end_function=
124112
goto_program.instructions.end();
125113
--end_function;
126114
DATA_INVARIANT(end_function->is_end_function(),
127115
"The last instruction in a goto-program must be END_FUNCTION");
128116

129-
entry["function"] = json_stringt(end_function->function);
117+
json_objectt &entry = dest.push_back().make_object();
118+
119+
entry["function"] = json_stringt(function_identifier);
130120
entry["fileName"]=
131121
json_stringt(concat_dir_file(
132122
id2string(end_function->source_location.get_working_directory()),
@@ -191,9 +181,9 @@ void unreachable_instructions(
191181
if(!dead_map.empty())
192182
{
193183
if(!json)
194-
output_dead_plain(ns, goto_program, dead_map, os);
184+
output_dead_plain(ns, f_it->first, goto_program, dead_map, os);
195185
else
196-
add_to_json(ns, goto_program, dead_map, json_result);
186+
add_to_json(ns, f_it->first, goto_program, dead_map, json_result);
197187
}
198188
}
199189

@@ -225,16 +215,16 @@ bool static_unreachable_instructions(
225215
{
226216
if(options.get_bool_option("json"))
227217
{
228-
add_to_json(ns, f_it->second.body, dead_map, json_result);
218+
add_to_json(ns, f_it->first, f_it->second.body, dead_map, json_result);
229219
}
230220
else if(options.get_bool_option("xml"))
231221
{
232-
add_to_xml(f_it->second.body, dead_map, xml_result);
222+
add_to_xml(f_it->first, f_it->second.body, dead_map, xml_result);
233223
}
234224
else
235225
{
236226
// text or console
237-
output_dead_plain(ns, f_it->second.body, dead_map, out);
227+
output_dead_plain(ns, f_it->first, f_it->second.body, dead_map, out);
238228
}
239229
}
240230
}

0 commit comments

Comments
 (0)