Skip to content

Commit 970cbc1

Browse files
Merge pull request #3820 from romainbrenguier/clean-up/guards
Remove guardt inheritance on exprt [TG-5977]
2 parents 1b22b57 + 69d82ca commit 970cbc1

17 files changed

+80
-85
lines changed

src/analyses/goto_check.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,16 +1407,15 @@ void goto_checkt::add_guarded_claim(
14071407
return;
14081408

14091409
// add the guard
1410-
exprt guard_expr=guard.as_expr();
14111410

14121411
exprt new_expr;
14131412

1414-
if(guard_expr.is_true())
1413+
if(guard.is_true())
14151414
new_expr.swap(expr);
14161415
else
14171416
{
14181417
new_expr=exprt(ID_implies, bool_typet());
1419-
new_expr.move_to_operands(guard_expr, expr);
1418+
new_expr.add_to_operands(guard.as_expr(), std::move(expr));
14201419
}
14211420

14221421
if(assertions.insert(new_expr).second)
@@ -1491,8 +1490,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard, bool address)
14911490
guard.add(op);
14921491
}
14931492

1494-
guard.swap(old_guard);
1495-
1493+
guard = std::move(old_guard);
14961494
return;
14971495
}
14981496
else if(expr.id()==ID_if)
@@ -1514,14 +1512,14 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard, bool address)
15141512
guardt old_guard=guard;
15151513
guard.add(expr.op0());
15161514
check_rec(expr.op1(), guard, false);
1517-
guard.swap(old_guard);
1515+
guard = std::move(old_guard);
15181516
}
15191517

15201518
{
15211519
guardt old_guard=guard;
15221520
guard.add(not_exprt(expr.op0()));
15231521
check_rec(expr.op2(), guard, false);
1524-
guard.swap(old_guard);
1522+
guard = std::move(old_guard);
15251523
}
15261524

15271525
return;
@@ -1634,7 +1632,7 @@ void goto_checkt::check_rec(const exprt &expr, guardt &guard, bool address)
16341632

16351633
void goto_checkt::check(const exprt &expr)
16361634
{
1637-
guardt guard;
1635+
guardt guard{true_exprt{}};
16381636
check_rec(expr, guard, false);
16391637
}
16401638

@@ -1764,7 +1762,7 @@ void goto_checkt::goto_check(
17641762
"pointer dereference",
17651763
i.source_location,
17661764
pointer,
1767-
guardt());
1765+
guardt(true_exprt()));
17681766
}
17691767
}
17701768

@@ -1802,7 +1800,7 @@ void goto_checkt::goto_check(
18021800
"pointer dereference",
18031801
i.source_location,
18041802
pointer,
1805-
guardt());
1803+
guardt(true_exprt()));
18061804
}
18071805

18081806
// this has no successor
@@ -1883,7 +1881,7 @@ void goto_checkt::goto_check(
18831881
"memory-leak",
18841882
source_location,
18851883
eq,
1886-
guardt());
1884+
guardt(true_exprt()));
18871885
}
18881886
}
18891887

src/analyses/goto_rw.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,15 +685,15 @@ void rw_guarded_range_set_value_sett::get_objects_if(
685685
{
686686
get_objects_rec(get_modet::READ, if_expr.cond());
687687

688-
guardt guard_bak1(guard), guard_bak2(guard);
688+
guardt copy = guard;
689689

690690
guard.add(not_exprt(if_expr.cond()));
691691
get_objects_rec(mode, if_expr.false_case(), range_start, size);
692-
guard.swap(guard_bak1);
692+
guard = copy;
693693

694694
guard.add(if_expr.cond());
695695
get_objects_rec(mode, if_expr.true_case(), range_start, size);
696-
guard.swap(guard_bak2);
696+
guard = std::move(copy);
697697
}
698698
}
699699

src/analyses/goto_rw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett
370370
get_modet mode,
371371
const exprt &expr) override
372372
{
373-
guard = true_exprt();
373+
guard = guardt(true_exprt());
374374

375375
rw_range_set_value_sett::get_objects_rec(_function, _target, mode, expr);
376376
}
@@ -384,7 +384,7 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett
384384
}
385385

386386
protected:
387-
guardt guard;
387+
guardt guard = guardt(true_exprt());
388388

389389
using rw_range_sett::get_objects_rec;
390390

src/goto-instrument/rw_set.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ void _rw_set_loct::compute()
7979
void _rw_set_loct::assign(const exprt &lhs, const exprt &rhs)
8080
{
8181
read(rhs);
82-
read_write_rec(lhs, false, true, "", guardt());
82+
read_write_rec(lhs, false, true, "", guardt(true_exprt()));
8383
}
8484

