@@ -2014,27 +2014,27 @@ Flag | Check
20142014` --uninitialized-check ` | add checks for uninitialized locals (experimental)
20152015` --error-label label ` | check that given label is unreachable
20162016
2017- #### Generating/Replacing function bodies
2017+ #### Generating function bodies
20182018
20192019Sometimes implementations for called functions are not available in the goto
20202020program, or it is desirable to replace bodies of functions with certain
20212021predetermined stubs (for example to confirm that these functions are never
20222022called, 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:
20332034
20342035 Option | Result
20352036-----------------------------|-------------------------------------------------------------
20362037 ` nondet-return ` | Do nothing and return a nondet result (this is the default)
2037- ` empty ` | Delete the body of the function
20382038 ` assert-false ` | Make the body contain an assert(false)
20392039 ` assume-false ` | Make the body contain an assume(false)
20402040 ` assert-false-assume-false ` | Combines assert-false and assume-false
@@ -2081,8 +2081,8 @@ called by invoking these commands
20812081 # (Excluding those starting with __)
20822082 # With ones that have an assert(false) body
20832083 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
20862086 cbmc error_example_replaced.goto
20872087
20882088Which gets us the output
@@ -2096,16 +2096,16 @@ Which gets us the output
20962096> VERIFICATION FAILED
20972097
20982098As opposed to the verification success we would have gotten without the
2099- replacement
2099+ generation.
21002100
21012101
21022102The havoc option takes further parameters ` globals ` and ` params ` with this
21032103syntax: ` havoc[,globals:<regex>][,params:<regex>] ` (where the square brackets
21042104indicate 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').
21092109
21102110Example: With a C program like this
21112111
@@ -2120,8 +2120,8 @@ Example: With a C program like this
21202120And the command line
21212121
21222122 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
21252125 'havoc,params:.*,globals:AGlobalComplex'
21262126
21272127The goto code equivalent of the following will be generated:
@@ -2133,6 +2133,8 @@ The goto code equivalent of the following will be generated:
21332133 complex->real = nondet_double();
21342134 complex->imag = nondet_double();
21352135 }
2136+ AGlobalComplex.real = nondet_double();
2137+ AGlobalComplex.imag = nondet_double();
21362138 return nondet_int();
21372139 }
21382140
@@ -2159,8 +2161,8 @@ Code like this will be generated:
21592161 }
21602162
21612163Note 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.
21642166
21652167Some care must be taken when choosing the regular expressions for globals and
21662168functions. Names starting with ` __ ` are reserved for internal purposes; For
0 commit comments