Skip to content

Commit 802e005

Browse files
Fix for Clang's initialization warning
1 parent 63c4740 commit 802e005

6 files changed

+65
-54
lines changed

src/cbmc/bmc.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ void bmct::slice()
346346
}
347347
}
348348
}
349-
statistics() << "Generated " << symex.total_vccs
350-
<< " VCC(s), " << symex.remaining_vccs
349+
statistics() << "Generated " << symex().total_vccs
350+
<< " VCC(s), " << symex().remaining_vccs
351351
<< " remaining after simplification" << eom;
352352
}
353353

@@ -510,12 +510,12 @@ safety_checkert::resultt bmct::initialize()
510510
return ERROR;
511511
}
512512

513-
symex.set_message_handler(get_message_handler());
514-
symex.options=options;
513+
symex().set_message_handler(get_message_handler());
514+
symex().options=options;
515515

516516
status() << "Starting Bounded Model Checking" << eom;
517517

518-
symex.last_source_location.make_nil();
518+
symex().last_source_location.make_nil();
519519

520520
// get unwinding info
521521
setup_unwind();
@@ -540,7 +540,7 @@ safety_checkert::resultt bmct::step(const goto_functionst &goto_functions)
540540
try
541541
{
542542
// perform symbolic execution
543-
symex(goto_functions);
543+
symex()(goto_functions);
544544

545545
// add a partial ordering, if required
546546
if(equation.has_threads())
@@ -575,8 +575,8 @@ safety_checkert::resultt bmct::step(const goto_functionst &goto_functions)
575575
slice();
576576

577577
{
578-
statistics() << "Generated " << symex.total_vccs
579-
<< " VCC(s), " << symex.remaining_vccs
578+
statistics() << "Generated " << symex().total_vccs
579+
<< " VCC(s), " << symex().remaining_vccs
580580
<< " remaining after simplification" << eom;
581581
}
582582

@@ -604,7 +604,7 @@ safety_checkert::resultt bmct::step(const goto_functionst &goto_functions)
604604

605605
// any properties to check at all?
606606
if(!options.get_bool_option("program-only") &&
607-
symex.remaining_vccs==0)
607+
symex().remaining_vccs==0)
608608
{
609609
report_success();
610610
output_graphml(SAFE, goto_functions);
@@ -729,12 +729,12 @@ void bmct::setup_unwind()
729729
long uw=unsafe_string2int(val.substr(val.rfind(":")+1));
730730

731731
if(thread_nr_set)
732-
symex.set_unwind_thread_loop_limit(thread_nr, id, uw);
732+
symex().set_unwind_thread_loop_limit(thread_nr, id, uw);
733733
else
734-
symex.set_unwind_loop_limit(id, uw);
734+
symex().set_unwind_loop_limit(id, uw);
735735
}
736736
}
737737

738738
if(options.get_option("unwind")!="")
739-
symex.set_unwind_limit(options.get_unsigned_int_option("unwind"));
739+
symex().set_unwind_limit(options.get_unsigned_int_option("unwind"));
740740
}

src/cbmc/bmc.h

+12-10
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ class bmct:public safety_checkert
4242
equation(ns),
4343
symex_ptr(new symex_bmct(ns, new_symbol_table, equation)),
4444
prop_conv(_prop_conv),
45-
ui(ui_message_handlert::PLAIN),
46-
symex(*symex_ptr)
45+
ui(ui_message_handlert::PLAIN)
4746
{
48-
symex.constant_propagation=options.get_bool_option("propagation");
47+
symex().constant_propagation=options.get_bool_option("propagation");
4948
}
5049

5150
virtual ~bmct() { }
@@ -73,22 +72,20 @@ class bmct:public safety_checkert
7372
}
7473

