@@ -1613,17 +1613,34 @@ void goto_convertt::convert_ifthenelse(
16131613 // convert 'then'-branch
16141614 goto_programt tmp_then;
16151615 convert (code.then_case (), tmp_then, mode);
1616+ source_locationt then_end_location =
1617+ code.then_case ().get_statement () == ID_block
1618+ ? to_code_block (code.then_case ()).end_location ()
1619+ : code.then_case ().source_location ();
16161620
16171621 goto_programt tmp_else;
1622+ source_locationt else_end_location;
16181623
16191624 if (has_else)
1625+ {
16201626 convert (code.else_case (), tmp_else, mode);
1627+ else_end_location = code.else_case ().get_statement () == ID_block
1628+ ? to_code_block (code.else_case ()).end_location ()
1629+ : code.else_case ().source_location ();
1630+ }
16211631
16221632 exprt tmp_guard=code.cond ();
16231633 clean_expr (tmp_guard, dest, mode);
16241634
16251635 generate_ifthenelse (
1626- tmp_guard, tmp_then, tmp_else, source_location, dest, mode);
1636+ tmp_guard,
1637+ source_location,
1638+ tmp_then,
1639+ then_end_location,
1640+ tmp_else,
1641+ else_end_location,
1642+ dest,
1643+ mode);
16271644}
16281645
16291646void goto_convertt::collect_operands (
@@ -1655,9 +1672,11 @@ static inline bool is_size_one(const goto_programt &g)
16551672// / if(guard) true_case; else false_case;
16561673void goto_convertt::generate_ifthenelse (
16571674 const exprt &guard,
1675+ const source_locationt &source_location,
16581676 goto_programt &true_case,
1677+ const source_locationt &then_end_location,
16591678 goto_programt &false_case,
1660- const source_locationt &source_location ,
1679+ const source_locationt &else_end_location ,
16611680 goto_programt &dest,
16621681 const irep_idt &mode)
16631682{
@@ -1727,13 +1746,17 @@ void goto_convertt::generate_ifthenelse(
17271746
17281747 // Flip around if no 'true' case code.
17291748 if (is_empty (true_case))
1749+ {
17301750 return generate_ifthenelse (
17311751 boolean_negate (guard),
1752+ source_location,
17321753 false_case,
1754+ else_end_location,
17331755 true_case,
1734- source_location ,
1756+ then_end_location ,
17351757 dest,
17361758 mode);
1759+ }
17371760
17381761 bool has_else=!is_empty (false_case);
17391762
@@ -1753,14 +1776,13 @@ void goto_convertt::generate_ifthenelse(
17531776
17541777 // do the x label
17551778 goto_programt tmp_x;
1756- goto_programt::targett x = tmp_x.add (goto_programt::make_incomplete_goto (
1757- true_exprt (), true_case. instructions . back (). source_location () ));
1779+ goto_programt::targett x = tmp_x.add (
1780+ goto_programt::make_incomplete_goto ( true_exprt (), then_end_location ));
17581781
17591782 // do the z label
17601783 goto_programt tmp_z;
1761- goto_programt::targett z = tmp_z.add (goto_programt::make_skip ());
1762- // We deliberately don't set a location for 'z', it's a dummy
1763- // target.
1784+ goto_programt::targett z = tmp_z.add (
1785+ goto_programt::make_skip (has_else ? else_end_location : then_end_location));
17641786
17651787 // y: Q;
17661788 goto_programt tmp_y;
0 commit comments