@@ -2014,27 +2014,27 @@ Flag | Check
2014
2014
` --uninitialized-check ` | add checks for uninitialized locals (experimental)
2015
2015
` --error-label label ` | check that given label is unreachable
2016
2016
2017
- #### Generating/Replacing function bodies
2017
+ #### Generating function bodies
2018
2018
2019
2019
Sometimes implementations for called functions are not available in the goto
2020
2020
program, or it is desirable to replace bodies of functions with certain
2021
2021
predetermined stubs (for example to confirm that these functions are never
2022
2022
called, or to indicate that these functions will never return). For this purpose
2023
- goto-instrument provides the ` --generate-function-body ` and
2024
- ` --replace-function-body ` options, that take a regular expression (in
2025
- [ ECMAScript syntax] ( http://en.cppreference.com/w/cpp/regex/ecmascript ) ) that
2026
- describes the names of the functions to generate or replace, the difference
2027
- being that ` --generate-function-body ` will only generate bodies of functions
2028
- that do not already have one, whereas ` --replace-function-body ` will do this and
2029
- in addition also replace existing bodies of functions with the stub.
2030
-
2031
- The shape of the stub itself can be chosen with the ` --replace-function-body-options `
2032
- parameter, which can take the following values:
2023
+ goto-instrument provides the ` --generate-function-body ` option, that takes a
2024
+ regular expression (in [ ECMAScript syntax]
2025
+ (http://en.cppreference.com/w/cpp/regex/ecmascript )) that describes the names of
2026
+ the functions to generate. Note that this will only generate bodies for
2027
+ functions that do not already have one; If one wishes to replace the body of a
2028
+ function with an existing definition, the ` --remove-function-body ` option can be
2029
+ used to remove the body of the function prior to generating a new one.
2030
+
2031
+ The shape of the stub itself can be chosen with the
2032
+ ` --generate-function-body-options ` parameter, which can take the following
2033
+ values:
2033
2034
2034
2035
Option | Result
2035
2036
-----------------------------|-------------------------------------------------------------
2036
2037
` nondet-return ` | Do nothing and return a nondet result (this is the default)
2037
- ` empty ` | Delete the body of the function
2038
2038
` assert-false ` | Make the body contain an assert(false)
2039
2039
` assume-false ` | Make the body contain an assume(false)
2040
2040
` assert-false-assume-false ` | Combines assert-false and assume-false
@@ -2081,8 +2081,8 @@ called by invoking these commands
2081
2081
# (Excluding those starting with __)
2082
2082
# With ones that have an assert(false) body
2083
2083
goto-instrument error_example.goto error_example_replaced.goto \
2084
- --replace -function-body '(?!__).*_error' \
2085
- --replace -function-body-options assert-false
2084
+ --generate -function-body '(?!__).*_error' \
2085
+ --generate -function-body-options assert-false
2086
2086
cbmc error_example_replaced.goto
2087
2087
2088
2088
Which gets us the output
@@ -2096,16 +2096,16 @@ Which gets us the output
2096
2096
> VERIFICATION FAILED
2097
2097
2098
2098
As opposed to the verification success we would have gotten without the
2099
- replacement
2099
+ generation.
2100
2100
2101
2101
2102
2102
The havoc option takes further parameters ` globals ` and ` params ` with this
2103
2103
syntax: ` havoc[,globals:<regex>][,params:<regex>] ` (where the square brackets
2104
2104
indicate an optional part). The regular expressions have the same format as the
2105
- those for the ` --replace -function-body ` and ` --generate-function-body ` options
2106
- and indicate which globals and function parameters should be set to nondet. All
2107
- regular expressions require exact matches (i.e. the regular expression ` ab? `
2108
- will match 'a' and 'b' but not 'adrian' or 'bertha').
2105
+ those for the ` --generate -function-body ` option and indicate which globals and
2106
+ function parameters should be set to nondet. All regular expressions require
2107
+ exact matches (i.e. the regular expression ` a|b ` will match 'a' and 'b' but not
2108
+ 'adrian' or 'bertha').
2109
2109
2110
2110
Example: With a C program like this
2111
2111
@@ -2120,8 +2120,8 @@ Example: With a C program like this
2120
2120
And the command line
2121
2121
2122
2122
goto-instrument in.goto out.goto
2123
- --replace -function-body do_something_with_complex
2124
- --replace -function-body-options
2123
+ --generate -function-body do_something_with_complex
2124
+ --generate -function-body-options
2125
2125
'havoc,params:.*,globals:AGlobalComplex'
2126
2126
2127
2127
The goto code equivalent of the following will be generated:
@@ -2133,6 +2133,8 @@ The goto code equivalent of the following will be generated:
2133
2133
complex->real = nondet_double();
2134
2134
complex->imag = nondet_double();
2135
2135
}
2136
+ AGlobalComplex.real = nondet_double();
2137
+ AGlobalComplex.imag = nondet_double();
2136
2138
return nondet_int();
2137
2139
}
2138
2140
@@ -2159,8 +2161,8 @@ Code like this will be generated:
2159
2161
}
2160
2162
2161
2163
Note that no attempt to follow the ` next ` pointer is made. If an array of
2162
- unknown (or 0) size is encountered, a diagnostic is emitted and the array
2163
- is not further examined.
2164
+ unknown (or 0) size is encountered, a diagnostic is emitted and the array is not
2165
+ further examined.
2164
2166
2165
2167
Some care must be taken when choosing the regular expressions for globals and
2166
2168
functions. Names starting with ` __ ` are reserved for internal purposes; For
0 commit comments