Skip to content

Commit bd20036

Browse files
committed
coverage instrumentation now passes a function identifier
1 parent 7663540 commit bd20036

10 files changed

+40
-22
lines changed

src/goto-instrument/cover.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Date: May 2016
3131
/// ID_java)
3232
/// \param message_handler: a message handler
3333
void instrument_cover_goals(
34+
const irep_idt &function,
3435
goto_programt &goto_program,
3536
const cover_instrumenterst &instrumenters,
3637
const irep_idt &mode,
@@ -42,8 +43,8 @@ void instrument_cover_goals(
4243
: std::unique_ptr<cover_blocks_baset>(
4344
new cover_basic_blockst(goto_program));
4445

45-
basic_blocks->report_block_anomalies(goto_program, message_handler);
46-
instrumenters(goto_program, *basic_blocks);
46+
basic_blocks->report_block_anomalies(function, goto_program, message_handler);
47+
instrumenters(function, goto_program, *basic_blocks);
4748
}
4849

4950
/// Instruments goto program for a given coverage criterion
@@ -60,6 +61,7 @@ DEPRECATED(
6061
"message_handlert &message_handler, const irep_idt mode) instead")
6162
void instrument_cover_goals(
6263
const symbol_tablet &symbol_table,
64+
const irep_idt &function,
6365
goto_programt &goto_program,
6466
coverage_criteriont criterion,
6567
message_handlert &message_handler)
@@ -71,7 +73,7 @@ void instrument_cover_goals(
7173
instrumenters.add_from_criterion(criterion, symbol_table, goal_filters);
7274

7375
instrument_cover_goals(
74-
goto_program, instrumenters, ID_unknown, message_handler);
76+
function, goto_program, instrumenters, ID_unknown, message_handler);
7577
}
7678

7779
/// Create and add an instrumenter based on the given criterion
@@ -283,7 +285,7 @@ static void instrument_cover_goals(
283285
if(config.function_filters(function_id, function))
284286
{
285287
instrument_cover_goals(
286-
function.body, config.cover_instrumenters, config.mode, message_handler);
288+
function_id, function.body, config.cover_instrumenters, config.mode, message_handler);
287289
changed = true;
288290
}
289291

src/goto-instrument/cover_basic_blocks.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ cover_basic_blockst::source_location_of(const std::size_t block_nr) const
109109
}
110110

