File tree 2 files changed +20
-8
lines changed
regression/cbmc/Pointer_Arithmetic15
2 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -15,5 +15,9 @@ int main()
15
15
16
16
a = p - q ;
17
17
18
+ // mixing types: the C front-end will insert casts
19
+ unsigned long long u ;
20
+ p = (p + a ) + u ;
21
+
18
22
assert (0 );
19
23
}
Original file line number Diff line number Diff line change @@ -439,16 +439,24 @@ simplify_exprt::resultt<> simplify_exprt::simplify_plus(const plus_exprt &expr)
439
439
expr.op0 ().id () == ID_plus && expr.op0 ().type ().id () == ID_pointer &&
440
440
expr.op0 ().operands ().size () == 2 )
441
441
{
442
- plus_exprt op0 = to_plus_expr (expr.op0 ());
442
+ plus_exprt result = to_plus_expr (expr.op0 ());
443
+ if (as_const (result).op0 ().type ().id () != ID_pointer)
444
+ result.op0 ().swap (result.op1 ());
445
+ const exprt &op1 = as_const (result).op1 ();
443
446
444
- if (op0.op1 ().id () == ID_plus)
445
- to_plus_expr (op0.op1 ()).add_to_operands (expr.op1 ());
447
+ if (op1.id () == ID_plus)
448
+ {
449
+ plus_exprt new_op1 = to_plus_expr (op1);
450
+ new_op1.add_to_operands (
451
+ typecast_exprt::conditional_cast (expr.op1 (), new_op1.op0 ().type ()));
452
+ result.op1 () = simplify_plus (new_op1);
453
+ }
446
454
else
447
- op0. op1 ()= plus_exprt (op0. op1 (), expr. op1 ());
448
-
449
- auto result = op0 ;
450
-
451
- result. op1 () = simplify_plus ( to_plus_expr (result. op1 ()));
455
+ {
456
+ plus_exprt new_op1{
457
+ op1, typecast_exprt::conditional_cast (expr. op1 (), op1. type ())} ;
458
+ result. op1 () = simplify_plus (new_op1);
459
+ }
452
460
453
461
return changed (simplify_plus (result));
454
462
}
You can’t perform that action at this time.
0 commit comments