Skip to content

Commit 198fd86

Browse files
authored
Merge pull request #6522 from tautschnig/remove-return-preserve-labels
Preserve labels when removing return statements
2 parents 98afb5e + 079d367 commit 198fd86

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

regression/goto-analyzer/label/main.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int main()
2+
{
3+
goto ERROR;
4+
5+
return 0;
6+
ERROR:
7+
return 1;
8+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
main.c
3+
--show-goto-functions --error-label ERROR
4+
Labels: ERROR$
5+
ASSIGN main#return_value := 1$
6+
^EXIT=0$
7+
^SIGNAL=0$
8+
--
9+
^warning: ignoring
10+
--
11+
This test ensures that removal of return values (confirmed by the existence of
12+
the ASSIGN instruction) preserves labels attached to the return statement.

src/goto-programs/remove_returns.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,10 @@ void remove_returnst::replace_returns(
128128
code_assignt assignment(*return_symbol, instruction.return_value());
129129

130130
// now turn the `return' into `assignment'
131+
auto labels = std::move(instruction.labels);
131132
instruction = goto_programt::make_assignment(
132133
assignment, instruction.source_location());
134+
instruction.labels = std::move(labels);
133135
}
134136
else
135137
instruction.turn_into_skip();

0 commit comments

Comments
 (0)