Commit Graph

20554 Commits

Author SHA1 Message Date
Daniel Poetzl 8279e91a60 Constant propagation of CProverString.setLength()
Only minimal tests are added at this point. The error conditions (like index out
of bounds) will be handled by the models. Once we have models that use
CProverString.setLength(), more comprehensive tests will be added.
2019-09-29 12:55:11 +01:00
Daniel Poetzl fd4a8ece9c
Merge pull request #5131 from danpoe/feature/constant-propagation-of-delete
Constant propagation of delete() for StringBuilder and StringBuffer
2019-09-26 18:23:58 +01:00
Chris Smowton aba7e7533f cfgt accessors: use map type, not template instruction type
This is required because otherwise a cfgt<..., goto_programt::targett> wouldn't be able to
accept const_targett as an argument to get_node_index(...) etc, which is undesirable. In
particular its own entry_mapt::keys() would not be usable. In general this ought to be some
constified version of 'I', but since base `cfgt` is currently restricted to either targett
or const_targett then statically specifying const_targett suffices.
2019-09-26 15:52:18 +01:00
Daniel Poetzl 76b89d56e9 Constant propagation of delete() for StringBuilder and StringBuffer 2019-09-26 15:42:53 +01:00
Chris Smowton 4f8065f6b4 NondetEnumOpaqueReturn: don't require that a clinit method is loaded
Symex-driven loading may notice that the clinit method is not really reachable, because
we're calling a virtual method with no truly viable callees, which amounts to an assume(false).
2019-09-26 15:26:59 +01:00
Chris Smowton 4c0bc6435b Symex: distinguish reachability from the state guard
Previously the state guard being false was taken to indicate unreachable code,
and different causes of unreachability were handled inconsistently:

* ASSUME false implied unreachability but had no effect on the guard
* --unwind or --depth being exceeded usually meant setting the guard false

This meant that expensive code downstream of an ASSUME false *was* executed, but the state
guard was maintained as usual including shrinking the guard when branches converge, while
--unwind or --depth limit breaks led to code *not* being executed (vital for these options
to function properly) but the state guard grew ever larger because the part that had gone
missing (been set to false) never got merged back in.

This commit distinguishes the two concepts: the "reachable" flag is set false whenever a
limit break OR and ASSUME false happens, but state guard maintenance continues as normal.
A new symex_unreachable_goto tries to find some way through the CFG back to reachable code;
when it can't due to loops *then* it sets the state guard to false, signifying our not
being able to figure out where the guard ought to be merged back in.

This means that ASSUME false instructions now correctly truncate execution and are
recognised as unreachable code for the purposes of state merging (leading to better
constant propagation downstream), but in some cases we may see more guard growth
because code downstream of an ASSUME false is executed less rigorously that before,
which could result in the guard not being merged or being merged later than it otherwise
would have been.

