Skip to content

Commit aab97b4

Browse files
committed
Run remove_skip in passes that may introduce skips
The only passes left out are set_properties and remove_unreachable as the caller may still find value in those instructions replaced by a skip. (This need not be true and it may as well be safe to run remove_skip for those as well.) Fixes: diffblue#2067
1 parent a530c15 commit aab97b4

10 files changed

+99
-34
lines changed

src/analyses/goto_check.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Author: Daniel Kroening, [email protected]
3131
#include <langapi/language.h>
3232
#include <langapi/mode.h>
3333

34+
#include <goto-programs/remove_skip.h>
35+
3436
#include "local_bitvector_analysis.h"
3537

3638
class goto_checkt
@@ -1475,6 +1477,8 @@ void goto_checkt::goto_check(
14751477
assertions.clear();
14761478
mode = _mode;
14771479

1480+
bool did_something = false;
1481+
14781482
local_bitvector_analysist local_bitvector_analysis_obj(goto_function);
14791483
local_bitvector_analysis=&local_bitvector_analysis_obj;
14801484

@@ -1625,13 +1629,15 @@ void goto_checkt::goto_check(
16251629
(!is_user_provided && !enable_built_in_assertions))
16261630
{
16271631
i.make_skip();
1632+
did_something = true;
16281633
}
16291634
}
16301635
else if(i.is_assume())
16311636
{
16321637
if(!enable_assumptions)
16331638
{
16341639
i.make_skip();
1640+
did_something = true;
16351641
}
16361642
}
16371643
else if(i.is_dead())
@@ -1719,6 +1725,7 @@ void goto_checkt::goto_check(
17191725
}
17201726

17211727
// insert new instructions -- make sure targets are not moved
1728+
did_something |= !new_code.instructions.empty();
17221729

17231730
while(!new_code.instructions.empty())
17241731
{
@@ -1727,6 +1734,9 @@ void goto_checkt::goto_check(
17271734
it++;
17281735
}
17291736
}
1737+
1738+
if(did_something)
1739+
remove_skip(goto_program);
17301740
}
17311741

17321742
void goto_check(

src/goto-instrument/cover.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Date: May 2016
2020
#include <util/options.h>
2121
#include <util/deprecate.h>
2222

23+
#include <goto-programs/remove_skip.h>
24+
2325
#include "cover_basic_blocks.h"
2426

2527
/// Applies instrumenters to given goto program
@@ -283,7 +285,7 @@ static void instrument_cover_goals(
283285
}
284286

285287
if(changed)
286-
function.body.update();
288+
remove_skip(function.body);
287289
}
288290

289291
/// Instruments a single goto program based on the given configuration

src/goto-instrument/goto_instrument_parse_options.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,6 @@ int goto_instrument_parse_optionst::doit()
204204
goto_unwindt goto_unwind;
205205
goto_unwind(goto_model, unwind_set, k, unwind_strategy);
206206

207-
goto_model.goto_functions.update();
208-
goto_model.goto_functions.compute_loop_numbers();
209-
210207
if(cmdline.isset("log"))
211208
{
212209
std::string filename=cmdline.get_value("log");
@@ -232,6 +229,10 @@ int goto_instrument_parse_optionst::doit()
232229
std::cout << result << '\n';
233230
}
234231
}
232+
233+
// goto_unwind holds references to instructions, only do remove_skip
234+
// after having generated the log above
235+
remove_skip(goto_model);
235236
}
236237
}
237238

src/goto-programs/generate_function_bodies.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Author: Diffblue Ltd.
2020
#include <util/pointer_offset_size.h>
2121
#include <util/arith_tools.h>
2222

23+
#include "remove_skip.h"
24+
2325
void generate_function_bodiest::generate_function_body(
2426
goto_functiont &function,
2527
symbol_tablet &symbol_table,
@@ -314,6 +316,8 @@ class havoc_generate_function_bodiest : public generate_function_bodiest,
314316
}
315317
auto end_function_instruction = add_instruction();
316318
end_function_instruction->make_end_function();
319+
320+
remove_skip(function.body);
317321
}
318322

319323
private:

src/goto-programs/remove_asm.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Date: December 2014
2222

2323
#include <assembler/assembler_parser.h>
2424

