@@ -9,7 +9,75 @@ Date: September 2009
9
9
\*******************************************************************/
10
10
11
11
// / \file
12
- // / Remove function returns
12
+ // / Replace function returns by assignments to global variables
13
+
14
+ // / The functions `remove_returns()` remove return instructions from a goto
15
+ // / program. The `restore_returns()` functions restore the returns in a goto
16
+ // / program in which they have been removed previously.
17
+ // /
18
+ // / In a goto program in which returns have not been removed, functions return
19
+ // / values via the `return` instruction, which is followed by a `GOTO` to the
20
+ // / end of the function. Unlike in C, in a goto program the `return` instruction
21
+ // / does not cause control-flow to return to the call site. Instead, it simply
22
+ // / sets the return value that will be returned once the function returns to the
23
+ // / call site when the `END_FUNCTION` instruction is encountered.
24
+ // /
25
+ // / Consider the following C code (with ... indicating further code):
26
+ // /
27
+ // / ```
28
+ // / int func()
29
+ // / {
30
+ // / ...
31
+ // / return 1;
32
+ // / ...
33
+ // / }
34
+ // /
35
+ // / r = func();
36
+ // /
37
+ // / ```
38
+ // /
39
+ // / This code would appear in a goto program as follows:
40
+ // /
41
+ // / ```
42
+ // / func
43
+ // / ...
44
+ // / return 1;
45
+ // / GOTO 1
46
+ // / ...
47
+ // / 1: END_FUNCTION
48
+ // /
49
+ // / r = func();
50
+ // / ```
51
+ // /
52
+ // / The return removal pass introduces a thread-local global variable
53
+ // / `func#return_value` (one for each non-void function) to which the return
54
+ // / value is assigned, and this variable is then assigned to the lhs expression
55
+ // / that takes the function return value:
56
+ // /
57
+ // / ```
58
+ // / func
59
+ // / ...
60
+ // / func#return_value = 1;
61
+ // / GOTO 1
62
+ // / ...
63
+ // / 1: END_FUNCTION
64
+ // /
65
+ // / func();
66
+ // / r = func#return_value;
67
+ // /
68
+ // / ```
69
+ // /
70
+ // / As `return` instructions are removed, the return types of the function types
71
+ // / are set to void as well (represented by the type `empty_typet`). This
72
+ // / applies both to the functions (i.e., the member `type` of `goto_functiont`)
73
+ // / and to the call sites (i.e., the type
74
+ // / `to_code_function_call(code).function().type()` with `code` being the code
75
+ // / member of the `instructiont` instance that represents the function call).
76
+ // /
77
+ // / The types of function pointer expressions in the goto program are however
78
+ // / not changed. For example, in an assignment where `func` is assigned to a
79
+ // / function pointer, such as `int (*f)(void) = func`, the function types
80
+ // / appearing in the lhs and rhs both retain the integer return type.
13
81
14
82
#ifndef CPROVER_GOTO_PROGRAMS_REMOVE_RETURNS_H
15
83
#define CPROVER_GOTO_PROGRAMS_REMOVE_RETURNS_H
@@ -25,10 +93,6 @@ class goto_model_functiont;
25
93
class goto_modelt ;
26
94
class symbol_table_baset ;
27
95
28
- // Turns 'return x' into an assignment to fkt#return_value,
29
- // unless the function returns void,
30
- // and a 'goto the_end_of_the_function'.
31
-
32
96
void remove_returns (symbol_table_baset &, goto_functionst &);
33
97
34
98
typedef std::function<bool (const irep_idt &)> function_is_stubt;
0 commit comments