Depth and unwind limit breaks behave roughly as before, except that there is some chance
the state guard will be merged rather than discarded, reducing costs downstream.
2019-09-26 15:26:59 +01:00
Chris Smowton 7418e731f6 Add exprt::drop_source_location
This removes the source location entirely from a given expression
2019-09-26 15:05:07 +01:00
Chris Smowton 7b8cb508cc Split java_bytecode_languaget::convert_single_method
This allows us to enforce invariants more cleanly, and gives us a place
to put post-conversion processing.
2019-09-26 15:05:06 +01:00
Chris Smowton bb09891236
Merge pull request #5130 from smowton/smowton/admin/symex-code-owner
Make Romain a code owner for symex, per Peter Schrammel's recommendation
2019-09-26 14:52:10 +01:00
Chris Smowton c7b1bc7bbf Make Romain a code owner for symex, per Peter Schrammel's recommendation 2019-09-26 10:06:51 +01:00
Romain Brenguier ed2936406e
Merge pull request #5128 from romainbrenguier/bugfix/negative-size-arrays
[TG-9313] Fix invariant failure in case of negative size arrays
2019-09-26 09:44:23 +01:00
Romain Brenguier 9171c86964
Merge pull request #5117 from romainbrenguier/experiment/never-throw
[TG-9400][UFC] Add an assume-no-exceptions-thrown option
2019-09-25 16:20:40 +01:00
Romain Brenguier b433f5c688 Test assert-no-exceptions-thrown and runtime exception
Test that when both are combined, --throw-runtime-exception still
works.
2019-09-25 13:03:03 +01:00
Romain Brenguier 4259db2002 Add a test with array of negative size
This tests that defining an array with negative size does not make JBMC crash.
2019-09-25 12:07:21 +01:00
Romain Brenguier d6da90945c Make flattening accept negative array sizes
If the specified array size is negative just do as if it was 0, this is
similar to the case where the array size is not given.
2019-09-25 12:07:21 +01:00
Romain Brenguier 03026cbd3b Make field_sensitivity ignore negative size arrays
This used to make an invariant fail when the input array had negative
size.
2019-09-25 12:07:21 +01:00
Romain Brenguier 7cdd2e2777 Add regression test for --assert-no-exceptions-thrown
This tests the option behaves as desired.
2019-09-25 11:30:29 +01:00
Romain Brenguier 2ed5dfd4c2 Add an assert-no-exceptions-thrown option
This is to specify that we want to replace all throw instructions by
assert false.
This is useful mainly for performance reasons as it simplifies
conditions for symex, while retaining the non-exceptional behaviour of
the program.
2019-09-25 11:30:29 +01:00
Romain Brenguier 06c4069876 Extract java_bytecode_language_optionst class
Extract java_bytecode_language_optionst class from
java_bytecode_language class, to make it more structured by separating
the fields that are expected to remain constant during the execution
once they are initialized.
2019-09-25 11:30:29 +01:00
Daniel Poetzl 2af983daac
Merge pull request #5126 from danpoe/feature/constant-propagation-of-delete-char-at
Constant propagation of deleteCharAt()
2019-09-24 10:40:35 +01:00
Daniel Poetzl 193a29b5e6 Constant propagation of deleteCharAt()
This implements constant propagation of CProverString.deleteCharAt() which in
turn enables constant propagation of StringBuilder.deleteCharAt() and
StringBuffer.deleteCharAt().
2019-09-23 23:32:21 +01:00
thomasspriggs 1b9409298e
Merge pull request #5107 from thomasspriggs/tas/alternative-loading-compatibility-minimal
Minor java loading changes to support alternative loading strategies
2019-09-23 19:12:56 +01:00
Romain Brenguier bec782e8b6
Merge pull request #5112 from romainbrenguier/feature/assign-from-json-ref
[TG-9450] Allocate reference arrays with constant size in assignments from json
2019-09-23 15:39:42 +01:00
Daniel Poetzl 85d5e13a79
Merge pull request #5125 from danpoe/fixes/string-preprocessing-string-buffer-delete-char-at
Fix string solver string preprocessing of deleteCharAt()
2019-09-23 15:06:21 +01:00
Daniel Poetzl c785b9bd4c Adapt existing CProverString.deleteCharAt() test and add new tests
Change existing test such that it cannot be solved by constant propagation, add
a test for which verification fails, and add variants that use StringBuffer
instead of StringBuilder.
2019-09-23 12:15:15 +01:00
Romain Brenguier bc47e4906e Add regression test for static array propagation
This checks that array cell sensitivity works fine for static arrays,
whether we use the --static-values option or not.
2019-09-23 12:10:22 +01:00
Romain Brenguier 9d60ccf4a3 Add unit test for references to arrays
This is a case for the json conversion which requires particular
attention.
2019-09-23 12:10:21 +01:00
Romain Brenguier b66226eca3 assign_from_json returns code_with_references_listt
This will allow references to be replaced after the all value pairs
have been replaced.
For instance in the regression test
regression/jbmc/deterministic_assignments_json/test_char_array_pass.desc
the reference 2 wouldn't have been assigned before the end of the
assign_from_json call in which it is referenced for the first time so
its allocation size would be non-deterministic but this is fixed by this
commit.
2019-09-23 12:10:10 +01:00
Romain Brenguier 5cd0c45842 add_to_front method for code_with_references_listt
This will make it easier to add declarations at the begginning of a list of
codet after the rest of the code has been generated.
2019-09-23 12:08:19 +01:00
Romain Brenguier 93aa152425 Set the array length of reference when it is assigned
We know the number of elements of the reference array only when it is
assigned so we replace the reference.array_length field at that point.
2019-09-23 12:08:19 +01:00
Romain Brenguier c9f4b2b7e3 Get rid of block field of object_creation_infot
This should be an output of the functions rather than an "info".
We make it so that assign_*_from_json functions have a return
type which reflects what the function does. That way we separate
the json to assignment conversion from the writting of code blocks,
which will ultimately allow us to rewrite references in the assignments.
2019-09-23 12:08:19 +01:00
Romain Brenguier b40ac5956e Add a class for code with references
This will be use in assign_from_json for json files in which the "@ref"
and "@id" entries are used, so that we can easily substitute code marked
by "@ref" by the code corresponding to the object marked by "@id".