25+
#include "remove_skip.h"
26+
2527
class remove_asmt
2628
{
2729
public:
@@ -281,20 +283,26 @@ void remove_asmt::process_instruction(
281283
void remove_asmt::process_function(
282284
goto_functionst::goto_functiont &goto_function)
283285
{
286+
bool did_something = false;
287+
284288
Forall_goto_program_instructions(it, goto_function.body)
285289
{
286290
if(it->is_other() && it->code.get_statement()==ID_asm)
287291
{
288292
goto_programt tmp_dest;
289293
process_instruction(*it, tmp_dest);
290294
it->make_skip();
295+
did_something = true;
291296

292297
goto_programt::targett next=it;
293298
next++;
294299

295300
goto_function.body.destructive_insert(next, tmp_dest);
296301
}
297302
}
303+
304+
if(did_something)
305+
remove_skip(goto_function.body);
298306
}
299307

300308
/// removes assembler

src/goto-programs/remove_returns.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Date: September 2009
1616
#include <util/std_expr.h>
1717
#include <util/symbol_table.h>
1818

19+
#include "remove_skip.h"
20+
1921
class remove_returnst
2022
{
2123
public:
@@ -341,6 +343,8 @@ bool remove_returnst::restore_returns(
341343

342344
goto_programt &goto_program=f_it->second.body;
343345

346+
bool did_something = false;
347+
344348
Forall_goto_program_instructions(i_it, goto_program)
345349
{
346350
if(i_it->is_assign())
@@ -383,9 +387,13 @@ bool remove_returnst::restore_returns(
383387

384388
i_it->make_return();
385389
i_it->code=return_code;
390+
did_something = true;
386391
}
387392
}
388393

394+
if(did_something)
395+
remove_skip(goto_program);
396+
389397
return false;
390398
}
391399

src/goto-programs/remove_virtual_functions.cpp

+37-20
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Author: Daniel Kroening, [email protected]
1313
#include "remove_virtual_functions.h"
1414
#include "class_hierarchy.h"
1515
#include "class_identifier.h"
16-
17-
#include <goto-programs/resolve_inherited_component.h>
16+
#include "remove_skip.h"
17+
#include "resolve_inherited_component.h"
1818

1919
#include <util/c_types.h>
2020
#include <util/prefix.h>
@@ -31,7 +31,7 @@ class remove_virtual_functionst
3131

3232
bool remove_virtual_functions(goto_programt &goto_program);
3333

34-
void remove_virtual_function(
34+
goto_programt::targett remove_virtual_function(
3535
goto_programt &goto_program,
3636
goto_programt::targett target,
3737
const dispatch_table_entriest &functions,
@@ -45,7 +45,7 @@ class remove_virtual_functionst
4545

4646
const class_hierarchyt &class_hierarchy;
4747

48-
void remove_virtual_function(
48+
goto_programt::targett remove_virtual_function(
4949
goto_programt &goto_program,
5050
goto_programt::targett target);
5151
typedef std::function<
@@ -73,7 +73,7 @@ remove_virtual_functionst::remove_virtual_functionst(
7373
{
7474
}
7575

76-
void remove_virtual_functionst::remove_virtual_function(
76+
goto_programt::targett remove_virtual_functionst::remove_virtual_function(
7777
goto_programt &goto_program,
7878
goto_programt::targett target)
7979
{
@@ -91,7 +91,7 @@ void remove_virtual_functionst::remove_virtual_function(
9191
dispatch_table_entriest functions;
9292
get_functions(function, functions);
9393

94-
remove_virtual_function(
94+
return remove_virtual_function(
9595
goto_program,
9696
target,
9797
functions,
@@ -120,7 +120,7 @@ static void create_static_function_call(
120120
call.arguments()[0].make_typecast(need_type);
121121
}
122122

123-
void remove_virtual_functionst::remove_virtual_function(
123+
goto_programt::targett remove_virtual_functionst::remove_virtual_function(
124124
goto_programt &goto_program,
125125
goto_programt::targett target,
126126
const dispatch_table_entriest &functions,
@@ -132,24 +132,30 @@ void remove_virtual_functionst::remove_virtual_function(
132132
const code_function_callt &code=
133133
to_code_function_call(target->code);
134134

135+
goto_programt::targett next_target = std::next(target);
136+
135137
if(functions.empty())
136138
{
137139
target->make_skip();
138-
return; // give up
140+
remove_skip(goto_program, target, next_target);
141+
return next_target; // give up
139142
}
140143

141144
// only one option?
142145
if(functions.size()==1 &&
143146
fallback_action==virtual_dispatch_fallback_actiont::CALL_LAST_FUNCTION)
144147
{
145148
if(functions.begin()->symbol_expr==symbol_exprt())
149+
{
146150
target->make_skip();
151+
remove_skip(goto_program, target, next_target);
152+
}
147153
else
148154
{
149155
create_static_function_call(
150156
to_code_function_call(target->code), functions.front().symbol_expr, ns);
151157
}
152-
return;
158+
return next_target;
153159
}
154160

155161
const auto &vcall_source_loc=target->source_location;
@@ -283,13 +289,14 @@ void remove_virtual_functionst::remove_virtual_function(
283289
it->source_location.set_comment(comment);
284290
}
285291

286-
goto_programt::targett next_target=target;
287-
next_target++;
288-
289292
goto_program.destructive_insert(next_target, new_code);
290293

291294
// finally, kill original invocation
292295
target->make_skip();
296+
297+
remove_skip(goto_program, target, next_target);
298+
299+
return next_target;
293300
}
294301

295302
/// Used by get_functions to track the most-derived parent that provides an
@@ -472,23 +479,29 @@ bool remove_virtual_functionst::remove_virtual_functions(
472479
{
473480
bool did_something=false;
474481

475-
Forall_goto_program_instructions(target, goto_program)
482+
for(goto_programt::instructionst::iterator
483+
target = goto_program.instructions.begin();
484+
target != goto_program.instructions.end();
485+
) // no ++target
486+
{
476487
if(target->is_function_call())
477488
{
478489
const code_function_callt &code=
479490
to_code_function_call(target->code);
480491

481492
if(code.function().id()==ID_virtual_function)
482493
{
483-
remove_virtual_function(goto_program, target);
494+
target = remove_virtual_function(goto_program, target);
484495
did_something=true;
496+
continue;
485497
}
486498
}
487499

500+
++target;
501+
}
502+
488503
if(did_something)
489-
{
490504
goto_program.update();
491-
}
492505

493506
return did_something;
494507
}
@@ -536,7 +549,7 @@ void remove_virtual_functions(goto_model_functiont &function)
536549
rvf.remove_virtual_functions(function.get_goto_function().body);
537550
}
538551

539-
void remove_virtual_function(
552+
goto_programt::targett remove_virtual_function(
540553
symbol_tablet &symbol_table,
541554
goto_programt &goto_program,
542555
goto_programt::targett instruction,
@@ -547,18 +560,22 @@ void remove_virtual_function(
547560
class_hierarchy(symbol_table);
548561
remove_virtual_functionst rvf(symbol_table, class_hierarchy);
549562

550-
rvf.remove_virtual_function(
563+
goto_programt::targett next = rvf.remove_virtual_function(
551564
goto_program, instruction, dispatch_table, fallback_action);
565+
566+
goto_program.update();
567+
568+
return next;
552569
}
553570

554-
void remove_virtual_function(
571+
goto_programt::targett remove_virtual_function(
555572
goto_modelt &goto_model,
556573
goto_programt &goto_program,
557574
goto_programt::targett instruction,
558575
const dispatch_table_entriest &dispatch_table,
559576
virtual_dispatch_fallback_actiont fallback_action)
560577
{
561-
remove_virtual_function(
578+
return remove_virtual_function(
562579
goto_model.symbol_table,
563580
goto_program,
564581
instruction,

src/goto-programs/remove_virtual_functions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ class dispatch_table_entryt
5959
typedef std::vector<dispatch_table_entryt> dispatch_table_entriest;
6060
typedef std::map<irep_idt, dispatch_table_entryt> dispatch_table_entries_mapt;
6161

62-
void remove_virtual_function(
62+
goto_programt::targett remove_virtual_function(
6363
goto_modelt &goto_model,
6464
goto_programt &goto_program,
6565
goto_programt::targett instruction,
6666
const dispatch_table_entriest &dispatch_table,
6767
virtual_dispatch_fallback_actiont fallback_action);
6868

69-
void remove_virtual_function(
69+
goto_programt::targett remove_virtual_function(
7070
symbol_tablet &symbol_table,
7171
goto_programt &goto_program,
7272
goto_programt::targett instruction,

src/goto-programs/string_instrumentation.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Author: Daniel Kroening, [email protected]
2323

2424
#include <goto-programs/format_strings.h>
2525
#include <goto-programs/goto_model.h>
26+
#include <goto-programs/remove_skip.h>
2627

2728

2829
exprt is_zero_string(
@@ -266,7 +267,7 @@ void string_instrumentationt::do_function_call(
266267
else if(identifier=="fscanf")
267268
do_fscanf(dest, target, call);
268269

269-
dest.update();
270+
remove_skip(dest);
270271
}
271272
}
272273

0 commit comments

Comments
 (0)