Skip to content

Commit 7420f4a

Browse files
committed
Squashed 'cbmc/' changes from 768e8a6..ad62682
ad62682 Merge pull request diffblue#2071 from thk123/refactor/split-string-unit-tests fc8ba88 Revert to aborting precondition for function inputs 3e2ab6f Merge pull request diffblue#2080 from diffblue/java-bytecode-dependency 6ff1eec cbmc: remove dependency on java_bytecode 0bff19b Merge pull request diffblue#2049 from karkhaz/kk-factor-goto-model-processing 79e3b25 Merge pull request diffblue#2084 from tautschnig/has_subtype-test cd45b0b Test has_subtype on recursive data types 85ac315 Merge pull request diffblue#2082 from thomasspriggs/default_dstring_hash 28c2e8b Merge pull request diffblue#2065 from tautschnig/be-constructor afa6023 Merge pull request diffblue#2061 from tautschnig/simplify-extractbits 014d151 Factor out getting & processing goto-model 06b3adc Merge pull request diffblue#2077 from peterschrammel/stable-tmp-var-names 0b3170d Stabilize clinit wrapper function type parameters 3cd8bf4 Temporary vars tests for goto-diff 9f0626c Prefix temporary var names with function id ca678aa More permissive regression tests regarding tmp var suffixes 47951ca Merge pull request diffblue#2079 from romainbrenguier/bugfix/has-subtype-recursion dd73b1a Specify default hash function of `dstringt` to STL. fe8e589 Avoid infinite recursion in has_subtype 00b9bf6 Merge pull request diffblue#2051 from svorenova/generics_tg2717 cd4bfc3 Merge pull request diffblue#2078 from romainbrenguier/bool-literal-in-while-loop 67ea889 Use bool literal in while loop d229ad9 Merge pull request diffblue#2056 from diffblue/fix-regression-cbmc-memcpy1 506faf0 Refactor a function for base existence 617d388 Utility functions for generic types c07e6ca Update generic specialization map when replacing pointers ed26d0a Merge pull request diffblue#2058 from peterschrammel/stable-disjuncts b663734 Simplify extractbits(concatenation(...)) b091560 Typing and refactoring of simplify_extractbits 49ad1bd Merge pull request diffblue#974 from tautschnig/fix-assert-encoding 16e9599 Merge pull request diffblue#2063 from tautschnig/has-subtype 950f58b Merge pull request diffblue#2060 from tautschnig/opt-local-map 4222a94 Regression tests for unstable instanceof and virtual method disjuncts b44589e Make disjuncts in instanceof removal independent of class loading 3afff86 Make disjuncts in virtual method removal independent of class loading a385d9b Allowed split_string to be used on whitespace if not also trying to strip fe4a642 Merge pull request diffblue#2062 from tautschnig/no-has-deref 145f474 Adding tests for empty string edge cases 07009d4 Refactored test to run all combinations 252c24c Migrate old string utils unit tests e87edbf Removing wrong elements from the make file b165c52 make test work on 32-bit Linux b804570 Merge pull request diffblue#2048 from JohnDumbell/improvement/adding_null_object_id 61f14d8 Merge pull request diffblue#1962 from owen-jones-diffblue/owen-jones-diffblue/simplify-replace-java-nondet fdee7e8 Merge pull request diffblue#2059 from tautschnig/generalise-test 4625cc5 Extend global has_subexpr to take a predicate as has_subtype does e9ebd59 has_subtype(type, pred, ns) to search for contained type matching pred 1f1f67f Merge pull request diffblue#1889 from hannes-steffenhagen-diffblue/develop-feature_generate_function_bodies 048c188 Add unit test for java_replace_nondet 0fe48c9 Make remove_java_nondet work before remove_returns bcc4dc4 Use byte_extract_exprt constructor a1814a3 Get rid of thin (and duplicate) has_dereference wrapper 4122a28 Test to demonstrate assert bug on alpine d44bfd3 Also simplify assert structure found on alpine linux c5cde18 Do not generate redundant if statements in assert expansions 4fb0603 Make is_skip publicly available and use constant argument 5832ffd Negative numbers should also pass the test 3c23b28 Consistently disable simplify_exprt::local_replace_map da63652 Merge pull request diffblue#2054 from romainbrenguier/bugfix/clear-equations d77f6a2 Merge pull request diffblue#1831 from NathanJPhillips/feature/class-annotations 60c8296 Clear string_refinement equations (not dependencies) 314ed53 Correcting the value of ID_null_object 751a882 Factor out default CBMC options to static method 6f24009 Can now test for an option being set in optionst 9a8d937 Add to_annotated_type and enable type_checked_cast for annotated_typet ca77b4e Add test for added annotations b06a27d Introduce abstract qualifierst base class e6fb3bf Pretty printing of java_class_typet e22b95b Fix spurious virtual function related keywords 3ac6d17 Add type_dynamic_cast and friends for java_class_typet ce1f4d2 Add annotations to java_class_typet, its methods and fields f84753d Merge pull request diffblue#2042 from hannes-steffenhagen-diffblue/add_deprecate_macro 7a38669 Merge pull request diffblue#2017 from NathanJPhillips/feature/overlay-classes 75a4aec Revert "the deprecation will need to wait until codebase is clean" 67735b5 Disable deprecation warnings by default 0764f77 Merge pull request diffblue#2036 from romainbrenguier/id_array_list 690b606 Merge pull request diffblue#2039 from peterschrammel/fix-duplicate-msg-json-ui bba17d9 the deprecation will need to wait until codebase is clean 822c757 Regression test for redundant JSON message output de0644d Only force end of previous message if there actually is one. 5a637bf Merge pull request diffblue#2037 from hannes-steffenhagen-diffblue/add_deprecate_macro bff456a Merge pull request diffblue#2040 from tautschnig/remove-swp 87ebe90 Remove vim temp file 228c019 Fix duplicate message output in json-ui 0a2c43e Add DEPRECATED to functions documented as \deprecated 47f4b35 interval_sparse_arrayt constructor from array-list 026c4ca Declare an array_list_exprt class 50a2696 Define ID_array_list 513b67a Merge pull request diffblue#2038 from romainbrenguier/bugfix/assign-at-malloc-site c207106 Test with array of strings 60183a3 Assign string at malloc site 116fffd Add DEPRECATED macro to mark deprecated functions and variables 7952f2c Add option to generate function body to goto-instrument 3d4183a Add ability to overlay classes with new definitions of existing methods dbc2f71 Improve code and error message in infer_opaque_type_fields 7c0ea4d Tidied up java_class_loader_limitt git-subtree-dir: cbmc git-subtree-split: ad62682
1 parent 60d2729 commit 7420f4a

