Skip to content

Commit 053b556

Browse files
authored
Merge pull request #3840 from tautschnig/function-unreachable_instructions
unreachable_instructions now passes down function identifier [blocks: #3126]
2 parents 22517a3 + b6f6ebe commit 053b556

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/goto-analyzer/unreachable_instructions.cpp

Lines changed: 12 additions & 22 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,6 +102,7 @@ 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)
@@ -125,7 +115,7 @@ static void add_to_json(
125115
"The last instruction in a goto-program must be END_FUNCTION");
126116

127117
json_objectt entry(
128-
{{"function", json_stringt(end_function->function)},
118+
{{"function", json_stringt(function_identifier)},
129119
{"fileName",
130120
json_stringt(concat_dir_file(
131121
id2string(end_function->source_location.get_working_directory()),
@@ -192,9 +182,9 @@ void unreachable_instructions(
192182
if(!dead_map.empty())
193183
{
194184
if(!json)
195-
output_dead_plain(ns, goto_program, dead_map, os);
185+
output_dead_plain(ns, f_it->first, goto_program, dead_map, os);
196186
else
197-
add_to_json(ns, goto_program, dead_map, json_result);
187+
add_to_json(ns, f_it->first, goto_program, dead_map, json_result);
198188
}
199189
}
200190

@@ -226,16 +216,16 @@ bool static_unreachable_instructions(
226216
{
227217
if(options.get_bool_option("json"))
228218
{
229-
add_to_json(ns, f_it->second.body, dead_map, json_result);
219+
add_to_json(ns, f_it->first, f_it->second.body, dead_map, json_result);
230220
}
231221
else if(options.get_bool_option("xml"))
232222
{
233-
add_to_xml(f_it->second.body, dead_map, xml_result);
223+
add_to_xml(f_it->first, f_it->second.body, dead_map, xml_result);
234224
}
235225
else
236226
{
237227
// text or console
238-
output_dead_plain(ns, f_it->second.body, dead_map, out);
228+
output_dead_plain(ns, f_it->first, f_it->second.body, dead_map, out);
239229
}
240230
}
241231
}

0 commit comments

Comments
 (0)