Skip to content

Commit c8687e7

Browse files
committed
Print the original return type in coverage report
remove_returns would cause return types that appear inconsistent to the user.
1 parent 610e9e4 commit c8687e7

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

src/cbmc/symex_coverage.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Date: March 2016
1919
#include <util/prefix.h>
2020

2121
#include <goto-programs/goto_functions.h>
22+
#include <goto-programs/remove_returns.h>
2223

2324
#include "symex_coverage.h"
2425

@@ -157,8 +158,14 @@ goto_program_coverage_recordt::goto_program_coverage_recordt(
157158
// </lines>
158159
// </method>
159160
xml.set_attribute("name", id2string(gf_it->first));
161+
162+
code_typet sig_type=
163+
original_return_type(ns.get_symbol_table(), gf_it->first);
164+
if(sig_type.is_nil())
165+
sig_type=gf_it->second.type;
160166
xml.set_attribute("signature",
161-
from_type(ns, gf_it->first, gf_it->second.type));
167+
from_type(ns, gf_it->first, sig_type));
168+
162169
xml.set_attribute("line-rate",
163170
rate(lines_covered, lines_total));
164171
xml.set_attribute("branch-rate",

src/goto-programs/remove_returns.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,46 @@ void remove_returns(goto_modelt &goto_model)
269269

270270
/*******************************************************************\
271271
272+
Function: original_return_type
273+
274+
Inputs:
275+
276+
Outputs:
277+
278+
Purpose:
279+
280+
\*******************************************************************/
281+
282+
code_typet original_return_type(
283+
const symbol_tablet &symbol_table,
284+
const irep_idt &function_id)
285+
{
286+
code_typet type;
287+
type.make_nil();
288+
289+
// do we have X#return_value?
290+
std::string rv_name=id2string(function_id)+RETURN_VALUE_SUFFIX;
291+
292+
symbol_tablet::symbolst::const_iterator rv_it=
293+
symbol_table.symbols.find(rv_name);
294+
295+
if(rv_it!=symbol_table.symbols.end())
296+
{
297+
// look up the function symbol
298+
symbol_tablet::symbolst::const_iterator s_it=
299+
symbol_table.symbols.find(function_id);
300+
301+
assert(s_it!=symbol_table.symbols.end());
302+
303+
type=to_code_type(s_it->second.type);
304+
type.return_type()=rv_it->second.type;
305+
}
306+
307+
return type;
308+
}
309+
310+
/*******************************************************************\
311+
272312
Function: remove_returnst::restore_returns
273313
274314
Inputs:
@@ -301,7 +341,7 @@ bool remove_returnst::restore_returns(
301341
symbolt &function_symbol=s_it->second;
302342

303343
// restore the return type
304-
f_it->second.type.return_type()=rv_it->second.type;
344+
f_it->second.type=original_return_type(symbol_table, function_id);
305345
function_symbol.type=f_it->second.type;
306346

307347
// remove the return_value symbol from the symbol_table

src/goto-programs/remove_returns.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ void remove_returns(goto_modelt &);
2626
// reverse the above operations
2727
void restore_returns(symbol_tablet &, goto_functionst &);
2828

29+
code_typet original_return_type(
30+
const symbol_tablet &symbol_table,
31+
const irep_idt &function_id);
32+
2933
#endif // CPROVER_GOTO_PROGRAMS_REMOVE_RETURNS_H

0 commit comments

Comments
 (0)