This also move object_creation_referencet to the new header file since
it will be used there, and the allocate_array is now declared in the new
header and defined in the corresponding cpp file.
2019-09-23 12:08:19 +01:00
Romain Brenguier 4879a7458b Move some code from assign_from_json to new file
This is in preparation for adding a new class in this file, we add there
the function and class which will be needed by this class.
2019-09-23 12:08:19 +01:00
Romain Brenguier 85cf5a4369 Make allocate_array take location and return code
This better reflects what this function does and make it easier to
refactor.
2019-09-23 12:08:19 +01:00
Daniel Poetzl c427ac0d6c Fix typo in string solver string preprocessing
The typo prevented CProverString.deleteCharAt(StringBuffer) from being replaced
by the corresponding string solver primitive.
2019-09-23 11:18:16 +01:00
Owen Mansel-Chan ff1f6c754e
Merge pull request #5104 from owen-mc-diffblue/owen/change-how-cprover-nondetinitialize-is-called
Make cproverNondetInitialize be inherited [TG-8677]
2019-09-23 11:02:42 +01:00
Daniel Poetzl b30b06aec7
Merge pull request #5116 from danpoe/feature/string-buffer-append
Tests for constant propagation of StringBuffer.append()
2019-09-23 10:38:24 +01:00
Daniel Poetzl 23e8572da3
Merge pull request #5110 from danpoe/feature/string-constructors
Tests for constant propagation of string constructors
2019-09-23 10:37:34 +01:00
Owen Mansel-Chan f097054d17
Merge pull request #5121 from owen-mc-diffblue/owen-mc-diffblue/extremely-minor-code-improvement
Extremely minor code improvement
2019-09-21 06:14:17 +01:00
Owen c156475a17 Move variable declaration inside conditional
Also switch to brace initialisation
2019-09-20 16:31:17 +01:00
Owen Mansel-Chan 9c0e0d36b9
Merge pull request #5115 from antlechner/antonia/context-include
[TG-9294][UFC] Fix context-include/exclude jbmc options
2019-09-20 16:30:33 +01:00
thomasspriggs c7e449b1ef
Merge pull request #5085 from thomasspriggs/tas/invariant_matcher
Improve catch support for checking of thrown instances of `invariant_failedt`
2019-09-20 15:26:07 +01:00
johndumbell d4f345bf3d Make any children of irept automatically use the irep pretty-printer 2019-09-20 13:00:29 +01:00
Daniel Poetzl 906c2f3945 Add tests for constant propagation of StringBuffer.append(Object) 2019-09-20 12:11:22 +01:00
Daniel Poetzl 5889579c29 Add tests for constant propagation of StringBuilder.append(Object) 2019-09-20 12:11:22 +01:00
Chris Smowton 22dc0f5ef5 Make symbol table refs const
These never needed to be mutable. Making them const means that they
can be used from contexts where the symbol table is const.
2019-09-20 10:59:27 +01:00
Thomas Spriggs 91d162646a Add printing of `invariant_failedt` in test failure messages
This means that generated error messages show what the particular
invariant failure actually generated was, instead of the catch framework
default of `{?}`.
2019-09-20 10:15:04 +01:00
Thomas Spriggs 7bf92cb225 Replace `try` `catch` blocks with `REQUIRE_THROWS_MATCHES`
`REQUIRE_THROWS_MATCHES` is the functionality built into the catch
framework for this purpose. Using it allows more concise specification
of the requirement.
2019-09-20 10:15:04 +01:00
Thomas Spriggs fafafbd90c Add catch framework matcher for `invariant_failuret` testing
This utility supports writing more succinct requirements on
`invariant_failuret` being thrown and the reason for which it was
thrown.
2019-09-20 10:15:04 +01:00
Romain Brenguier 20164f5bc2
Merge pull request #5106 from romainbrenguier/refactor/assign-from-json
[TG-9450] Allocate array with right length when "@nondetLength" not used in Json
2019-09-20 09:19:46 +01:00