@@ -223,24 +223,40 @@ void goto_convertt::remove_pre(
223223 op, statement == ID_preincrement ? ID_plus : ID_minus, std::move (constant)};
224224 rhs.add_source_location () = expr.source_location ();
225225
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+
226239 const bool cannot_use_lhs =
227- result_is_used && !address_taken && needs_cleaning (op );
240+ result_is_used && !address_taken && needs_cleaning (lhs );
228241 if (cannot_use_lhs)
229242 make_temp_symbol (rhs, " pre" , dest, mode);
230243
231- code_assignt assignment (op , rhs);
244+ code_assignt assignment (lhs , rhs);
232245 assignment.add_source_location ()=expr.find_source_location ();
233246
234247 convert (assignment, dest, mode);
235248
236249 if (result_is_used)
237250 {
238251 if (cannot_use_lhs)
239- expr.swap (rhs);
252+ {
253+ auto tmp = typecast_exprt::conditional_cast (rhs, expr.type ());
254+ expr.swap (tmp);
255+ }
240256 else
241257 {
242258 // revert to argument of pre-inc/pre-dec
243- exprt tmp = op ;
259+ auto tmp = typecast_exprt::conditional_cast (lhs, expr. type ()) ;
244260 expr.swap (tmp);
245261 }
246262 }
0 commit comments