File tree 2 files changed +26
-5
lines changed
2 files changed +26
-5
lines changed Original file line number Diff line number Diff line change @@ -260,13 +260,19 @@ void goto_convertt::clean_expr(
260
260
// preserve the expressions for possible later checks
261
261
if (if_expr.true_case ().is_not_nil ())
262
262
{
263
- code_expressiont code_expression (if_expr.true_case ());
263
+ // add a (void) type cast so that is_skip catches it in case the
264
+ // expression is just a constant
265
+ code_expressiont code_expression (
266
+ typecast_exprt (if_expr.true_case (), empty_typet ()));
264
267
convert (code_expression, tmp_true);
265
268
}
266
269
267
270
if (if_expr.false_case ().is_not_nil ())
268
271
{
269
- code_expressiont code_expression (if_expr.false_case ());
272
+ // add a (void) type cast so that is_skip catches it in case the
273
+ // expression is just a constant
274
+ code_expressiont code_expression (
275
+ typecast_exprt (if_expr.false_case (), empty_typet ()));
270
276
convert (code_expression, tmp_false);
271
277
}
272
278
Original file line number Diff line number Diff line change 31
31
static bool is_empty (const goto_programt &goto_program)
32
32
{
33
33
forall_goto_program_instructions (it, goto_program)
34
- if (!it->is_skip () ||
35
- !it->labels .empty () ||
36
- !it->code .is_nil ())
34
+ if (!is_skip (goto_program, it))
37
35
return false ;
38
36
39
37
return true ;
@@ -1749,6 +1747,23 @@ void goto_convertt::generate_ifthenelse(
1749
1747
return ;
1750
1748
}
1751
1749
1750
+ // a special case for C libraries that use
1751
+ // (void)((cond) || (assert(0),0))
1752
+ if (
1753
+ is_empty (false_case) && true_case.instructions .size () == 2 &&
1754
+ true_case.instructions .front ().is_assert () &&
1755
+ true_case.instructions .front ().guard .is_false () &&
1756
+ true_case.instructions .front ().labels .empty () &&
1757
+ true_case.instructions .back ().labels .empty ())
1758
+ {
1759
+ true_case.instructions .front ().guard = boolean_negate (guard);
1760
+ true_case.instructions .erase (--true_case.instructions .end ());
1761
+ dest.destructive_append (true_case);
1762
+ true_case.instructions .clear ();
1763
+
1764
+ return ;
1765
+ }
1766
+
1752
1767
// Flip around if no 'true' case code.
1753
1768
if (is_empty (true_case))
1754
1769
return generate_ifthenelse (
You can’t perform that action at this time.
0 commit comments