Skip to content

Commit b20cf69

Browse files
author
Daniel Kroening
authored
Merge pull request #4963 from diffblue/analyses-opX
fix exprt::opX accesses in analyses
2 parents f3291f3 + 458c3c2 commit b20cf69

7 files changed

+46
-35
lines changed

src/analyses/custom_bitvector_analysis.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,10 @@ exprt custom_bitvector_domaint::eval(
704704
{
705705
if(src.operands().size()==2)
706706
{
707-
unsigned bit_nr=
708-
custom_bitvector_analysis.get_bit_nr(src.op1());
707+
unsigned bit_nr =
708+
custom_bitvector_analysis.get_bit_nr(to_binary_expr(src).op1());
709709

710-
exprt pointer=src.op0();
710+
exprt pointer = to_binary_expr(src).op0();
711711

712712
if(pointer.type().id()!=ID_pointer)
713713
return src;

src/analyses/goto_check.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ void goto_checkt::integer_overflow_check(
790790
exprt tmp;
791791

792792
if(i==1)
793-
tmp=expr.op0();
793+
tmp = to_multi_ary_expr(expr).op0();
794794
else
795795
{
796796
tmp=expr;
@@ -1732,7 +1732,8 @@ optionalt<exprt> goto_checkt::rw_ok_check(exprt expr)
17321732
DATA_INVARIANT(
17331733
expr.operands().size() == 2, "r/w_ok must have two operands");
17341734

1735-
const auto conditions = address_check(expr.op0(), expr.op1());
1735+
const auto conditions =
1736+
address_check(to_binary_expr(expr).op0(), to_binary_expr(expr).op1());
17361737

17371738
exprt::operandst conjuncts;
17381739

@@ -1964,7 +1965,7 @@ void goto_checkt::goto_check(
19641965
{
19651966
// must not throw NULL
19661967

1967-
exprt pointer=i.code.op0().op0();
1968+
exprt pointer = to_unary_expr(i.code.op0()).op();
19681969

19691970
const notequal_exprt not_eq_null(
19701971
pointer, null_pointer_exprt(to_pointer_type(pointer.type())));

src/analyses/local_bitvector_analysis.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,23 +176,26 @@ local_bitvector_analysist::flagst local_bitvector_analysist::get_rec(
176176
}
177177
else if(rhs.id()==ID_plus)
178178
{
179-
if(rhs.operands().size()>=3)
179+
const auto &plus_expr = to_plus_expr(rhs);
180+
181+
if(plus_expr.operands().size() >= 3)
180182
{
181-
assert(rhs.op0().type().id()==ID_pointer);
182-
return get_rec(rhs.op0(), loc_info_src) |
183-
flagst::mk_uses_offset();
183+
DATA_INVARIANT(
184+
plus_expr.op0().type().id() == ID_pointer,
185+
"pointer in pointer-typed sum must be op0");
186+
return get_rec(plus_expr.op0(), loc_info_src) | flagst::mk_uses_offset();
184187
}
185-
else if(rhs.operands().size()==2)
188+
else if(plus_expr.operands().size() == 2)
186189
{
187190
// one must be pointer, one an integer
188-
if(rhs.op0().type().id()==ID_pointer)
191+
if(plus_expr.op0().type().id() == ID_pointer)
189192
{
190-
return get_rec(rhs.op0(), loc_info_src) |
193+
return get_rec(plus_expr.op0(), loc_info_src) |
191194
flagst::mk_uses_offset();
192195
}
193-
else if(rhs.op1().type().id()==ID_pointer)
196+
else if(plus_expr.op1().type().id() == ID_pointer)
194197
{
195-
return get_rec(rhs.op1(), loc_info_src) |
198+
return get_rec(plus_expr.op1(), loc_info_src) |
196199
flagst::mk_uses_offset();
197200
}
198201
else
@@ -203,10 +206,11 @@ local_bitvector_analysist::flagst local_bitvector_analysist::get_rec(
203206
}
204207
else if(rhs.id()==ID_minus)
205208
{
206-
if(rhs.op0().type().id()==ID_pointer)
209+
const auto &op0 = to_minus_expr(rhs).op0();
210+
211+
if(op0.type().id() == ID_pointer)
207212
{
208-
return get_rec(rhs.op0(), loc_info_src) |
209-
flagst::mk_uses_offset();
213+
return get_rec(op0, loc_info_src) | flagst::mk_uses_offset();
210214
}
211215
else
212216
return flagst::mk_unknown();

src/analyses/local_may_alias.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,21 +250,25 @@ void local_may_aliast::get_rec(
250250
}
251251
else if(rhs.id()==ID_plus)
252252
{
253-
if(rhs.operands().size()>=3)
253+
const auto &plus_expr = to_plus_expr(rhs);
254+
255+
if(plus_expr.operands().size() >= 3)
254256
{
255-
assert(rhs.op0().type().id()==ID_pointer);
256-
get_rec(dest, rhs.op0(), loc_info_src);
257+
DATA_INVARIANT(
258+
plus_expr.op0().type().id() == ID_pointer,
259+
"pointer in pointer-typed sum must be op0");
260+
get_rec(dest, plus_expr.op0(), loc_info_src);
257261
}
258-
else if(rhs.operands().size()==2)
262+
else if(plus_expr.operands().size() == 2)
259263
{
260264
// one must be pointer, one an integer
261-
if(rhs.op0().type().id()==ID_pointer)
265+
if(plus_expr.op0().type().id() == ID_pointer)
262266
{
263-
get_rec(dest, rhs.op0(), loc_info_src);
267+
get_rec(dest, plus_expr.op0(), loc_info_src);
264268
}
265-
else if(rhs.op1().type().id()==ID_pointer)
269+
else if(plus_expr.op1().type().id() == ID_pointer)
266270
{
267-
get_rec(dest, rhs.op1(), loc_info_src);
271+
get_rec(dest, plus_expr.op1(), loc_info_src);
268272
}
269273
else
270274
dest.insert(unknown_object);
@@ -274,9 +278,11 @@ void local_may_aliast::get_rec(
274278
}
275279
else if(rhs.id()==ID_minus)
276280
{
277-
if(rhs.op0().type().id()==ID_pointer)
281+
const auto &op0 = to_minus_expr(rhs).op0();
282+
283+
if(op0.type().id() == ID_pointer)
278284
{
279-
get_rec(dest, rhs.op0(), loc_info_src);
285+
get_rec(dest, op0, loc_info_src);
280286
}
281287
else
282288
dest.insert(unknown_object);

src/analyses/local_safe_pointers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static optionalt<goto_null_checkt> get_null_checked_expr(const exprt &expr)
4343
// Reduce some roundabout ways of saying "x != null", e.g. "!(x == null)".
4444
while(normalized_expr.id() == ID_not)
4545
{
46-
normalized_expr = normalized_expr.op0();
46+
normalized_expr = to_not_expr(normalized_expr).op();
4747
checked_when_taken = !checked_when_taken;
4848
}
4949

@@ -55,8 +55,8 @@ static optionalt<goto_null_checkt> get_null_checked_expr(const exprt &expr)
5555

5656
if(normalized_expr.id() == ID_notequal)
5757
{
58-
const exprt &op0 = skip_typecast(normalized_expr.op0());
59-
const exprt &op1 = skip_typecast(normalized_expr.op1());
58+
const exprt &op0 = skip_typecast(to_notequal_expr(normalized_expr).op0());
59+
const exprt &op1 = skip_typecast(to_notequal_expr(normalized_expr).op1());
6060

6161
if(op0.type().id() == ID_pointer &&
6262
op0 == null_pointer_exprt(to_pointer_type(op0.type())))

src/analyses/static_analysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ void static_analysis_baset::do_function_call_rec(
370370
calling_function,
371371
l_call,
372372
l_return,
373-
function.op1(),
373+
to_if_expr(function).true_case(),
374374
arguments,
375375
new_state,
376376
goto_functions);
@@ -379,7 +379,7 @@ void static_analysis_baset::do_function_call_rec(
379379
calling_function,
380380
l_call,
381381
l_return,
382-
function.op2(),
382+
to_if_expr(function).false_case(),
383383
arguments,
384384
*n2,
385385
goto_functions);

src/analyses/uncaught_exceptions_analysis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ irep_idt uncaught_exceptions_domaint::get_exception_type(const typet &type)
2828
/// Returns the symbol corresponding to an exception
2929
exprt uncaught_exceptions_domaint::get_exception_symbol(const exprt &expr)
3030
{
31-
if(expr.id()!=ID_symbol && expr.has_operands())
32-
return get_exception_symbol(expr.op0());
31+
if(expr.id() != ID_symbol && expr.operands().size() >= 1)
32+
return get_exception_symbol(to_multi_ary_expr(expr).op0());
3333

3434
return expr;
3535
}

0 commit comments

Comments
 (0)