Skip to content

Commit 72303a7

Browse files
authored
Merge pull request #7049 from diffblue/fix_bool_preincrement
Fix _Bool preincrement
2 parents 5fcf8c9 + 4d215fa commit 72303a7

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

regression/cbmc/Bool/bool6.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
CORE
22
bool6.c
33

44
^EXIT=0$

src/goto-programs/goto_convert_side_effect.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)