8585
void _rw_set_loct::read_write_rec(

src/goto-instrument/rw_set.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class _rw_set_loct:public rw_set_baset
149149

150150
void read(const exprt &expr)
151151
{
152-
read_write_rec(expr, true, false, "", guardt());
152+
read_write_rec(expr, true, false, "", guardt(true_exprt()));
153153
}
154154

155155
void read(const exprt &expr, const guardt &guard)
@@ -159,7 +159,7 @@ class _rw_set_loct:public rw_set_baset
159159

160160
void write(const exprt &expr)
161161
{
162-
read_write_rec(expr, false, true, "", guardt());
162+
read_write_rec(expr, false, true, "", guardt(true_exprt()));
163163
}
164164

165165
void compute();

src/goto-symex/goto_symex_state.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,12 @@ bool goto_symex_statet::l2_thread_read_encoding(
384384
ssa_exprt ssa_l1=expr;
385385
ssa_l1.remove_level_2();
386386
const irep_idt &l1_identifier=ssa_l1.get_identifier();
387+
const exprt guard_as_expr = guard.as_expr();
387388

388389
// see whether we are within an atomic section
389390
if(atomic_section_id!=0)
390391
{
391-
guardt write_guard;
392-
write_guard.add(false_exprt());
392+
guardt write_guard{false_exprt{}};
393393

394394
const auto a_s_writes = written_in_atomic_section.find(ssa_l1);
395395
if(a_s_writes!=written_in_atomic_section.end())
@@ -413,8 +413,7 @@ bool goto_symex_statet::l2_thread_read_encoding(
413413
// we cannot determine for sure that there has been a write already
414414
// so generate a read even if l1_identifier has been written on
415415
// all branches flowing into this read
416-
guardt read_guard;
417-
read_guard.add(false_exprt());
416+
guardt read_guard{false_exprt{}};
418417

419418
a_s_r_entryt &a_s_read=read_in_atomic_section[ssa_l1];
420419
for(const auto &a_s_read_guard : a_s_read.second)
@@ -430,11 +429,11 @@ bool goto_symex_statet::l2_thread_read_encoding(
430429
read_guard |= a_s_read_guard;
431430
}
432431

433-
exprt cond=read_guard.as_expr();
432+
guardt cond = read_guard;
434433
if(!no_write.op().is_false())
435-
cond=or_exprt(no_write.op(), cond);
434+
cond |= guardt{no_write.op()};
436435

437-
if_exprt tmp(cond, ssa_l1, ssa_l1);
436+
if_exprt tmp(cond.as_expr(), ssa_l1, ssa_l1);
438437
set_l2_indices(to_ssa_expr(tmp.true_case()), ns);
439438

440439
if(a_s_read.second.empty())
@@ -460,7 +459,7 @@ bool goto_symex_statet::l2_thread_read_encoding(
460459
record_events=record_events_bak;
461460

462461
symex_target->assignment(
463-
guard.as_expr(),
462+
guard_as_expr,
464463
ssa_l1,
465464
ssa_l1,
466465
ssa_l1.get_original_expr(),
@@ -498,11 +497,7 @@ bool goto_symex_statet::l2_thread_read_encoding(
498497
// and record that
499498
INVARIANT_STRUCTURED(
500499
symex_target!=nullptr, nullptr_exceptiont, "symex_target is null");
501-
symex_target->shared_read(
502-
guard.as_expr(),
503-
expr,
504-
atomic_section_id,
505-
source);
500+
symex_target->shared_read(guard_as_expr, expr, atomic_section_id, source);
506501

507502
return true;
508503
}

src/goto-symex/goto_symex_state.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class goto_symex_statet final
5454
/// distance from entry
5555
unsigned depth;
5656

57-
guardt guard;
57+
guardt guard{true_exprt{}};
5858
symex_targett::sourcet source;
5959
symex_target_equationt *symex_target;
6060

@@ -254,7 +254,7 @@ class goto_symex_statet final
254254
struct threadt
255255
{
256256
goto_programt::const_targett pc;
257-
guardt guard;
257+
guardt guard{true_exprt{}};
258258
call_stackt call_stack;
259259
std::map<irep_idt, unsigned> function_frame;
260260
unsigned atomic_section_id = 0;

src/goto-symex/slice_by_trace.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,12 @@ void symex_slice_by_tracet::slice_by_trace(
8585

8686
slice_SSA_steps(equation, implications); // Slice based on implications
8787

88-
guardt t_guard;
8988
symex_targett::sourcet empty_source;
9089
equation.SSA_steps.emplace_front(
9190
empty_source, goto_trace_stept::typet::ASSUME);
9291
symex_target_equationt::SSA_stept &SSA_step=equation.SSA_steps.front();
9392

94-
SSA_step.guard=t_guard.as_expr();
93+
SSA_step.guard = true_exprt();
9594
SSA_step.ssa_lhs.make_nil();
9695
SSA_step.cond_expr.swap(trace_condition);
9796

@@ -485,7 +484,6 @@ void symex_slice_by_tracet::assign_merges(
485484
ssa_exprt merge_sym(merge_symbol);
486485
merge_sym.set_level_2(merge_count);
487486
merge_count--;
488-
guardt t_guard;
489487
symex_targett::sourcet empty_source;
490488

491489
exprt merge_copy(*i);
@@ -494,7 +492,7 @@ void symex_slice_by_tracet::assign_merges(
494492
empty_source, goto_trace_stept::typet::ASSIGNMENT);
495493
symex_target_equationt::SSA_stept &SSA_step=equation.SSA_steps.front();
496494

497-
SSA_step.guard=t_guard.as_expr();
495+
SSA_step.guard = true_exprt();
498496
SSA_step.ssa_lhs=merge_sym;
499497
SSA_step.ssa_rhs.swap(merge_copy);
500498
SSA_step.assignment_type=symex_targett::assignment_typet::HIDDEN;

src/goto-symex/symex_assign.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void goto_symext::symex_assign(
8989
if(state.source.pc->source_location.get_hide())
9090
assignment_type=symex_targett::assignment_typet::HIDDEN;
9191

92-
guardt guard; // NOT the state guard!
92+
guardt guard{true_exprt{}}; // NOT the state guard!
9393
symex_assign_rec(state, lhs, nil_exprt(), rhs, guard, assignment_type);
9494
}
9595
}
@@ -431,15 +431,15 @@ void goto_symext::symex_assign_if(
431431
guard.add(renamed_guard);
432432
symex_assign_rec(
433433
state, lhs.true_case(), full_lhs, rhs, guard, assignment_type);
434-
guard.swap(old_guard);
434+
guard = std::move(old_guard);
435435
}
436436

437437
if(!renamed_guard.is_true())
438438
{
439439
guard.add(not_exprt(renamed_guard));
440440
symex_assign_rec(
441441
state, lhs.false_case(), full_lhs, rhs, guard, assignment_type);
442-
guard.swap(old_guard);
442+
guard = std::move(old_guard);
443443
}
444444
}
445445

src/goto-symex/symex_dereference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ void goto_symext::dereference(
384384
state.rename(expr, ns, goto_symex_statet::L1);
385385

386386
// start the recursion!
387-
guardt guard;
387+
guardt guard{true_exprt{}};
388388
dereference_rec(expr, state, guard, write);
389389
// dereferencing may introduce new symbol_exprt
390390
// (like __CPROVER_memory)

src/goto-symex/symex_function_call.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void goto_symext::parameter_assignments(
139139
clean_expr(lhs, state, true);
140140
clean_expr(rhs, state, false);
141141

142-
guardt guard;
142+
guardt guard{true_exprt{}};
143143
symex_assign_rec(state, lhs, nil_exprt(), rhs, guard, assignment_type);
144144
}
145145

src/goto-symex/symex_goto.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ void goto_symext::symex_goto(statet &state)
225225
// adjust guards
226226
if(new_guard.is_true())
227227
{
228-
state.guard = false_exprt();
228+
state.guard = guardt(false_exprt());
229229
}
230230
else
231231
{
@@ -249,7 +249,7 @@ void goto_symext::symex_goto(statet &state)
249249
state.rename(new_lhs, ns, goto_symex_statet::L1);
250250
state.assignment(new_lhs, new_rhs, ns, true, false);
251251

252-
guardt guard;
252+
guardt guard{true_exprt{}};
253253

254254
log.conditional_output(
255255
log.debug(),

src/goto-symex/symex_other.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void goto_symext::symex_other(
275275
dereference_exprt object(code.op0(), empty_typet());
276276
clean_expr(object, state, true);
277277

278-
havoc_rec(state, guardt(), object);
278+
havoc_rec(state, guardt(true_exprt()), object);
279279
}
280280
else
281281
UNREACHABLE;

src/goto-symex/symex_start_thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void goto_symext::symex_start_thread(statet &state)
8181
// make copy
8282
ssa_exprt rhs=c_it->second.first;
8383

84-
guardt guard;
84+
guardt guard{true_exprt{}};
8585
const bool record_events=state.record_events;
8686
state.record_events=false;
8787
symex_assign_symbol(
@@ -120,7 +120,7 @@ void goto_symext::symex_start_thread(statet &state)
120120
rhs = *zero;
121121
}
122122

123-
guardt guard;
123+
guardt guard{true_exprt{}};
124124
symex_assign_symbol(
125125
state,
126126
lhs,

src/pointer-analysis/goto_program_dereference.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,7 @@ void goto_program_dereferencet::dereference_rec(
132132
guard.add(op);
133133
}
134134

135-
guard.swap(old_guard);
136-
135+
guard = std::move(old_guard);
137136
return;
138137
}
139138
else if(expr.id()==ID_if)
@@ -159,15 +158,15 @@ void goto_program_dereferencet::dereference_rec(
159158
guardt old_guard=guard;
160159
guard.add(expr.op0());
161160
dereference_rec(expr.op1(), guard, mode);
162-
guard.swap(old_guard);
161+
guard = std::move(old_guard);
163162
}
164163

165164
if(o2)
166165
{
167166
guardt old_guard=guard;
168167
guard.add(boolean_negate(expr.op0()));
169168
dereference_rec(expr.op2(), guard, mode);
170-
guard.swap(old_guard);
169+
guard = std::move(old_guard);
171170
}
172171

173172
return;
@@ -252,7 +251,7 @@ void goto_program_dereferencet::dereference_expr(
252251
const bool checks_only,
253252
const value_set_dereferencet::modet mode)
254253
{
255-
guardt guard;
254+
guardt guard{true_exprt{}};
256255

257256
if(checks_only)
258257
{

0 commit comments

Comments
 (0)