Skip to content

Commit d44bfd3

Browse files
committed
Also simplify assert structure found on alpine linux
1 parent c5cde18 commit d44bfd3

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

src/goto-programs/goto_clean_expr.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,19 @@ void goto_convertt::clean_expr(
260260
// preserve the expressions for possible later checks
261261
if(if_expr.true_case().is_not_nil())
262262
{
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()));
264267
convert(code_expression, tmp_true);
265268
}
266269

267270
if(if_expr.false_case().is_not_nil())
268271
{
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()));
270276
convert(code_expression, tmp_false);
271277
}
272278

src/goto-programs/goto_convert.cpp

+18-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ Author: Daniel Kroening, [email protected]
3131
static bool is_empty(const goto_programt &goto_program)
3232
{
3333
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))
3735
return false;
3836

3937
return true;
@@ -1749,6 +1747,23 @@ void goto_convertt::generate_ifthenelse(
17491747
return;
17501748
}
17511749

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+
17521767
// Flip around if no 'true' case code.
17531768
if(is_empty(true_case))
17541769
return generate_ifthenelse(

0 commit comments

Comments
 (0)