Skip to content

Commit 788bbc0

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 b555a7d commit 788bbc0

10 files changed

+100
-35
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
@@ -13,6 +13,8 @@ Author: Diffblue Ltd.
1313
#include <util/make_unique.h>
1414
#include <util/string_utils.h>
1515

16+
#include "remove_skip.h"
17+
1618
void generate_function_bodiest::generate_function_body(
1719
goto_functiont &function,
1820
symbol_tablet &symbol_table,
@@ -307,6 +309,8 @@ class havoc_generate_function_bodiest : public generate_function_bodiest,
307309
}
308310
auto end_function_instruction = add_instruction();
309311
end_function_instruction->make_end_function();
312+
313+
remove_skip(function.body);
310314
}
311315

312316
private:

src/goto-programs/remove_asm.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Date: December 2014
2020
#include <assembler/assembler_parser.h>
2121

2222
#include "goto_model.h"
23+
#include "remove_skip.h"
2324

2425
class remove_asmt
2526
{
@@ -280,20 +281,26 @@ void remove_asmt::process_instruction(
280281
void remove_asmt::process_function(
281282
goto_functionst::goto_functiont &goto_function)
282283
{
284+
bool did_something = false;
285+
283286
Forall_goto_program_instructions(it, goto_function.body)
284287
{
285288
if(it->is_other() && it->code.get_statement()==ID_asm)
286289
{
287290
goto_programt tmp_dest;
288291
process_instruction(*it, tmp_dest);
289292
it->make_skip();
293+
did_something = true;
290294

291295
goto_programt::targett next=it;
292296
next++;
293297

294298
goto_function.body.destructive_insert(next, tmp_dest);
295299
}
296300
}
301+
302+
if(did_something)
303+
remove_skip(goto_function.body);
297304
}
298305

299306
/// removes assembler

src/goto-programs/remove_returns.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Date: September 2009
1717

1818
#include "goto_model.h"
1919

20+
#include "remove_skip.h"
21+
2022
class remove_returnst
2123
{
2224
public:
@@ -342,6 +344,8 @@ bool remove_returnst::restore_returns(
342344

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

347+
bool did_something = false;
348+
345349
Forall_goto_program_instructions(i_it, goto_program)
346350
{
347351
if(i_it->is_assign())
@@ -384,9 +388,13 @@ bool remove_returnst::restore_returns(
384388

385389
i_it->make_return();
386390
i_it->code=return_code;
391+
did_something = true;
387392
}
388393
}
389394

395+
if(did_something)
396+
remove_skip(goto_program);
397+
390398
return false;
391399
}
392400

src/goto-programs/remove_virtual_functions.cpp

+37-18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Daniel Kroening, [email protected]
1616

1717
#include "class_identifier.h"
1818
#include "goto_model.h"
19+
#include "remove_skip.h"
1920
#include "resolve_inherited_component.h"
2021

2122
class remove_virtual_functionst
@@ -29,7 +30,7 @@ class remove_virtual_functionst
2930

3031
bool remove_virtual_functions(goto_programt &goto_program);
3132

32-
void remove_virtual_function(
33+
goto_programt::targett remove_virtual_function(
3334
goto_programt &goto_program,
3435
goto_programt::targett target,
3536
const dispatch_table_entriest &functions,
@@ -43,7 +44,7 @@ class remove_virtual_functionst
4344

4445
const class_hierarchyt &class_hierarchy;
4546

46-
void remove_virtual_function(
47+
goto_programt::targett remove_virtual_function(
4748
goto_programt &goto_program,
4849
goto_programt::targett target);
4950
typedef std::function<
@@ -71,7 +72,7 @@ remove_virtual_functionst::remove_virtual_functionst(
7172
{
7273
}
7374

74-
void remove_virtual_functionst::remove_virtual_function(
75+
goto_programt::targett remove_virtual_functionst::remove_virtual_function(
7576
goto_programt &goto_program,
7677
goto_programt::targett target)
7778
{
@@ -89,7 +90,7 @@ void remove_virtual_functionst::remove_virtual_function(
8990
dispatch_table_entriest functions;
9091
get_functions(function, functions);
9192

92-
remove_virtual_function(
93+
return remove_virtual_function(
9394
goto_program,
9495
target,
9596
functions,
@@ -118,7 +119,7 @@ static void create_static_function_call(
118119
call.arguments()[0].make_typecast(need_type);
119120
}
120121

121-
void remove_virtual_functionst::remove_virtual_function(
122+
goto_programt::targett remove_virtual_functionst::remove_virtual_function(
122123
goto_programt &goto_program,
123124
goto_programt::targett target,
124125
const dispatch_table_entriest &functions,
@@ -130,24 +131,30 @@ void remove_virtual_functionst::remove_virtual_function(
130131
const code_function_callt &code=
131132
to_code_function_call(target->code);
132133

134+
goto_programt::targett next_target = std::next(target);
135+
133136
if(functions.empty())
134137
{
135138
target->make_skip();
136-
return; // give up
139+
remove_skip(goto_program, target, next_target);
140+
return next_target; // give up
137141
}
138142

139143
// only one option?
140144
if(functions.size()==1 &&
141145
fallback_action==virtual_dispatch_fallback_actiont::CALL_LAST_FUNCTION)
142146
{
143147
if(functions.begin()->symbol_expr==symbol_exprt())
148+
{
144149
target->make_skip();
150+
remove_skip(goto_program, target, next_target);
151+
}
145152
else
146153
{
147154
create_static_function_call(
148155
to_code_function_call(target->code), functions.front().symbol_expr, ns);
149156
}
150-
return;
157+
return next_target;
151158
}
152159

153160
const auto &vcall_source_loc=target->source_location;
@@ -281,13 +288,15 @@ void remove_virtual_functionst::remove_virtual_function(
281288
it->source_location.set_comment(comment);
282289
}
283290

284-
goto_programt::targett next_target=target;
285-
next_target++;
286-
287291
goto_program.destructive_insert(next_target, new_code);
288292

289293
// finally, kill original invocation
290294
target->make_skip();
295+
296+
// only remove skips within the virtual-function handling block
297+
remove_skip(goto_program, target, next_target);
298+
299+
return next_target;
291300
}
292301

293302
/// Used by get_functions to track the most-derived parent that provides an
@@ -475,23 +484,29 @@ bool remove_virtual_functionst::remove_virtual_functions(
475484
{
476485
bool did_something=false;
477486

478-
Forall_goto_program_instructions(target, goto_program)
487+
for(goto_programt::instructionst::iterator
488+
target = goto_program.instructions.begin();
489+
target != goto_program.instructions.end();
490+
) // remove_virtual_function returns the next instruction to process
491+
{
479492
if(target->is_function_call())
480493
{
481494
const code_function_callt &code=
482495
to_code_function_call(target->code);
483496

484497
if(code.function().id()==ID_virtual_function)
485498
{
486-
remove_virtual_function(goto_program, target);
499+
target = remove_virtual_function(goto_program, target);
487500
did_something=true;
501+
continue;
488502
}
489503
}
490504

505+
++target;
506+
}
507+
491508
if(did_something)
492-
{
493509
goto_program.update();
494-
}
495510

496511
return did_something;
497512
}
@@ -539,7 +554,7 @@ void remove_virtual_functions(goto_model_functiont &function)
539554
rvf.remove_virtual_functions(function.get_goto_function().body);
540555
}
541556

542-
void remove_virtual_function(
557+
goto_programt::targett remove_virtual_function(
543558
symbol_tablet &symbol_table,
544559
goto_programt &goto_program,
545560
goto_programt::targett instruction,
@@ -550,18 +565,22 @@ void remove_virtual_function(
550565
class_hierarchy(symbol_table);
551566
remove_virtual_functionst rvf(symbol_table, class_hierarchy);
552567

553-
rvf.remove_virtual_function(
568+
goto_programt::targett next = rvf.remove_virtual_function(
554569
goto_program, instruction, dispatch_table, fallback_action);
570+
571+
goto_program.update();
572+
573+
return next;
555574
}
556575

557-
void remove_virtual_function(
576+
goto_programt::targett remove_virtual_function(
558577
goto_modelt &goto_model,
559578
goto_programt &goto_program,
560579
goto_programt::targett instruction,
561580
const dispatch_table_entriest &dispatch_table,
562581
virtual_dispatch_fallback_actiont fallback_action)
563582
{
564-
remove_virtual_function(
583+
return remove_virtual_function(
565584
goto_model.symbol_table,
566585
goto_program,
567586
instruction,

src/goto-programs/remove_virtual_functions.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ class dispatch_table_entryt
6666
typedef std::vector<dispatch_table_entryt> dispatch_table_entriest;
6767
typedef std::map<irep_idt, dispatch_table_entryt> dispatch_table_entries_mapt;
6868

69-
void remove_virtual_function(
69+
goto_programt::targett remove_virtual_function(
7070
goto_modelt &goto_model,
7171
goto_programt &goto_program,
7272
goto_programt::targett instruction,
7373
const dispatch_table_entriest &dispatch_table,
7474
virtual_dispatch_fallback_actiont fallback_action);
7575

76-
void remove_virtual_function(
76+
goto_programt::targett remove_virtual_function(
7777
symbol_tablet &symbol_table,
7878
goto_programt &goto_program,
7979
goto_programt::targett instruction,

src/goto-programs/string_instrumentation.cpp

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

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

2828
exprt is_zero_string(
2929
const exprt &what,
@@ -266,7 +266,7 @@ void string_instrumentationt::do_function_call(
266266
else if(identifier=="fscanf")
267267
do_fscanf(dest, target, call);
268268

269-
dest.update();
269+
remove_skip(dest);
270270
}
271271
}
272272

0 commit comments

Comments
 (0)