File tree

236 files changed

+4313
-1172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

236 files changed

+4313
-1172
lines changed

CHANGELOG

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
5.9
2+
===
3+
* GOTO-INSTRUMENT: --generate-function-body can be used to
4+
generate bodies for functions that don't have a body
5+
in the goto code. This supercedes the functionality
6+
of --undefined-function-is-assume-false
7+
18
5.8
29
===
310

CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
2222
# Ensure NDEBUG is not set for release builds
2323
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
2424
# Enable lots of warnings
25-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror")
25+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wno-deprecated-declarations")
2626
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
2727
# This would be the place to enable warnings for Windows builds, although
2828
# config.inc doesn't seem to do that currently
@@ -75,7 +75,6 @@ set_target_properties(
7575
mmcc
7676
pointer-analysis
7777
solvers
78-
string_utils
7978
test-bigint
8079
testing-utils
8180
unit

doc/cbmc-user-manual.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,6 +2014,164 @@ Flag | Check
20142014
`--uninitialized-check` | add checks for uninitialized locals (experimental)
20152015
`--error-label label` | check that given label is unreachable
20162016

2017+
#### Generating function bodies
2018+
2019+
Sometimes implementations for called functions are not available in the goto
2020+
program, or it is desirable to replace bodies of functions with certain
2021+
predetermined stubs (for example to confirm that these functions are never
2022+
called, or to indicate that these functions will never return). For this purpose
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:
2034+
2035+
Option | Result
2036+
-----------------------------|-------------------------------------------------------------
2037+
`nondet-return` | Do nothing and return a nondet result (this is the default)
2038+
`assert-false` | Make the body contain an assert(false)
2039+
`assume-false` | Make the body contain an assume(false)
2040+
`assert-false-assume-false` | Combines assert-false and assume-false
2041+
`havoc` | Set the contents of parameters and globals to nondet
2042+
2043+
The various combinations of assert-false and assume-false can be used to
2044+
indicate that functions shouldn't be called, that they will never return or
2045+
both.
2046+
2047+
Example: We have a program like this:
2048+
2049+
// error_example.c
2050+
#include <stdlib.h>
2051+
2052+
void api_error(void);
2053+
void internal_error(void);
2054+
2055+
int main(void)
2056+
{
2057+
int arr[10] = {1,2,3,4,5, 6, 7, 8, 9, 10};
2058+
int sum = 0;
2059+
for(int i = 1; i < 10; ++i)
2060+
{
2061+
sum += arr[i];
2062+
}
2063+
if(sum != 55)
2064+
{
2065+
// we made a mistake when calculating the sum
2066+
internal_error();
2067+
}
2068+
if(rand() < 0)
2069+
{
2070+
// we think this cannot happen
2071+
api_error();
2072+
}
2073+
return 0;
2074+
}
2075+
2076+
Now, we can compile the program and detect that the error functions are indeed
2077+
called by invoking these commands
2078+
2079+
goto-cc error_example.c -o error_example.goto
2080+
# Replace all functions ending with _error
2081+
# (Excluding those starting with __)
2082+
# With ones that have an assert(false) body
2083+
goto-instrument error_example.goto error_example_replaced.goto \
2084+
--generate-function-body '(?!__).*_error' \
2085+
--generate-function-body-options assert-false
2086+
cbmc error_example_replaced.goto
2087+
2088+
Which gets us the output
2089+
2090+
> ** Results:
2091+
> [internal_error.assertion.1] assertion false: FAILURE
2092+
> [api_error.assertion.1] assertion false: FAILURE
2093+
>
2094+
>
2095+
> ** 2 of 2 failed (2 iterations)
2096+
> VERIFICATION FAILED
2097+
2098+
As opposed to the verification success we would have gotten without the
2099+
generation.
2100+
2101+
2102+
The havoc option takes further parameters `globals` and `params` with this
2103+
syntax: `havoc[,globals:<regex>][,params:<regex>]` (where the square brackets
2104+
indicate an optional part). The regular expressions have the same format as the
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+
2110+
Example: With a C program like this
2111+
2112+
struct Complex {
2113+
double real;
2114+
double imag;
2115+
};
2116+
2117+
struct Complex AGlobalComplex;
2118+
int do_something_with_complex(struct Complex *complex);
2119+
2120+
And the command line
2121+
2122+
goto-instrument in.goto out.goto
2123+
--generate-function-body do_something_with_complex
2124+
--generate-function-body-options
2125+
'havoc,params:.*,globals:AGlobalComplex'
2126+
2127+
The goto code equivalent of the following will be generated:
2128+
2129+
int do_something_with_complex(struct Complex *complex)
2130+
{
2131+
if(complex)
2132+
{
2133+
complex->real = nondet_double();
2134+
complex->imag = nondet_double();
2135+
}
2136+
AGlobalComplex.real = nondet_double();
2137+
AGlobalComplex.imag = nondet_double();
2138+
return nondet_int();
2139+
}
2140+
2141+
A note on limitations: Because only static information is used for code
2142+
generation, arrays of unknown size and pointers will not be affected by this;
2143+
Which means that for code like this:
2144+
2145+
struct Node {
2146+
int val;
2147+
struct Node *next;
2148+
};
2149+
2150+
void do_something_with_node(struct Node *node);
2151+
2152+
Code like this will be generated:
2153+
2154+
void do_something_with_node(struct Node *node)
2155+
{
2156+
if(node)
2157+
{
2158+
node->val = nondet_int();
2159+
node->next = nondet_0();
2160+
}
2161+
}
2162+
2163+
Note that no attempt to follow the `next` pointer is made. If an array of
2164+
unknown (or 0) size is encountered, a diagnostic is emitted and the array is not
2165+
further examined.
2166+
2167+
Some care must be taken when choosing the regular expressions for globals and
2168+
functions. Names starting with `__` are reserved for internal purposes; For
2169+
example, replacing functions or setting global variables with the `__CPROVER`
2170+
prefix might make analysis impossible. To avoid doing this by accident, negative
2171+
lookahead can be used. For example, `(?!__).*` matches all names not starting
2172+
with `__`.
2173+
2174+
20172175
\subsection man_instrumentation-api The CPROVER API Reference
20182176

20192177
The following sections summarize the functions available to programs
Binary file not shown.
Binary file not shown.
Binary file not shown.
409 Bytes
Binary file not shown.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
@interface ClassAnnotation {
2+
}
3+
4+
@interface MethodAnnotation {
5+
}
6+
7+
@interface FieldAnnotation {
8+
}
9+
10+
@ClassAnnotation
11+
public class annotations
12+
{
13+
@FieldAnnotation
14+
public int x;
15+
16+
@FieldAnnotation
17+
public static int y;
18+
19+
@MethodAnnotation
20+
public void main()
21+
{
22+
}
23+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CORE
2+
annotations.class
3+
--verbosity 10 --show-symbol-table
4+
^EXIT=0$
5+
^SIGNAL=0$
6+
^Type\.\.\.\.\.\.\.\.: @java::ClassAnnotation struct annotations
7+
^Type\.\.\.\.\.\.\.\.: @java::MethodAnnotation \(struct annotations \*\) -> void$
8+
^Type\.\.\.\.\.\.\.\.: @java::FieldAnnotation int$
9+
--
10+
--
11+
The purpose of the test is ensuring that annotations can be shown in the symbol
12+
table.
228 Bytes
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Test {
2+
public void main() {}
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Test.class
3+
--classpath ./NotHere.jar
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^the program has no entry point$
7+
^failed to load class `Test'$
8+
--
9+
--
10+
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CORE symex-driven-lazy-loading-expected-failure
2+
Test.class
3+
--classpath ./NotHere
4+
^EXIT=6$
5+
^SIGNAL=0$
6+
^the program has no entry point$
7+
^failed to load class `Test'$
8+
--
9+
--
10+
symex-driven lazy loading should emit "the program has no entry point" but currently doesn't
583 Bytes
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Test
2+
{
3+
public int x;
4+
5+
public static void main(String[] args)
6+
{
7+
assert(false);
8+
}
9+
10+
public static void notOverlain()
11+
{
12+
assert(true);
13+
}
14+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.diffblue;
2+
3+
public @interface OverlayClassImplementation {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.diffblue;
2+
3+
public @interface OverlayMethodImplementation {
4+
}
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import com.diffblue.OverlayClassImplementation;
2+
import com.diffblue.OverlayMethodImplementation;
3+
4+
@OverlayClassImplementation
5+
public class Test
6+
{
7+
public int x;
8+
9+
@OverlayMethodImplementation
10+
public static void main(String[] args)
11+
{
12+
assert(true);
13+
}
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CORE
2+
Test.class
3+
--classpath `./format_classpath.sh . annotations correct-overlay` --verbosity 10
4+
^Getting class `Test' from file \.[\\/]Test\.class$
5+
^Getting class `Test' from file correct-overlay[\\/]Test\.class$
6+
^Adding symbol from overlay class: field 'x'$
7+
^Adding symbol from overlay class: method 'java::Test\.<init>:\(\)V'$
8+
^Field definition for java::Test\.x already loaded from overlay class$
9+
^Adding symbol from overlay class: method 'java::Test\.main:\(\[Ljava/lang/String;\)V'$
10+
^Method java::Test\.<init>:\(\)V exists in an overlay class without being marked as an overlay and also exists in the underlying class
11+
^Adding symbol: method 'java::Test\.notOverlain:\(\)V'$
12+
^VERIFICATION SUCCESSFUL$
13+
^EXIT=0$
14+
^SIGNAL=0$
15+
--
16+
^Skipping class Test marked with OverlayClassImplementation but found before original definition$
17+
^Skipping duplicate definition of class Test not marked with OverlayClassImplementation$
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
CORE
2+
Test.class
3+
--classpath `./format_classpath.sh . annotations . correct-overlay` --verbosity 10
4+
^Getting class `Test' from file \.[\\/]Test\.class$
5+
^Getting class `Test' from file correct-overlay[\\/]Test\.class$
6+
^Skipping duplicate definition of class Test not marked with OverlayClassImplementation$
7+
^Adding symbol from overlay class: field 'x'$
8+
^Adding symbol from overlay class: method 'java::Test\.<init>:\(\)V'$
9+
^Field definition for java::Test\.x already loaded from overlay class$
10+
^Adding symbol from overlay class: method 'java::Test\.main:\(\[Ljava/lang/String;\)V'$
11+
^Method java::Test\.<init>:\(\)V exists in an overlay class without being marked as an overlay and also exists in the underlying class
12+
^Adding symbol: method 'java::Test\.notOverlain:\(\)V'$
13+
^VERIFICATION SUCCESSFUL$
14+
^EXIT=0$
15+
^SIGNAL=0$
16+
--
17+
^Skipping class Test marked with OverlayClassImplementation but found before original definition$
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
unameOut="$(uname -s)"
4+
case "${unameOut}" in
5+
CYGWIN*) separator=";";;
6+
MINGW*) separator=";";;
7+
MSYS*) separator=";";;
8+
Windows*) separator=";";;
9+
*) separator=":"
10+
esac
11+
12+
echo -n `IFS=$separator; echo "$*"`
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
Test.class
3+
--classpath `./format_classpath.sh annotations correct-overlay .` --verbosity 10
4+
^Getting class `Test' from file correct-overlay[\\/]Test\.class$
5+
^Getting class `Test' from file \.[\\/]Test\.class$
6+
^Skipping class Test marked with OverlayClassImplementation but found before original definition$
7+
^Adding symbol: field 'x'$
8+
^Adding symbol: method 'java::Test\.main:\(\[Ljava/lang/String;\)V'$
9+
^Adding symbol: method 'java::Test\.notOverlain:\(\)V'$
10+
^VERIFICATION FAILED$
11+
^EXIT=10$
12+
^SIGNAL=0$
13+
--
14+
^Skipping duplicate definition of class Test not marked with OverlayClassImplementation$
15+
^Adding symbol from overlay class
16+
exists in an overlay class without being marked as an overlay and also exists in the underlying class
Binary file not shown.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import com.diffblue.OverlayClassImplementation;
2+
import com.diffblue.OverlayMethodImplementation;
3+
4+
public class Test
5+
{
6+
@OverlayMethodImplementation
7+
public static void main(String[] args)
8+
{
9+
assert(false);
10+
}
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CORE
2+
Test.class
3+
--classpath `./format_classpath.sh . annotations unmarked-overlay` --verbosity 10
4+
^Getting class `Test' from file \.[\\/]Test\.class$
5+
^Getting class `Test' from file unmarked-overlay[\\/]Test\.class$
6+
^Skipping duplicate definition of class Test not marked with OverlayClassImplementation$
7+
^Adding symbol: field 'x'$
8+
^Adding symbol: method 'java::Test\.main:\(\[Ljava/lang/String;\)V'$
9+
^Adding symbol: method 'java::Test\.notOverlain:\(\)V'$
10+
^VERIFICATION FAILED$
11+
^EXIT=10$
12+
^SIGNAL=0$
13+
--
14+
^Skipping class Test marked with OverlayClassImplementation but found before original definition$
15+
^Adding symbol from overlay class
16+
exists in an overlay class without being marked as an overlay and also exists in the underlying class
Binary file not shown.

0 commit comments

Comments
 (0)