Skip to content

Commit 112bd5b

Browse files
committed
Add changes suggested during code review.
1 parent 526945e commit 112bd5b

15 files changed

+78
-47
lines changed

src/goto-symex/build_goto_trace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void build_goto_trace(
222222
else if(it->is_atomic_end() && current_time<0)
223223
current_time*=-1;
224224

225-
PRECONDITION(current_time>=0);
225+
INVARIANT(current_time>=0, "time keeping inconsistency");
226226
// move any steps gathered in an atomic section
227227

228228
if(time_before<0)

src/goto-symex/goto_symex_state.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,10 @@ void goto_symex_statet::rename(
493493
}
494494
else if(expr.id()==ID_address_of)
495495
{
496-
PRECONDITION(expr.operands().size() == 1);
497-
rename_address(expr.op0(), ns, level);
498496
PRECONDITION(expr.type().id() == ID_pointer);
497+
DATA_INVARIANT(
498+
expr.operands().size() == 1, "address_of should have a single operand");
499+
rename_address(expr.op0(), ns, level);
499500
expr.type().subtype()=expr.op0().type();
500501
}
501502
else

src/goto-symex/postcondition.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,22 @@ bool postconditiont::is_used_address_of(
7676
}
7777
else if(expr.id()==ID_index)
7878
{
79-
PRECONDITION(expr.operands().size() == 2);
79+
DATA_INVARIANT(
80+
expr.operands().size() == 2, "index expression should have two operands");
8081
return
8182
is_used_address_of(expr.op0(), identifier) ||
8283
is_used(expr.op1(), identifier);
8384
}
8485
else if(expr.id()==ID_member)
8586
{
86-
PRECONDITION(expr.operands().size() == 1);
87+
DATA_INVARIANT(
88+
expr.operands().size() == 1, "member expression should only have one operand");
8789
return is_used_address_of(expr.op0(), identifier);
8890
}
8991
else if(expr.id()==ID_dereference)
9092
{
91-
PRECONDITION(expr.operands().size() == 1);
93+
DATA_INVARIANT(
94+
expr.operands().size() == 1, "dereference expression should only have one operand");
9295
return is_used(expr.op0(), identifier);
9396
}
9497

@@ -154,7 +157,9 @@ bool postconditiont::is_used(
154157
if(expr.id()==ID_address_of)
155158
{
156159
// only do index!
157-
PRECONDITION(expr.operands().size() == 1);
160+
DATA_INVARIANT(
161+
expr.operands().size() == 1,
162+
"address_of expression expected to have one operand at this point");
158163
return is_used_address_of(expr.op0(), identifier);
159164
}
160165
else if(expr.id()==ID_symbol &&
@@ -168,7 +173,9 @@ bool postconditiont::is_used(
168173
}
169174
else if(expr.id()==ID_dereference)
170175
{
171-
PRECONDITION(expr.operands().size() == 1);
176+
DATA_INVARIANT(
177+
expr.operands().size() == 1,
178+
"dereference expression expected to have one operand");
172179

173180
// aliasing may happen here
174181

src/goto-symex/precondition.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,21 @@ void preconditiont::compute_address_of(exprt &dest)
7878
}
7979
else if(dest.id()==ID_index)
8080
{
81-
PRECONDITION(dest.operands().size() == 2);
81+
DATA_INVARIANT(
82+
dest.operands().size() == 2, "index expression expected to have two operands");
8283
compute_address_of(dest.op0());
8384
compute(dest.op1());
8485
}
8586
else if(dest.id()==ID_member)
8687
{
87-
PRECONDITION(dest.operands().size() == 1);
88+
DATA_INVARIANT(
89+
dest.operands().size() == 1, "member expression expected to have one operand");
8890
compute_address_of(dest.op0());
8991
}
9092
else if(dest.id()==ID_dereference)
9193
{
92-
PRECONDITION(dest.operands().size() == 1);
94+
DATA_INVARIANT(
95+
dest.operands().size() == 1, "dereference expression expected to have 1 operand");
9396
compute(dest.op0());
9497
}
9598
}
@@ -104,12 +107,16 @@ void preconditiont::compute_rec(exprt &dest)
104107
if(dest.id()==ID_address_of)
105108
{
106109
// only do index!
107-
PRECONDITION(dest.operands().size() == 1);
110+
DATA_INVARIANT(
111+
dest.operands().size() == 1,
112+
"address_of expression expected to have one operand at this point");
108113
compute_address_of(dest.op0());
109114
}
110115
else if(dest.id()==ID_dereference)
111116
{
112-
PRECONDITION(dest.operands().size() == 1);
117+
DATA_INVARIANT(
118+
dest.operands().size() == 1,
119+
"dereference expression expected to have one operand at this point");
113120

114121
const irep_idt &lhs_identifier=SSA_step.ssa_lhs.get_object_name();
115122

src/goto-symex/slice_by_trace.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,6 @@ void symex_slice_by_tracet::slice_by_trace(
9999
simplify(copy_last, ns);
100100
implications.insert(copy_last);
101101
}
102-
else if(!(g_copy.id()==ID_constant))
103-
{
104-
UNHANDLED_CASE;
105-
}
106102
}
107103

108104
slice_SSA_steps(equation, implications); // Slice based on implications

src/goto-symex/symex_assign.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ void goto_symext::symex_assign(
5555
symex_allocate(state, lhs, side_effect_expr);
5656
else if(statement==ID_printf)
5757
{
58-
if(lhs.is_not_nil())
59-
throw "printf: unexpected assignment";
58+
PRECONDITION(!lhs.is_not_nil());
59+
// if(lhs.is_not_nil())
60+
// throw "printf: unexpected assignment";
6061
symex_printf(state, side_effect_expr);
6162
}
6263
else if(statement==ID_gcc_builtin_va_arg_next)
@@ -106,12 +107,15 @@ exprt goto_symext::add_to_lhs(
106107

107108
while(p->is_not_nil())
108109
{
109-
PRECONDITION(p->id()!=ID_symbol);
110-
PRECONDITION(p->operands().size()>=1);
110+
INVARIANT(
111+
p->id() != ID_symbol, "expected pointed-to expression to be a symbol");
112+
INVARIANT(
113+
p->operands().size() >= 1,
114+
"expected pointed-to expression to have at least one operand");
111115
p=&p->op0();
112116
}
113117

114-
PRECONDITION(p->is_nil());
118+
INVARIANT(p->is_nil(), "expected pointed-to expression to be nil at this point");
115119

116120
*p=tmp_what;
117121
return new_lhs;
@@ -366,7 +370,9 @@ void goto_symext::symex_assign_struct_member(
366370
// typecasts involved? C++ does that for inheritance.
367371
if(lhs_struct.id()==ID_typecast)
368372
{
369-
PRECONDITION(lhs_struct.operands().size() == 1);
373+
DATA_INVARIANT(
374+
lhs_struct.operands().size() == 1,
375+
"typecast expression expected to have one operand");
370376

371377
if(lhs_struct.op0().id() == ID_null_object)
372378
{
@@ -445,7 +451,7 @@ void goto_symext::symex_assign_if(
445451
guard.swap(old_guard);
446452
}
447453

448-
if(!renamed_guard.is_true())
454+
if(!renamed_guard.is_true())
449455
{
450456
guard.add(not_exprt(renamed_guard));
451457
symex_assign_rec(

src/goto-symex/symex_atomic_section.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ void goto_symext::symex_atomic_begin(statet &state)
1616
if(state.guard.is_false())
1717
return;
1818

19-
// we don't allow any nesting of atomic sections
20-
INVARIANT(state.atomic_section_id == 0,
21-
"nested atomic section detected at " +
22-
state.source.pc->source_location.as_string());
19+
INVARIANT(
20+
state.atomic_section_id == 0,
21+
"we don't support nesting of atomic sections");
2322

2423
state.atomic_section_id=++atomic_section_counter;
2524
state.read_in_atomic_section.clear();

src/goto-symex/symex_builtin_functions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ void goto_symext::symex_allocate(
174174
ns,
175175
null_message);
176176

177-
PRECONDITION(zero_value.is_not_nil())
177+
CHECK_RETURN(zero_value.is_not_nil());
178178
code_assignt assignment(value_symbol.symbol_expr(), zero_value);
179179
symex_assign(state, assignment);
180180
}
@@ -229,7 +229,7 @@ void goto_symext::symex_gcc_builtin_va_arg_next(
229229
const exprt &lhs,
230230
const side_effect_exprt &code)
231231
{
232-
PRECONDITION(code.operands().size() != 1);
232+
PRECONDITION(code.operands().size() == 1);
233233

234234
if(lhs.is_nil())
235235
return; // ignore
@@ -518,7 +518,7 @@ void goto_symext::symex_macro(
518518
{
519519
const irep_idt &identifier=code.op0().get(ID_identifier);
520520

521-
PRECONDITION(identifier == CPROVER_MACRO_PREFIX "waitfor")
521+
PRECONDITION(identifier == CPROVER_MACRO_PREFIX "waitfor");
522522
#if 0
523523
exprt new_fc("waitfor", fc.type());
524524

src/goto-symex/symex_dead.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ void goto_symext::symex_dead(statet &state)
2323

2424
const codet &code=to_code(instruction.code);
2525

26-
PRECONDITION(code.operands().size()!=1);
27-
PRECONDITION(code.op0().id()!=ID_symbol);
26+
PRECONDITION(code.operands().size()==1);
27+
PRECONDITION(code.op0().id()==ID_symbol);
2828

2929
// We increase the L2 renaming to make these non-deterministic.
3030
// We also prevent propagation of old values.

src/goto-symex/symex_decl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ void goto_symext::symex_decl(statet &state)
2626
const codet &code=to_code(instruction.code);
2727

2828
// two-operand decl not supported here
29-
PRECONDITION(code.operands().size()!=2);
3029
// we handle the decl with only one operand
3130
PRECONDITION(code.operands().size()==1);
3231
PRECONDITION(code.op0().id()!=ID_symbol);

0 commit comments

Comments
 (0)