diff --git a/regression/goto-analyzer/label/main.c b/regression/goto-analyzer/label/main.c new file mode 100644 index 00000000000..626816c225d --- /dev/null +++ b/regression/goto-analyzer/label/main.c @@ -0,0 +1,8 @@ +int main() +{ + goto ERROR; + + return 0; +ERROR: + return 1; +} diff --git a/regression/goto-analyzer/label/test.desc b/regression/goto-analyzer/label/test.desc new file mode 100644 index 00000000000..986369495fb --- /dev/null +++ b/regression/goto-analyzer/label/test.desc @@ -0,0 +1,12 @@ +CORE +main.c +--show-goto-functions --error-label ERROR +Labels: ERROR$ +ASSIGN main#return_value := 1$ +^EXIT=0$ +^SIGNAL=0$ +-- +^warning: ignoring +-- +This test ensures that removal of return values (confirmed by the existence of +the ASSIGN instruction) preserves labels attached to the return statement. diff --git a/src/goto-programs/remove_returns.cpp b/src/goto-programs/remove_returns.cpp index 6daff643ad3..13a9e4fc065 100644 --- a/src/goto-programs/remove_returns.cpp +++ b/src/goto-programs/remove_returns.cpp @@ -128,8 +128,10 @@ void remove_returnst::replace_returns( code_assignt assignment(*return_symbol, instruction.return_value()); // now turn the `return' into `assignment' + auto labels = std::move(instruction.labels); instruction = goto_programt::make_assignment( assignment, instruction.source_location()); + instruction.labels = std::move(labels); } else instruction.turn_into_skip();