Skip to content

Commit 0114f7e

Browse files
author
Daniel Kroening
committed
source locations in location coverage
1 parent 5a5bb12 commit 0114f7e

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/goto-instrument/cover.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,24 @@ class basic_blockst
2727

2828
block_map[it]=block_count;
2929

30+
if(!it->source_location.is_nil() &&
31+
source_location_map.find(block_count)==source_location_map.end())
32+
source_location_map[block_count]=it->source_location;
33+
3034
next_is_target=
3135
it->is_goto() || it->is_return() ||
3236
it->is_function_call() || it->is_assume();
3337
}
3438
}
35-
39+
40+
// map program locations to block numbers
3641
typedef std::map<goto_programt::const_targett, unsigned> block_mapt;
3742
block_mapt block_map;
3843

44+
// map block numbers to source code locations
45+
typedef std::map<unsigned, source_locationt> source_location_mapt;
46+
source_location_mapt source_location_map;
47+
3948
inline unsigned operator[](goto_programt::const_targett t)
4049
{
4150
return block_map[t];
@@ -134,12 +143,14 @@ void instrument_cover_goals(
134143
{
135144
std::string b=i2string(block_nr);
136145
std::string id=id2string(i_it->function)+"#"+b;
137-
if(i_it->source_location.get_file()!="")
146+
source_locationt source_location=
147+
basic_blocks.source_location_map[block_nr];
148+
149+
if(source_location.get_file()!="")
138150
{
139151
std::string comment=
140-
"block "+i_it->source_location.as_string()+" "+i2string(i_it->location_number);
152+
"block "+source_location.as_string()+" "+i2string(i_it->location_number);
141153

142-
source_locationt source_location=i_it->source_location;
143154
goto_program.insert_before_swap(i_it);
144155
i_it->make_assertion(false_exprt());
145156
i_it->source_location=source_location;

src/goto-programs/goto_convert.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2224,7 +2224,8 @@ void goto_convertt::generate_ifthenelse(
22242224
goto_programt tmp_z;
22252225
goto_programt::targett z=tmp_z.add_instruction();
22262226
z->make_skip();
2227-
z->source_location=source_location;
2227+
// We deliberately don't set a location for 'z', it's a dummy
2228+
// target.
22282229

22292230
// y: Q;
22302231
goto_programt tmp_y;

0 commit comments

Comments
 (0)