@@ -26,13 +26,12 @@ Author: Daniel Kroening, kroening@kroening.com
2626
2727#include " goto_convert_class.h"
2828#include " destructor.h"
29+ #include " remove_skip.h"
2930
3031static bool is_empty (const goto_programt &goto_program)
3132{
3233 forall_goto_program_instructions (it, goto_program)
33- if (!it->is_skip () ||
34- !it->labels .empty () ||
35- !it->code .is_nil ())
34+ if (!is_skip (goto_program, it))
3635 return false ;
3736
3837 return true ;
@@ -1723,6 +1722,11 @@ void goto_convertt::generate_ifthenelse(
17231722 true_case.instructions .back ().guard =boolean_negate (guard);
17241723 dest.destructive_append (true_case);
17251724 true_case.instructions .clear ();
1725+ if (
1726+ is_empty (false_case) ||
1727+ (is_size_one (false_case) &&
1728+ is_skip (false_case, false_case.instructions .begin ())))
1729+ return ;
17261730 }
17271731
17281732 // similarly, do guarded assertions directly
@@ -1736,6 +1740,28 @@ void goto_convertt::generate_ifthenelse(
17361740 false_case.instructions .back ().guard =guard;
17371741 dest.destructive_append (false_case);
17381742 false_case.instructions .clear ();
1743+ if (
1744+ is_empty (true_case) ||
1745+ (is_size_one (true_case) &&
1746+ is_skip (true_case, true_case.instructions .begin ())))
1747+ return ;
1748+ }
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 ;
17391765 }
17401766
17411767 // Flip around if no 'true' case code.
0 commit comments