Skip to content

Commit 6726aad

Browse files
authored
Merge pull request #3831 from tautschnig/function-coverage
Coverage instrumentation now passes a function identifier [blocks: #3126]
2 parents 4d2a024 + babdd13 commit 6726aad

11 files changed

+81
-54
lines changed

src/goto-instrument/cover.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ Date: May 2016
2525
#include "cover_basic_blocks.h"
2626

2727
/// Applies instrumenters to given goto program
28+
/// \param function_id: name of \p goto_program
2829
/// \param goto_program: the goto program
2930
/// \param instrumenters: the instrumenters
3031
/// \param mode: mode of the function to instrument (for instance ID_C or
3132
/// ID_java)
3233
/// \param message_handler: a message handler
3334
void instrument_cover_goals(
35+
const irep_idt &function_id,
3436
goto_programt &goto_program,
3537
const cover_instrumenterst &instrumenters,
3638
const irep_idt &mode,
@@ -42,12 +44,14 @@ void instrument_cover_goals(
4244
: std::unique_ptr<cover_blocks_baset>(
4345
new cover_basic_blockst(goto_program));
4446

45-
basic_blocks->report_block_anomalies(goto_program, message_handler);
46-
instrumenters(goto_program, *basic_blocks);
47+
basic_blocks->report_block_anomalies(
48+
function_id, goto_program, message_handler);
49+
instrumenters(function_id, goto_program, *basic_blocks);
4750
}
4851

4952
/// Instruments goto program for a given coverage criterion
5053
/// \param symbol_table: the symbol table
54+
/// \param function_id: name of \p goto_program
5155
/// \param goto_program: the goto program
5256
/// \param criterion: the coverage criterion
5357
/// \param message_handler: a message handler
@@ -57,6 +61,7 @@ void instrument_cover_goals(
5761
DEPRECATED("use instrument_cover_goals(goto_programt &...) instead")
5862
void instrument_cover_goals(
5963
const symbol_tablet &symbol_table,
64+
const irep_idt &function_id,
6065
goto_programt &goto_program,
6166
coverage_criteriont criterion,
6267
message_handlert &message_handler)
@@ -68,7 +73,7 @@ void instrument_cover_goals(
6873
instrumenters.add_from_criterion(criterion, symbol_table, goal_filters);
6974

7075
instrument_cover_goals(
71-
goto_program, instrumenters, ID_unknown, message_handler);
76+
function_id, goto_program, instrumenters, ID_unknown, message_handler);
7277
}
7378

7479
/// Create and add an instrumenter based on the given criterion
@@ -249,7 +254,7 @@ std::unique_ptr<cover_configt> get_cover_config(
249254
/// Instruments a single goto program based on the given configuration
250255
/// \param cover_config: configuration, produced using get_cover_config
251256
/// \param function_id: function name
252-
/// \param function: function function to instrument
257+
/// \param function: function to instrument
253258
/// \param message_handler: log output
254259
static void instrument_cover_goals(
255260
const cover_configt &cover_config,
@@ -281,6 +286,7 @@ static void instrument_cover_goals(
281286
if(cover_config.function_filters(function_id, function))
282287
{
283288
instrument_cover_goals(
289+
function_id,
284290
function.body,
285291
cover_config.cover_instrumenters,
286292
cover_config.mode,

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_id,
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_id
137138
<< " (missing source location)" << messaget::eom;
138139
}
139140
// The location numbers printed here are those

src/goto-instrument/cover_basic_blocks.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,16 @@ class cover_blocks_baset
4343
virtual void output(std::ostream &out) const = 0;
4444

4545
/// Output warnings about ignored blocks
46+
/// \param function_id: name of \p goto_program
4647
/// \param goto_program: The goto program
4748
/// \param message_handler: The message handler
4849
virtual void report_block_anomalies(
50+
const irep_idt &function_id,
4951
const goto_programt &goto_program,
5052
message_handlert &message_handler)
5153
{
5254
// unused parameters
55+
(void)function_id;
5356
(void)goto_program;
5457
(void)message_handler;
5558
}
@@ -78,9 +81,11 @@ class cover_basic_blockst final : public cover_blocks_baset
7881
source_location_of(std::size_t block_nr) const override;
7982

8083
/// Output warnings about ignored blocks
84+
/// \param function_id: name of \p goto_program
8185
/// \param goto_program: The goto program
8286
/// \param message_handler: The message handler
8387
void report_block_anomalies(
88+
const irep_idt &function_id,
8489
const goto_programt &goto_program,
8590
message_handlert &message_handler) override;
8691

src/goto-instrument/cover_filter.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ Author: Peter Schrammel
1414
#include <linking/static_lifetime_init.h>
1515

1616
/// Filter out functions that are not considered provided by the user
17-
/// \param identifier: a function name
17+
/// \param function_id: a function name
1818
/// \param goto_function: a goto function
1919
/// \return returns true if function is considered user-provided
2020
bool internal_functions_filtert::operator()(
21-
const irep_idt &identifier,
21+
const irep_idt &function_id,
2222
const goto_functionst::goto_functiont &goto_function) const
2323
{
24-
if(identifier == goto_functionst::entry_point())
24+
if(function_id == goto_functionst::entry_point())
2525
return false;
2626

27-
if(identifier == INITIALIZE_FUNCTION)
27+
if(function_id == INITIALIZE_FUNCTION)
2828
return false;
2929

3030
if(goto_function.is_hidden())
3131
return false;
3232

3333
// ignore Java built-ins (synthetic functions)
34-
if(has_prefix(id2string(identifier), "java::array["))
34+
if(has_prefix(id2string(function_id), "java::array["))
3535
return false;
3636

3737
// ignore if built-in library
@@ -44,31 +44,32 @@ bool internal_functions_filtert::operator()(
4444
}
4545

4646
/// Filter functions whose name match the regex
47-
/// \param identifier: a function name
47+
/// \param function_id: a function name
4848
/// \param goto_function: a goto function
4949
/// \return returns true if the function name matches
5050
bool include_pattern_filtert::operator()(
51-
const irep_idt &identifier,
51+
const irep_idt &function_id,
5252
const goto_functionst::goto_functiont &goto_function) const
5353
{
5454
(void)goto_function; // unused parameter
5555
std::smatch string_matcher;
56-
return std::regex_match(id2string(identifier), string_matcher, regex_matcher);
56+
return std::regex_match(
57+
id2string(function_id), string_matcher, regex_matcher);
5758
}
5859

5960
/// Call a goto_program non-trivial if it has:
6061
/// * Any declarations
6162
/// * At least 2 branches
6263
/// * At least 5 assignments
6364
/// These criteria are arbitrarily chosen.
64-
/// \param identifier: a function name
65+
/// \param function_id: name of \p goto_function
6566
/// \param goto_function: a goto function
6667
/// \return returns true if non-trivial
6768
bool trivial_functions_filtert::operator()(
68-
const irep_idt &identifier,
69+
const irep_idt &function_id,
6970
const goto_functionst::goto_functiont &goto_function) const
7071
{
71-
(void)identifier; // unused parameter
72+
(void)function_id; // unused parameter
7273
unsigned long count_assignments = 0, count_goto = 0;
7374
forall_goto_program_instructions(i_it, goto_function.body)
7475
{

src/goto-instrument/cover_instrument.h

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ class cover_instrumenter_baset
3737
}
3838

3939
/// Instruments a goto program
40+
/// \param function_id: name of \p goto_program
4041
/// \param goto_program: a goto program
4142
/// \param basic_blocks: detected basic blocks
4243
virtual void operator()(
44+
const irep_idt &function_id,
4345
goto_programt &goto_program,
4446
const cover_blocks_baset &basic_blocks) const
4547
{
4648
Forall_goto_program_instructions(i_it, goto_program)
4749
{
48-
instrument(goto_program, i_it, basic_blocks);
50+
instrument(function_id, goto_program, i_it, basic_blocks);
4951
}
5052
}
5153

@@ -58,20 +60,21 @@ class cover_instrumenter_baset
5860

5961
/// Override this method to implement an instrumenter
6062
virtual void instrument(
63+
const irep_idt &function_id,
6164
goto_programt &,
6265
goto_programt::targett &,
6366
const cover_blocks_baset &) const = 0;
6467

6568
void initialize_source_location(
6669
goto_programt::targett t,
6770
const std::string &comment,
68-
const irep_idt &function) const
71+
const irep_idt &function_id) const
6972
{
7073
t->source_location.set_comment(comment);
7174
t->source_location.set(ID_coverage_criterion, coverage_criterion);
7275
t->source_location.set_property_class(property_class);
73-
t->source_location.set_function(function);
74-
t->function = function;
76+
t->source_location.set_function(function_id);
77+
t->function = function_id;
7578
}
7679

7780
bool is_non_cover_assertion(goto_programt::const_targett t) const
@@ -91,14 +94,16 @@ class cover_instrumenterst
9194
const goal_filterst &);
9295

9396
/// Applies all instrumenters to the given goto program
97+
/// \param function_id: name of \p goto_program
9498
/// \param goto_program: a goto program
9599
/// \param basic_blocks: detected basic blocks of the goto program
96100
void operator()(
101+
const irep_idt &function_id,
97102
goto_programt &goto_program,
98103
const cover_blocks_baset &basic_blocks) const
99104
{
100105
for(const auto &instrumenter : instrumenters)
101-
(*instrumenter)(goto_program, basic_blocks);
106+
(*instrumenter)(function_id, goto_program, basic_blocks);
102107
}
103108

104109
private:
@@ -118,6 +123,7 @@ class cover_location_instrumentert : public cover_instrumenter_baset
118123

119124
protected:
120125
void instrument(
126+
const irep_idt &function_id,
121127
goto_programt &,
122128
goto_programt::targett &,
123129
const cover_blocks_baset &) const override;
@@ -136,6 +142,7 @@ class cover_branch_instrumentert : public cover_instrumenter_baset
136142

137143
protected:
138144
void instrument(
145+
const irep_idt &function_id,
139146
goto_programt &,
140147
goto_programt::targett &,
141148
const cover_blocks_baset &) const override;
@@ -154,6 +161,7 @@ class cover_condition_instrumentert : public cover_instrumenter_baset
154161

155162
protected:
156163
void instrument(
164+
const irep_idt &function_id,
157165
goto_programt &,
158166
goto_programt::targett &,
159167
const cover_blocks_baset &) const override;
@@ -172,6 +180,7 @@ class cover_decision_instrumentert : public cover_instrumenter_baset
172180

173181
protected:
174182
void instrument(
183+
const irep_idt &function_id,
175184
goto_programt &,
176185
goto_programt::targett &,
177186
const cover_blocks_baset &) const override;
@@ -190,6 +199,7 @@ class cover_mcdc_instrumentert : public cover_instrumenter_baset
190199

191200
protected:
192201
void instrument(
202+
const irep_idt &function_id,
193203
goto_programt &,
194204
goto_programt::targett &,
195205
const cover_blocks_baset &) const override;
@@ -208,6 +218,7 @@ class cover_path_instrumentert : public cover_instrumenter_baset
208218

209219
protected:
210220
void instrument(
221+
const irep_idt &function_id,
211222
goto_programt &,
212223
goto_programt::targett &,
213224
const cover_blocks_baset &) const override;
@@ -226,6 +237,7 @@ class cover_assertion_instrumentert : public cover_instrumenter_baset
226237

227238
protected:
228239
void instrument(
240+
const irep_idt &function_id,
229241
goto_programt &,
230242
goto_programt::targett &,
231243
const cover_blocks_baset &) const override;
@@ -244,13 +256,14 @@ class cover_cover_instrumentert : public cover_instrumenter_baset
244256

245257
protected:
246258
void instrument(
259+
const irep_idt &function_id,
247260
goto_programt &,
248261
goto_programt::targett &,
249262
const cover_blocks_baset &) const override;
250263
};
251264

252265
void cover_instrument_end_of_function(
253-
const irep_idt &function,
266+
const irep_idt &function_id,
254267
goto_programt &goto_program);
255268

256269
#endif // CPROVER_GOTO_INSTRUMENT_COVER_INSTRUMENT_H

src/goto-instrument/cover_instrument_branch.cpp

Lines changed: 4 additions & 4 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_id,
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_id);
3536
}
3637

3738
if(
@@ -44,18 +45,17 @@ 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);
5151
i_it->make_assertion(not_exprt(guard));
5252
i_it->source_location = source_location;
53-
initialize_source_location(i_it, true_comment, function);
53+
initialize_source_location(i_it, true_comment, function_id);
5454

5555
goto_program.insert_before_swap(i_it);
5656
i_it->make_assertion(guard);
5757
i_it->source_location = source_location;
58-
initialize_source_location(i_it, false_comment, function);
58+
initialize_source_location(i_it, false_comment, function_id);
5959

6060
std::advance(i_it, 2);
6161
}

src/goto-instrument/cover_instrument_condition.cpp

Lines changed: 4 additions & 4 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_id,
2021
goto_programt &goto_program,
2122
goto_programt::targett &i_it,
2223
const cover_blocks_baset &) const
@@ -33,20 +34,19 @@ 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_id, 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;
43-
initialize_source_location(i_it, comment_t, function);
43+
initialize_source_location(i_it, comment_t, function_id);
4444

4545
const std::string comment_f = "condition `" + c_string + "' false";
4646
goto_program.insert_before_swap(i_it);
4747
i_it->make_assertion(not_exprt(c));
4848
i_it->source_location = source_location;
49-
initialize_source_location(i_it, comment_f, function);
49+
initialize_source_location(i_it, comment_f, function_id);
5050
}
5151

5252
for(std::size_t i = 0; i < conditions.size() * 2; i++)

0 commit comments

Comments
 (0)