111111
void cover_basic_blockst::report_block_anomalies(
112+
const irep_idt &function,
112113
const goto_programt &goto_program,
113114
message_handlert &message_handler)
114115
{
@@ -133,7 +134,7 @@ void cover_basic_blockst::report_block_anomalies(
133134
block_info.source_location.is_nil())
134135
{
135136
msg.warning() << "Ignoring block " << (block_nr + 1) << " location "
136-
<< it->location_number << " " << it->function
137+
<< it->location_number << " " << function
137138
<< " (missing source location)" << messaget::eom;
138139
}
139140
// The location numbers printed here are those

src/goto-instrument/cover_basic_blocks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class cover_blocks_baset
4646
/// \param goto_program The goto program
4747
/// \param message_handler The message handler
4848
virtual void report_block_anomalies(
49+
const irep_idt &function,
4950
const goto_programt &goto_program,
5051
message_handlert &message_handler)
5152
{
@@ -78,6 +79,7 @@ class cover_basic_blockst final : public cover_blocks_baset
7879
/// \param goto_program The goto program
7980
/// \param message_handler The message handler
8081
void report_block_anomalies(
82+
const irep_idt &function,
8183
const goto_programt &goto_program,
8284
message_handlert &message_handler) override;
8385

src/goto-instrument/cover_instrument.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ class cover_instrumenter_baset
4040
/// \param goto_program: a goto program
4141
/// \param basic_blocks: detected basic blocks
4242
virtual void operator()(
43+
const irep_idt &function,
4344
goto_programt &goto_program,
4445
const cover_blocks_baset &basic_blocks) const
4546
{
4647
Forall_goto_program_instructions(i_it, goto_program)
4748
{
48-
instrument(goto_program, i_it, basic_blocks);
49+
instrument(function, goto_program, i_it, basic_blocks);
4950
}
5051
}
5152

@@ -58,6 +59,7 @@ class cover_instrumenter_baset
5859

5960
/// Override this method to implement an instrumenter
6061
virtual void instrument(
62+
const irep_idt &function,
6163
goto_programt &,
6264
goto_programt::targett &,
6365
const cover_blocks_baset &) const = 0;
@@ -94,11 +96,12 @@ class cover_instrumenterst
9496
/// \param goto_program: a goto program
9597
/// \param basic_blocks: detected basic blocks of the goto program
9698
void operator()(
99+
const irep_idt &function,
97100
goto_programt &goto_program,
98101
const cover_blocks_baset &basic_blocks) const
99102
{
100103
for(const auto &instrumenter : instrumenters)
101-
(*instrumenter)(goto_program, basic_blocks);
104+
(*instrumenter)(function, goto_program, basic_blocks);
102105
}
103106

104107
private:
@@ -118,6 +121,7 @@ class cover_location_instrumentert : public cover_instrumenter_baset
118121

119122
protected:
120123
void instrument(
124+
const irep_idt &function,
121125
goto_programt &,
122126
goto_programt::targett &,
123127
const cover_blocks_baset &) const override;
@@ -136,6 +140,7 @@ class cover_branch_instrumentert : public cover_instrumenter_baset
136140

137141
protected:
138142
void instrument(
143+
const irep_idt &function,
139144
goto_programt &,
140145
goto_programt::targett &,
141146
const cover_blocks_baset &) const override;
@@ -154,6 +159,7 @@ class cover_condition_instrumentert : public cover_instrumenter_baset
154159

155160
protected:
156161
void instrument(
162+
const irep_idt &function,
157163
goto_programt &,
158164
goto_programt::targett &,
159165
const cover_blocks_baset &) const override;
@@ -172,6 +178,7 @@ class cover_decision_instrumentert : public cover_instrumenter_baset
172178

173179
protected:
174180
void instrument(
181+
const irep_idt &function,
175182
goto_programt &,
176183
goto_programt::targett &,
177184
const cover_blocks_baset &) const override;
@@ -190,6 +197,7 @@ class cover_mcdc_instrumentert : public cover_instrumenter_baset
190197

191198
protected:
192199
void instrument(
200+
const irep_idt &function,
193201
goto_programt &,
194202
goto_programt::targett &,
195203
const cover_blocks_baset &) const override;
@@ -208,6 +216,7 @@ class cover_path_instrumentert : public cover_instrumenter_baset
208216

209217
protected:
210218
void instrument(
219+
const irep_idt &function,
211220
goto_programt &,
212221
goto_programt::targett &,
213222
const cover_blocks_baset &) const override;
@@ -226,6 +235,7 @@ class cover_assertion_instrumentert : public cover_instrumenter_baset
226235

227236
protected:
228237
void instrument(
238+
const irep_idt &function,
229239
goto_programt &,
230240
goto_programt::targett &,
231241
const cover_blocks_baset &) const override;
@@ -244,6 +254,7 @@ class cover_cover_instrumentert : public cover_instrumenter_baset
244254

245255
protected:
246256
void instrument(
257+
const irep_idt &function,
247258
goto_programt &,
248259
goto_programt::targett &,
249260
const cover_blocks_baset &) const override;

src/goto-instrument/cover_instrument_branch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening
1313
#include "cover_basic_blocks.h"
1414

1515
void cover_branch_instrumentert::instrument(
16+
const irep_idt &function,
1617
goto_programt &goto_program,
1718
goto_programt::targett &i_it,
1819
const cover_blocks_baset &basic_blocks) const
@@ -31,7 +32,7 @@ void cover_branch_instrumentert::instrument(
3132
goto_programt::targett t = goto_program.insert_before(i_it);
3233
t->make_assertion(false_exprt());
3334
t->source_location = source_location;
34-
initialize_source_location(t, comment, i_it->function);
35+
initialize_source_location(t, comment, function);
3536
}
3637

3738
if(
@@ -44,7 +45,6 @@ void cover_branch_instrumentert::instrument(
4445
std::string false_comment = "block " + b + " branch false";
4546

4647
exprt guard = i_it->guard;
47-
const irep_idt function = i_it->function;
4848
source_locationt source_location = i_it->source_location;
4949

5050
goto_program.insert_before_swap(i_it);

src/goto-instrument/cover_instrument_condition.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Author: Daniel Kroening
1717
#include "cover_basic_blocks.h"
1818

1919
void cover_condition_instrumentert::instrument(
20+
const irep_idt &function,
2021
goto_programt &goto_program,
2122
goto_programt::targett &i_it,
2223
const cover_blocks_baset &) const
@@ -33,10 +34,9 @@ void cover_condition_instrumentert::instrument(
3334

3435
for(const auto &c : conditions)
3536
{
36-
const std::string c_string = from_expr(ns, i_it->function, c);
37+
const std::string c_string = from_expr(ns, function, c);
3738

3839
const std::string comment_t = "condition `" + c_string + "' true";
39-
const irep_idt function = i_it->function;
4040
goto_program.insert_before_swap(i_it);
4141
i_it->make_assertion(c);
4242
i_it->source_location = source_location;

src/goto-instrument/cover_instrument_decision.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening
1616
#include "cover_util.h"
1717

1818
void cover_decision_instrumentert::instrument(
19+
const irep_idt &function,
1920
goto_programt &goto_program,
2021
goto_programt::targett &i_it,
2122
const cover_blocks_baset &) const
@@ -32,10 +33,9 @@ void cover_decision_instrumentert::instrument(
3233

3334
for(const auto &d : decisions)
3435
{
35-
const std::string d_string = from_expr(ns, i_it->function, d);
36+
const std::string d_string = from_expr(ns, function, d);
3637

3738
const std::string comment_t = "decision `" + d_string + "' true";
38-
const irep_idt function = i_it->function;
3939
goto_program.insert_before_swap(i_it);
4040
i_it->make_assertion(d);
4141
i_it->source_location = source_location;

src/goto-instrument/cover_instrument_location.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Author: Daniel Kroening
1515
#include "cover_filter.h"
1616

1717
void cover_location_instrumentert::instrument(
18+
const irep_idt &function,
1819
goto_programt &goto_program,
1920
goto_programt::targett &i_it,
2021
const cover_blocks_baset &basic_blocks) const
@@ -28,14 +29,13 @@ void cover_location_instrumentert::instrument(
2829
if(representative_instruction && *representative_instruction == i_it)
2930
{
3031
const std::string b = std::to_string(block_nr + 1); // start with 1
31-
const std::string id = id2string(i_it->function) + "#" + b;
32+
const std::string id = id2string(function) + "#" + b;
3233
const auto source_location = basic_blocks.source_location_of(block_nr);
3334

3435
// filter goals
3536
if(goal_filters(source_location))
3637
{
3738
const std::string comment = "block " + b;
38-
const irep_idt function = i_it->function;
3939
goto_program.insert_before_swap(i_it);
4040
i_it->make_assertion(false_exprt());
4141
i_it->source_location = source_location;

src/goto-instrument/cover_instrument_mcdc.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ void minimize_mcdc_controlling(
621621
}
622622

623623
void cover_mcdc_instrumentert::instrument(
624+
const irep_idt &function,
624625
goto_programt &goto_program,
625626
goto_programt::targett &i_it,
626627
const cover_blocks_baset &) const
@@ -657,10 +658,9 @@ void cover_mcdc_instrumentert::instrument(
657658
? "decision/condition"
658659
: is_decision ? "decision" : "condition";
659660

660-
std::string p_string = from_expr(ns, i_it->function, p);
661+
std::string p_string = from_expr(ns, function, p);
661662

662663
std::string comment_t = description + " `" + p_string + "' true";
663-
const irep_idt function = i_it->function;
664664
goto_program.insert_before_swap(i_it);
665665
i_it->make_assertion(not_exprt(p));
666666
i_it->source_location = source_location;
@@ -693,12 +693,11 @@ void cover_mcdc_instrumentert::instrument(
693693

694694
for(const auto &p : controlling)
695695
{
696-
std::string p_string = from_expr(ns, i_it->function, p);
696+
std::string p_string = from_expr(ns, function, p);
697697

698698
std::string description =
699699
"MC/DC independence condition `" + p_string + "'";
700700

701-
const irep_idt function = i_it->function;
702701
goto_program.insert_before_swap(i_it);
703702
i_it->make_assertion(not_exprt(p));
704703
i_it->source_location = source_location;

src/goto-instrument/cover_instrument_other.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening
1616
#include "cover_util.h"
1717

1818
void cover_path_instrumentert::instrument(
19+
const irep_idt &,
1920
goto_programt &,
2021
goto_programt::targett &i_it,
2122
const cover_blocks_baset &) const
@@ -27,6 +28,7 @@ void cover_path_instrumentert::instrument(
2728
}
2829

2930
void cover_assertion_instrumentert::instrument(
31+
const irep_idt &function,
3032
goto_programt &,
3133
goto_programt::targett &i_it,
3234
const cover_blocks_baset &) const
@@ -36,11 +38,12 @@ void cover_assertion_instrumentert::instrument(
3638
{
3739
i_it->guard = false_exprt();
3840
initialize_source_location(
39-
i_it, id2string(i_it->source_location.get_comment()), i_it->function);
41+
i_it, id2string(i_it->source_location.get_comment()), function);
4042
}
4143
}
4244

4345
void cover_cover_instrumentert::instrument(
46+
const irep_idt &function,
4447
goto_programt &,
4548
goto_programt::targett &i_it,
4649
const cover_blocks_baset &) const
@@ -58,11 +61,11 @@ void cover_cover_instrumentert::instrument(
5861
{
5962
const exprt c = code_function_call.arguments()[0];
6063
std::string comment =
61-
"condition `" + from_expr(ns, i_it->function, c) + "'";
64+
"condition `" + from_expr(ns, function, c) + "'";
6265
i_it->guard = not_exprt(c);
6366
i_it->type = ASSERT;
6467
i_it->code.clear();
65-
initialize_source_location(i_it, comment, i_it->function);
68+
initialize_source_location(i_it, comment, function);
6669
}
6770
}
6871
else if(is_non_cover_assertion(i_it))

0 commit comments

Comments
 (0)