@@ -223,24 +223,40 @@ void goto_convertt::remove_pre(
223
223
op, statement == ID_preincrement ? ID_plus : ID_minus, std::move (constant)};
224
224
rhs.add_source_location () = expr.source_location ();
225
225
226
+ // Is there a typecast, e.g., for _Bool? If so, transform
227
+ // t1(op : t2) := op+1 --> op := t2(op+1)
228
+ exprt lhs;
229
+ if (op.id () == ID_typecast)
230
+ {
231
+ lhs = to_typecast_expr (op).op ();
232
+ rhs = typecast_exprt (rhs, lhs.type ());
233
+ }
234
+ else
235
+ {
236
+ lhs = op;
237
+ }
238
+
226
239
const bool cannot_use_lhs =
227
- result_is_used && !address_taken && needs_cleaning (op );
240
+ result_is_used && !address_taken && needs_cleaning (lhs );
228
241
if (cannot_use_lhs)
229
242
make_temp_symbol (rhs, " pre" , dest, mode);
230
243
231
- code_assignt assignment (op , rhs);
244
+ code_assignt assignment (lhs , rhs);
232
245
assignment.add_source_location ()=expr.find_source_location ();
233
246
234
247
convert (assignment, dest, mode);
235
248
236
249
if (result_is_used)
237
250
{
238
251
if (cannot_use_lhs)
239
- expr.swap (rhs);
252
+ {
253
+ auto tmp = typecast_exprt::conditional_cast (rhs, expr.type ());
254
+ expr.swap (tmp);
255
+ }
240
256
else
241
257
{
242
258
// revert to argument of pre-inc/pre-dec
243
- exprt tmp = op ;
259
+ auto tmp = typecast_exprt::conditional_cast (lhs, expr. type ()) ;
244
260
expr.swap (tmp);
245
261
}
246
262
}
0 commit comments