Skip to content

Commit 7e71a71

Browse files
lucasccordeiropeterschrammel
authored andcommitted
do not produce test goals for constructor and destructor methods
1 parent 2440baf commit 7e71a71

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed

src/cbmc/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ OBJ += ../ansi-c/ansi-c$(LIBEXT) \
2727
../xmllang/xmllang$(LIBEXT) \
2828
../assembler/assembler$(LIBEXT) \
2929
../solvers/solvers$(LIBEXT) \
30-
../util/util$(LIBEXT)
30+
../util/util$(LIBEXT) \
31+
../json/json$(LIBEXT)
3132

3233
INCLUDES= -I ..
3334

src/goto-instrument/cover.cpp

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,23 @@ coverage_goalst coverage_goalst::get_coverage_goals(const std::string &coverage,
135135
source_locationt source_location;
136136
goals.set_no_trivial_tests(false);
137137

138-
//check coverage file
138+
// check coverage file
139139
if(parse_json(coverage, message_handler, json))
140140
{
141141
messaget message(message_handler);
142142
message.error() << coverage << " file is not a valid json file"
143143
<< messaget::eom;
144-
exit(0);
144+
exit(6);
145145
}
146146

147-
//make sure that we have an array of elements
147+
// make sure that we have an array of elements
148148
if(!json.is_array())
149149
{
150150
messaget message(message_handler);
151-
message.error() << "expecting an array in the " << coverage << " file, but got "
151+
message.error() << "expecting an array in the " << coverage
152+
<< " file, but got "
152153
<< json << messaget::eom;
153-
exit(0);
154+
exit(6);
154155
}
155156

156157
irep_idt file, function, line;
@@ -159,29 +160,28 @@ coverage_goalst coverage_goalst::get_coverage_goals(const std::string &coverage,
159160
it!=json.array.end();
160161
it++)
161162
{
162-
163-
//get the file of each existing goal
163+
// get the file of each existing goal
164164
file=(*it)["file"].value;
165165
source_location.set_file(file);
166166

167-
//get the function of each existing goal
167+
// get the function of each existing goal
168168
function=(*it)["function"].value;
169169
source_location.set_function(function);
170170

171-
//get the lines array
172-
if ((*it)["lines"].is_array())
173-
{
174-
for(jsont::arrayt::const_iterator
175-
itg=(*it)["lines"].array.begin();
176-
itg!=(*it)["lines"].array.end();
177-
itg++)
178-
{
179-
//get the line of each existing goal
171+
// get the lines array
172+
if((*it)["lines"].is_array())
173+
{
174+
for(jsont::arrayt::const_iterator
175+
itg=(*it)["lines"].array.begin();
176+
itg!=(*it)["lines"].array.end();
177+
itg++)
178+
{
179+
// get the line of each existing goal
180180
line=(*itg)["number"].value;
181181
source_location.set_line(line);
182182
goals.set_goals(source_location);
183-
}
184-
}
183+
}
184+
}
185185
}
186186
return goals;
187187
}
@@ -218,12 +218,12 @@ Function: coverage_goalst::is_existing_goal
218218
bool coverage_goalst::is_existing_goal(source_locationt source_location)
219219
{
220220
std::vector<source_locationt>::iterator it = existing_goals.begin();
221-
while (it!=existing_goals.end())
221+
while(it!=existing_goals.end())
222222
{
223-
if (!source_location.get_file().compare(it->get_file()) &&
224-
!source_location.get_function().compare(it->get_function()) &&
225-
!source_location.get_line().compare(it->get_line()))
226-
break;
223+
if(!source_location.get_file().compare(it->get_file()) &&
224+
!source_location.get_function().compare(it->get_function()) &&
225+
!source_location.get_line().compare(it->get_line()))
226+
break;
227227
++it;
228228
}
229229
if(it == existing_goals.end())
@@ -1347,9 +1347,9 @@ void instrument_cover_goals(
13471347
source_locationt source_location=
13481348
basic_blocks.source_location_map[block_nr];
13491349

1350-
//check whether the current goal already exists
1350+
// check whether the current goal already exists
13511351
if(goals.is_existing_goal(source_location) &&
1352-
!source_location.get_file().empty() &&
1352+
!source_location.get_file().empty() &&
13531353
source_location.get_file()[0]!='<')
13541354
{
13551355
std::string comment="block "+b;
@@ -1639,10 +1639,10 @@ void instrument_cover_goals(
16391639
f_it->first=="__CPROVER_initialize")
16401640
continue;
16411641

1642-
//empty set of existing goals
1642+
// empty set of existing goals
16431643
coverage_goalst goals;
16441644
instrument_cover_goals(symbol_table, f_it->second.body,
1645-
criterion, goals);
1645+
criterion, goals);
16461646
}
16471647
}
16481648

@@ -1662,8 +1662,8 @@ bool consider_goals(
16621662
const goto_programt &goto_program,
16631663
coverage_goalst &goals)
16641664
{
1665-
//check whether we should eliminate trivial goals
1666-
if (!goals.get_no_trivial_tests())
1665+
// check whether we should eliminate trivial goals
1666+
if(!goals.get_no_trivial_tests())
16671667
return true;
16681668

16691669
bool result;
@@ -1672,16 +1672,19 @@ bool consider_goals(
16721672
forall_goto_program_instructions(i_it, goto_program)
16731673
{
16741674
if(i_it->is_goto())
1675-
++count_goto;
1676-
else if (i_it->is_assign())
1675+
++count_goto;
1676+
else if(i_it->is_assign())
16771677
++count_assignments;
1678-
else if (i_it->is_decl())
1678+
else if(i_it->is_decl())
16791679
++count_decl;
16801680
}
16811681

1682-
//this might be a get or set method (pattern)
1683-
result = !((count_decl==0) && (count_goto<=1) &&
1684-
(count_assignments>0 && count_assignments<5));
1682+
// check whether this is a constructor/destructor or a get/set (pattern)
1683+
if(!count_goto && !count_assignments && !count_decl)
1684+
result=false;
1685+
else
1686+
result = !((count_decl==0) && (count_goto<=1) &&
1687+
(count_assignments>0 && count_assignments<5));
16851688

16861689
return result;
16871690
}

0 commit comments

Comments
 (0)