Commit Graph

20184 Commits

Author SHA1 Message Date
Romain Brenguier ca78842ca6 Document how arrays are handled by field sensitivity
This explains how field sensitivity transforms instructions that contain
array operations.
2019-08-21 09:40:14 +01:00
Chris Smowton c93c1ca9ff Add tests for array-cell sensitivity
Most are for C, then a couple are duplicated for Java to check whether its use of a structure
to represent all arrays makes any difference.
2019-08-21 09:40:14 +01:00
Romain Brenguier c3fdc33083 Simplify lhs in build goto trace
Avoid lhs of the form `{array[0], array[1]}[0]`
2019-08-21 09:40:14 +01:00
Romain Brenguier 162abbd18a Tag test failing with SMT backend
This is failing because of this bug:
https://github.com/diffblue/cbmc/issues/4749
2019-08-21 09:40:14 +01:00
Romain Brenguier d857648bfd Adapt double_deref test for array cell sensitivity
Propagatiof of values of array cells lead to different expressions in VCC.
2019-08-21 09:40:14 +01:00
Romain Brenguier 91de1649a0 Allow trace to assign in two steps
With field sensitivity on arrays, the element can be initialized in two
steps, first the field f then the field array.
2019-08-21 09:40:14 +01:00
Romain Brenguier e86810e6b2 Apply field sensitivity in symex_printf
This may be necessary for constant propagation of the format string.
An example of that is in regression/cbmc/printf1
2019-08-21 09:40:14 +01:00
Romain Brenguier 33e00378c6 Only apply field_sensitivity to dereferenced object
This is important to consider dereferenced object as read value.
2019-08-21 09:40:14 +01:00
Romain Brenguier d11beceb38 Make field_sensitivity::apply handle non-constant index
When the index is not constant when accessing a constant size array, we
should expand the expression into `{array[0]; array[1];...}[index]` so
that the relation with field sensitivity expressions `array[[0]]`,
`array[[1]]`, etc, is not lost.
2019-08-21 09:40:14 +01:00
Romain Brenguier 22f3570365 Rename size to L2 in field_sensitivity::apply
This is to allow constant propagation to take place and know whether the
size is actually constant, which can allow field sensitivity to apply.
2019-08-21 09:40:14 +01:00
Romain Brenguier 08a71e9284 Attempt to get missing array size from symbol table
In some cases, like the test in regression/cbmc/Global_Initialization2,
the array type is incomplete and changed in the symbol table after the
main function has been converted, leading to inconsistencies.
This means we can get nil instead of the size in
field_sensitivityt::apply, though the actual size is present in the
symbol table.
The issue is reported here: https://github.com/diffblue/cbmc/issues/5022
2019-08-21 09:40:14 +01:00
Romain Brenguier 7b958bf4c9 Set a limit size for array cell propagation
The use of field_sensitivity for arrays can be expensive for big arrays
so we have to set a limit on the size of constant arrays which get
processed.
The value 64 was determined by changing the size of the array in the
test regression/cbmc/variable-access-to-constant-array and reducing it
until there was no significant difference in execution time between the
versions of CBMC with and without array cell propagation.
For the chosen value the execution time was around 0.05 second in both
cases (for comparison with size 1024 the time with propagation was 0.5
sec, against 0.1 without).
2019-08-21 09:40:14 +01:00
Chris Smowton 026a5104ab Resolve array indices before dereferencing
This may lead to application of array-cell-sensitivity (i.e. querying the symbol
some_array[[1]] instead of some_array[some_index]), leading to higher precision.