7574
protected:
75+
// for initialization of derived classes
7676
bmct(
7777
const optionst &_options,
7878
const symbol_tablet &_symbol_table,
79-
message_handlert &_message_handler,
8079
prop_convt& _prop_conv,
81-
symex_bmct *_symex_ptr):
80+
message_handlert &_message_handler):
8281
safety_checkert(ns, _message_handler),
8382
options(_options),
8483
ns(_symbol_table, new_symbol_table),
8584
equation(ns),
86-
symex_ptr(_symex_ptr),
85+
symex_ptr(NULL),
8786
prop_conv(_prop_conv),
88-
ui(ui_message_handlert::PLAIN),
89-
symex(dynamic_cast<symex_bmct &>(*symex_ptr))
87+
ui(ui_message_handlert::PLAIN)
9088
{
91-
symex.constant_propagation=options.get_bool_option("propagation");
9289
}
9390

9491
const optionst &options;
@@ -149,7 +146,12 @@ class bmct:public safety_checkert
149146
friend class fault_localizationt;
150147

151148
private:
152-
symex_bmct &symex;
149+
// We cannot use a reference member here
150+
// because the initialization sequence would not be clean (Clang complains)
151+
symex_bmct &symex()
152+
{
153+
return dynamic_cast<symex_bmct &>(*symex_ptr);
154+
}
153155
};
154156

155157
#endif // CPROVER_CBMC_BMC_H

src/cbmc/bmc_incremental.cpp