Some tests must be amended because better constant propagation causes some test behaviour
to change as symex has better knowledge regarding the targets of pointers.
2019-08-21 09:40:14 +01:00
Chris Smowton da30884721 Array cell sensitivity: tolerate zero-length arrays 2019-08-21 09:40:14 +01:00
Chris Smowton 1f334015c2 Symex: enable array cell sensitivity 2019-08-21 09:40:14 +01:00
Chris Smowton 13ccc773e2 Add L1_WITH_CONSTANT_PROPAGATION mode to goto_symex_statet::rename
This allows applying constant propagation without upgrading non-constant symbols to L2,
which is useful for the dereferencing logic, as the value-set used to resolve pointer
aliasing is indexed by L1 names.
2019-08-21 09:40:14 +01:00
jeannielynnmoulton 153a4b93f3
Merge pull request #5038 from jeannielynnmoulton/jeannie/NoEscape
Do not escape ' in java strings
2019-08-20 17:39:34 +01:00
Romain Brenguier 04aa83e4b3
Merge pull request #5040 from diffblue/bugfix/empty-string-propagation
Fix array length in symex constant string propagation [TG-9048]
2019-08-20 16:28:06 +01:00
Jeannie Moulton 93004ed806 Tests for utf16_native_endian_to_java_string
utf16_native_endian_to_java_string should not escape the ' character.
2019-08-20 16:14:08 +01:00
Jeannie Moulton 9a66e75b8f Remove utf16_native_endian_to_java(std::wstring)
This has been replaced by
utf16_native_endian_to_java_string(std::wstring)
2019-08-20 16:14:08 +01:00
Jeannie Moulton c1a00b2a27 Do not escape ' character in java strings.
When printing a character, it is required to escape the ' character, but
when printing it as part of a string, it is not. Therefore, this has
been separated into two separate functions.
2019-08-20 16:14:06 +01:00
Romain Brenguier 334714a4c1 Add trace check in StringBuilder test for empty array
This tests would fail before the fix to the symex constant propagation
of strings.
2019-08-20 14:18:13 +01:00
Romain Brenguier 7a3202b20c Improve the StringBuilder constructor tests
Split the tests for the different constructors, add assertions that
are supposed to fail, and activate the tests that can be.
2019-08-20 14:17:50 +01:00
Romain Brenguier 40a22bce1c Add length assumption at assign_string_constant beginning
This is to make sure that the length of the array before the assignment
isn't unconstrained. Otherwise it could be set to be arbitrarily large
by the solver which will causes invalid traces.
2019-08-20 14:17:46 +01:00
Chris Smowton bbc9bb363c
Merge pull request #5039 from smowton/smowton/cleanup/java-instanceof-expr
Add java_instanceof_exprt, and use it in place of raw exprts
2019-08-20 13:16:25 +01:00
Chris Smowton 0319cd6dcb
Merge pull request #5037 from smowton/smowton/admin/goto-trace-constant-comment
Add documentation to `goto_trace_constant_pointer_exprt`
2019-08-20 12:49:39 +01:00
Chris Smowton bb05926a43 Add java_instanceof_exprt, and use it in place of raw exprts 2019-08-20 11:06:33 +01:00
Romain Brenguier 440ad9cc04
Merge pull request #5016 from romainbrenguier/enhance/solver-equations
Handle more formulas than just equations in string solver
2019-08-20 10:14:11 +01:00
Chris Smowton 6d6fa0a395 Add documentation to `goto_trace_constant_pointer_exprt` 2019-08-20 10:02:51 +01:00
Kareem Khazem 8c7609eaa5
Merge pull request #4985 from nchong-at-aws/insert-final-assert-false-pass
Insert final assert false pass
2019-08-19 15:51:47 +01:00
Nathan Chong 639ef8195c Add --insert-final-assert-false to goto-instrument
This option takes a function name (usually the test harness entry point) and
inserts `assert(false)` at the end of the function body. This assertion is
*expected to fail*. If it passes then this may indicate that the test harness
has inconsistent assumptions. Note that there are other reasons why the assert
may pass (such as insufficient loop unwind depth). It is up to the user to
interpret the results.
2019-08-19 09:39:43 -04:00
Romain Brenguier 462d355468 Add unit test for the string solver
This tests the solver directly on a set of desired formula instead of
through symex as would a regression test.
This can be easier to debug when trying to track a bug or add an new
feature, as the correspondence with the string solver code would be
easier to see.
2019-08-19 13:07:29 +01:00
Romain Brenguier 445a880299 Give all formulas to the solver
Even if they are not equations, they may contain formulas talking about
char arrays and other expressions which require special handling by the solver.
2019-08-19 13:07:28 +01:00
Romain Brenguier f07cbb1c56 Make equations of type exprt instead of equal_exprt
Accept formulas that are not equations as input.
This is to make the solver more robust to different kind of formulas.
In particular, formulas of the form
`guard1 => result = some_string_builin_function(s)` should be accepted.
2019-08-19 13:07:28 +01:00
Romain Brenguier 95f599ea92 Mark argument const for identifiers resolution
EXplicit that it is not modified by the function.
2019-08-19 13:07:27 +01:00
Romain Brenguier ba7578d12f Make the string ids replacement look for function_application
This make it handle the cases where the function application is not
directly the right hand side of the equation but may be deeper inside
the expression.
2019-08-19 13:07:27 +01:00
Romain Brenguier 2fc646c840 make_char_array_pointer_associations take exprt argument
This makes the function more generic
2019-08-19 13:07:26 +01:00
Romain Brenguier bfeb8dd016 Generalize `add_node` to handle more than simple equations
The add_node function was only handling expressions of the form:
`lhs = builtin_function(args)`
We make it handle more general expressions and look recursively for
functions to replace, for instance
`(lhs == a) && (builtin_function(b) == builtin_function(c))`
 would be replaced by
 `(lhs == a) && (string_builtin_return1 == string_builtin_return2)`.