+12-11
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ safety_checkert::resultt bmc_incrementalt::step(
3030
try
3131
{
3232
// We count only new assertions.
33-
symex.total_vccs=0;
34-
symex.remaining_vccs=0;
33+
symex().total_vccs=0;
34+
symex().remaining_vccs=0;
3535

3636
// perform symbolic execution
3737
bool symex_done=
38-
symex(
39-
symex_state,goto_functions,
38+
symex()(
39+
symex_state,
40+
goto_functions,
4041
goto_functions.function_map.at(goto_functions.entry_point()).body);
4142

4243
// add a partial ordering, if required
@@ -59,7 +60,7 @@ safety_checkert::resultt bmc_incrementalt::step(
5960
return result;
6061

6162
// any properties to check at all?
62-
if(symex.remaining_vccs==0)
63+
if(symex().remaining_vccs==0)
6364
{
6465
report_success();
6566
result=safety_checkert::SAFE;
@@ -121,16 +122,16 @@ safety_checkert::resultt bmc_incrementalt::run(
121122

122123
// check unwinding assertions
123124
if(result==safety_checkert::UNKNOWN &&
124-
symex.add_loop_check())
125+
symex().add_loop_check())
125126
{
126127
resultt loop_check_result=
127128
stop_on_fail(goto_functions, prop_conv);
128129
bool earliest_loop_exit=
129130
options.get_bool_option("earliest-loop-exit");
130131
if(loop_check_result==SAFE)
131-
symex.update_loop_info(earliest_loop_exit ? false : true);
132+
symex().update_loop_info(earliest_loop_exit ? false : true);
132133
else if(loop_check_result==UNSAFE)
133-
symex.update_loop_info(earliest_loop_exit ? true : false);
134+
symex().update_loop_info(earliest_loop_exit ? true : false);
134135
}
135136
}
136137

@@ -154,11 +155,11 @@ void bmc_incrementalt::setup_unwind()
154155
bmct::setup_unwind();
155156

156157
if(options.get_option("unwind-min")!="")
157-
symex.incr_min_unwind=options.get_unsigned_int_option("unwind-min");
158+
symex().incr_min_unwind=options.get_unsigned_int_option("unwind-min");
158159
if(options.get_option("unwind-max")!="")
159-
symex.incr_max_unwind=options.get_unsigned_int_option("unwind-max");
160+
symex().incr_max_unwind=options.get_unsigned_int_option("unwind-max");
160161
else
161-
symex.incr_max_unwind=std::numeric_limits<unsigned>::max();
162+
symex().incr_max_unwind=std::numeric_limits<unsigned>::max();
162163

163164
status() << "Using incremental mode" << eom;
164165
prop_conv.set_all_frozen();

src/cbmc/bmc_incremental.h

+10-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,13 @@ class bmc_incrementalt:public bmct
3333
bmct(
3434
_options,
3535
_symbol_table,
36-
_message_handler,
3736
_prop_conv,
38-
new symex_bmc_incrementalt(ns, new_symbol_table, equation)),
39-
goto_functions(_goto_functions),
40-
symex(dynamic_cast<symex_bmc_incrementalt &>(*symex_ptr))
41-
{}
37+
_message_handler),
38+
goto_functions(_goto_functions)
39+
{
40+
symex_ptr=new symex_bmc_incrementalt(ns, new_symbol_table, equation);
41+
symex().constant_propagation=options.get_bool_option("propagation");
42+
}
4243

4344
virtual ~bmc_incrementalt() { }
4445

@@ -61,7 +62,10 @@ class bmc_incrementalt:public bmct
6162
virtual void setup_unwind();
6263

6364
private:
64-
symex_bmc_incrementalt &symex;
65+
symex_bmc_incrementalt &symex()
66+
{
67+
return dynamic_cast<symex_bmc_incrementalt &>(*symex_ptr);
68+
}
6569
};
6670

6771
#endif

src/cbmc/bmc_incremental_one_loop.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ safety_checkert::resultt bmc_incremental_one_loopt::step(
2828
try
2929
{
3030
// We count only new assertions.
31-
symex.total_vccs=0;
32-
symex.remaining_vccs=0;
31+
symex().total_vccs=0;
32+
symex().remaining_vccs=0;
3333

3434
// perform symbolic execution
3535
bool symex_done=
36-
symex(
36+
symex()(
3737
symex_state,goto_functions,
3838
goto_functions.function_map.at(goto_functions.entry_point()).body);
3939

@@ -63,7 +63,7 @@ safety_checkert::resultt bmc_incremental_one_loopt::step(
6363
resultt result=safety_checkert::UNKNOWN;
6464

6565
// any properties to check at all?
66-
if(symex.remaining_vccs==0)
66+
if(symex().remaining_vccs==0)
6767
{
6868
report_success();
6969
result=safety_checkert::SAFE;
@@ -144,12 +144,12 @@ void bmc_incremental_one_loopt::setup_unwind()
144144
bmct::setup_unwind();
145145

146146
if(options.get_option("unwind-min")!="")
147-
symex.incr_min_unwind=options.get_unsigned_int_option("unwind-min");
147+
symex().incr_min_unwind=options.get_unsigned_int_option("unwind-min");
148148
if(options.get_option("unwind-max")!="")
149-
symex.incr_max_unwind=options.get_unsigned_int_option("unwind-max");
150-
symex.ignore_assertions=(symex.incr_min_unwind>=2) &&
149+
symex().incr_max_unwind=options.get_unsigned_int_option("unwind-max");
150+
symex().ignore_assertions=(symex().incr_min_unwind>=2) &&
151151
options.get_bool_option("ignore-assertions-before-unwind-min");
152-
symex.incr_loop_id=options.get_option("incremental-check");
152+
symex().incr_loop_id=options.get_option("incremental-check");
153153

154154
status() << "Using incremental mode" << eom;
155155
prop_conv.set_all_frozen();

src/cbmc/bmc_incremental_one_loop.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ class bmc_incremental_one_loopt:public bmct
3434
bmct(
3535
_options,
3636
_symbol_table,
37-
_message_handler,
3837
_prop_conv,
39-
new symex_bmc_incremental_one_loopt(
40-
ns, new_symbol_table, equation, prop_conv)),
41-
goto_functions(_goto_functions),
42-
symex(dynamic_cast<symex_bmc_incremental_one_loopt &>(*symex_ptr))
43-
{}
38+
_message_handler),
39+
goto_functions(_goto_functions)
40+
{
41+
symex_ptr=new symex_bmc_incremental_one_loopt(
42+
ns, new_symbol_table, equation, prop_conv);
43+
symex().constant_propagation=options.get_bool_option("propagation");
44+
}
4445

4546
virtual ~bmc_incremental_one_loopt() {}
4647

@@ -63,7 +64,10 @@ class bmc_incremental_one_loopt:public bmct
6364
virtual void setup_unwind();
6465

6566
private:
66-
symex_bmc_incremental_one_loopt &symex;
67+
symex_bmc_incremental_one_loopt &symex()
68+
{
69+
return dynamic_cast<symex_bmc_incremental_one_loopt &>(*symex_ptr);
70+
}
6771
};
6872

6973
#endif

0 commit comments

Comments
 (0)