2019-08-19 13:07:21 +01:00
Romain Brenguier 549dbdaedf Force move to make_node, making clear that it is moved
Since the argument is a unique_ptr, it cannot be copied so having the
function take the argument by copy means that it has to be moved at the
function call, which makes clear from there that the argument is moved
and shouldn't be used afterwards.
2019-08-19 13:04:28 +01:00
Chris Smowton 3e42990124
Merge pull request #5034 from smowton/smowton/cleanup/constant-pointer-expr
Add goto_trace_constant_pointer_exprt
2019-08-19 11:51:18 +01:00
Chris Smowton 58f8101ebf Add goto_trace_constant_pointer_exprt
These are derivatives of constant_exprt which give a pointer's numerical address in the usual
constant value slot, but which also have an operand giving its symbolic value (e.g. "0xabcd0004"
vs. "&some_object + 4"
2019-08-19 10:34:20 +01:00
yumibagge 82b08f81a0
Merge pull request #5032 from yumibagge/yb/jbmc-regression-tidy
Rename constant evaluation regression folder names
2019-08-16 12:18:44 +01:00
Yumi Bagge 225d4ffaac Clang reformat 2019-08-16 09:27:19 +01:00
Yumi Bagge 0d47ec872e Rename ConstantEvaluation folders
Renamed except IndexOf
2019-08-16 09:26:33 +01:00
Daniel Poetzl 744671a4b2
Merge pull request #4941 from danpoe/feature/constant-propagate-string-substring
[TG-7648] Constant propagation of substring operations
2019-08-15 17:58:11 +01:00
Daniel Poetzl e56041f4cf Add String.substring() and StringBuilder.substring() regression error tests
Add regression tests that check that the constant propagator does not simplify
substring() invocations with only constant arguments when the indices are out of
bounds.
2019-08-15 15:50:46 +01:00
Daniel Poetzl 8f9a9c76bc Implement constant propagation for substring operations
This implements constant propagation of ID_cprover_string_substring_func
function application expressions. These are in turn used by the various
substring operations of String and StringBuilder.
2019-08-15 15:33:44 +01:00
Daniel Kroening 60b2851617
Merge pull request #5003 from smowton/smowton/feature/revert-guards-after-calls
[TG-9002] Symex: revert guards after call return
2019-08-15 14:53:07 +01:00
Daniel Kroening 20a2055b58
Merge pull request #5018 from diffblue/java_bytecode-opX
fix exprt::opX accesses in java_bytecode
2019-08-15 14:06:26 +01:00
Thomas Kiley 31c0c5dafc
Merge pull request #5013 from thk123/improve-interface-warning
Improve error message when functional method is inherited
2019-08-15 11:40:52 +01:00