Commit Graph

759 Commits

Author SHA1 Message Date
Daniel Poetzl 3872df2941 Disable sharing stats when using msvc to avert msvc crash 2019-03-26 16:51:07 +00:00
Daniel Poetzl dc661c4149 Adapt unit test Makefile to not count disabled tests 2019-03-26 16:51:07 +00:00
Daniel Poetzl a1d7024441 Update unit tests for new sharing map interface 2019-03-26 16:51:07 +00:00
Daniel Poetzl 19d3c5c88e Refactor sharing_node_leaft
Add move constructors and remove unnecessary methods.
2019-03-26 10:28:19 +00:00
xbauch 01da544262 Add check that gdb is on the path
No functional change.  Only wraps the test cases in an if-statements checking
the presence of gdb.
2019-03-24 17:03:08 +00:00
Peter Schrammel 2e04b54cfc
Merge pull request #4217 from peterschrammel/move-bmct-jbmc
Move cbmc/bmc and all_properties to jbmc
2019-03-21 14:15:43 +00:00
Daniel Poetzl 468717f39e Make the shared pointers and write_* methods of the sharing nodes protected
The data member and the write_* methods of sharing_node_innert and
sharing_node_leaft are made protected and existing external callers are
refactored to not use write_* directly.
2019-03-21 11:15:12 +00:00
Daniel Poetzl 2614c5bac9 Add reset() method to small_shared_two_way_ptrt
This adds a reset() method which clears the contents of the shared pointer.
Furthermore, the code to remove a reference to the pointed-to object is factored
out into a method destruct(). The method is used both by the destructor and by
reset().
2019-03-21 10:59:59 +00:00
Michael Tautschnig d61900d41c
Merge pull request #4370 from tautschnig/fix-cudd-Makefile-build
Fix Makefile-based build for with CUDD
2019-03-21 10:12:16 +00:00
Peter Schrammel 14109a48ba Fix path explorer unit test
Cannot use deprecated bmct anymore.
2019-03-21 09:57:38 +00:00
Peter Schrammel 90a041da9c Move bmct and all_properties to jbmc/
These aren't used by CBMC anymore, but only
for the symex-driven lazy-loading mode of JBMC.
2019-03-21 09:54:48 +00:00
Daniel Poetzl 6533631183
Merge pull request #3983 from danpoe/feature/gdb-api
GDB API [blocks: #4261]
2019-03-19 17:04:26 +00:00
Petr Bauch d803bde3c9 Fix based on comments 2019-03-19 16:01:40 +00:00
Daniel Poetzl fcbe7b933b Add new unit tests for the gdb api
This adds new unit tests for gdb_apit. The tests compile a test file test.c and
then run gdb on it (via gdb_apit).
2019-03-19 15:52:32 +00:00
Daniel Poetzl aece5a5644 Enable and update gdb api unit tests
This enables the gdb api unit tests (in memory-analyzer/gdb_api.cpp) and adapts
them to include use_catch.h instead of catch.hpp.
2019-03-19 15:52:32 +00:00
Daniel Poetzl 7e6bd17018 Replace #ifdef __linux__ by guards allowing more Unices
We require the Unix fork() system call (in unistd.h)
2019-03-19 15:52:32 +00:00
Daniel Poetzl 0b9480bb40 Update banners for gdb api files 2019-03-19 13:42:01 +00:00
Daniel Poetzl d44dfb99c9 Adapt gdb interaction exception to cprover style 2019-03-19 13:42:01 +00:00
Malte Mues 1e71fd7fbc Add an api to analyze a core dump with gdb
Applying CBMC on large code bases
requires sometimes to model a test environment.
Running a program until a certain point and let it
crash, allows to analyze the memory state at this point in time.
In continuation, the memory state might be reconstructed as base for
the test environment model.

By using gdb to analyze the core dump, I don't have to take
care of reading and interpreting the core dump myself.
2019-03-19 13:42:01 +00:00
Chris Smowton c5d7bae08d Symex: propagate constants implied by assumptions and conditions
When passing `assume(symbol == constant)` or `if symbol == constant then GOTO`, we can populate the
constant propagator and value-set accordingly and use that information until the next merge point without
that constraint. We implement this by allocating and defining a fresh L2 generation on this path, which
will be merged as "real", assignment-derived generations are. Symbols are subject to propagation under
the same conditions as they are on assignment (e.g. requiring that they are not subject to concurrent
modification by other threads).
2019-03-18 16:15:59 +00:00
Michael Tautschnig c7db0c9e6f Fix Makefile-based build for with CUDD
The previous set-up failed to compile (as cudd.h was not found), and
first fixes to make it compile and link resulted in persistent
segmentation faults. These were caused by inconsistent includes as
HAVE_CUDD was only set in selected directories (unlike the CMake
configuration).
2019-03-14 21:41:47 +00:00
Michael Tautschnig 4fa790bdc2
Merge pull request #4385 from smowton/smowton/fix/expr-iterator-mutated
Expr-depth-iterator: support iterating over mutated expressions
2019-03-14 20:37:18 +00:00
Chris Smowton 17bee52504 Add unit tests for expr_iterator 2019-03-14 18:09:17 +00:00
Michael Tautschnig 027760b479 Pass irept by value in modifying irept::add/set operations
This should enable use (with performance benefit) of rvalue references in
higher-level APIs.
2019-03-14 15:03:12 +00:00
Romain Brenguier e80340d31a Unit test for ranget drop
This tests that these operations behave as expected and gives examples
on how to use them.
2019-03-08 14:13:53 +00:00
Romain Brenguier f9a698ce24 Remove root field of bdd_exprt
Instead the result of from_exprt and the input of as_expr should be
BDDs.
This makes it possible to reuse the same manager for several exprt
conversion and to combine the results obtain from the from_expr
conversion with BDD operations.
2019-03-07 11:02:35 +00:00
Romain Brenguier 4da4bd3dbe Remove unused field ns field of bdd_exprt
A reference to a namespace was stored without being ever used.
2019-03-07 11:02:35 +00:00
Romain Brenguier 9727c5e7e8 Add guard_manager class and pass it around
This in preparation to using BDDs to encode guards,
every part of the code creating guards need to reference a guard_manager.
2019-03-07 11:02:35 +00:00
Michael Tautschnig ab09a6c134 A decision_proceduret isn't a messaget
Some derived classes may want to generate output, but then it's safe for them to
be messaget's.
2019-03-07 06:56:11 +00:00
Michael Tautschnig 0a73e03b24 std_expr.h: add/enable missing can_cast, validate_expr
Some were unnecessarily missing, others were wrongly commented out.
2019-03-06 23:25:22 +00:00
Peter Schrammel 55f7bafeca Remove obsolete cbmc/bmc_cover
The goto-checker infrastructure is used now.
2019-03-04 18:22:31 +00:00
Michael Tautschnig 2bb84ade66
Merge pull request #3191 from sonodtt/goto_programs-validation
Goto programs validation
2019-03-04 14:37:57 +00:00
Michael Tautschnig ebfab8d2c1 Store "is hidden" attribute of goto functions in the symbol table
There should only be a single place to hold type information, including
attributes, to ensure consistency. Future changes will remove the "type" member
of goto_functiont, making the type information stored in the symbol table the
single, authoritative source of information.

With this commit the information will remain available in both places, but all
read accesses only use the information in the symbol table.
2019-03-04 10:22:10 +00:00
Peter Schrammel 585ea91c72 Remove obsolete cbmc/fault_localization
The goto-checker infrastructure is used now.
2019-03-03 21:57:51 +00:00
Sonny Martin 6ba2cf43b4 Reorder unit test headers for consistency. 2019-03-01 14:50:19 +00:00
Sonny Martin a1de5dc259 Remove extraneous goto-program checks in unit tests.
Although additional checks may hold, they have their own unit
tests and it is these tests that should fail when these checks fail.
2019-03-01 14:50:19 +00:00
Sonny Martin b5b1f64a2b Address review comments - Kroening
Removed previously disabled checks:
Not every instruction has a code member - so removed checks that both 
instruction sourcelocation and code sourcelocation are set and identical
Remove also remaining check that every instruction have a non-nil 
sourcelocation as this would have to be optional (if enabled fails 
many regression tests). This also simplifies considerably the overall 
validation pass (removes much passing around of the options structure).

Removes check on function return type - this will be preserved (#4266)

goto_model::validate now has default parameters.

Minor fixes.
2019-03-01 14:50:02 +00:00
Sonny Martin 971c788ae0 Address review comments - Kroening
Removed previously disabled checks:
Not every instruction has a code member - so removed checks that both 
instruction sourcelocation and code sourcelocation are set and identical
Remove also remaining check that every instruction have a non-nil 
sourcelocation as this would have to be optional (if enabled fails 
many regression tests). This also simplifies considerably the overall 
validation pass (removes much passing around of the options structure).

Removes check on function return type - this will be preserved (#4266)

goto_model::validate now has default parameters.

Minor fixes.
2019-03-01 14:05:54 +00:00
Michael Tautschnig 5377c2c4ef
Merge pull request #4301 from romainbrenguier/refactor/simplify_expr_copy
Make simplify_expr take copy instead of reference
2019-02-28 17:40:45 +00:00
Romain Brenguier 94b2145fdd Move arguments into simplify_expr call
We use std::move in a few places where this is made possible by the
change in interface.
2019-02-28 15:09:02 +00:00
Vojtěch Forejt be4cee2fa9
Merge pull request #4180 from forejtv/forejtv/cover-instrumentations
Extend the options for coverage instrumentation
2019-02-28 15:04:28 +00:00
Daniel Kroening d285eb8e90 pointer_offset_size functions now use optional
This reminds the user of these functionst that they might return an error.
2019-02-27 11:55:09 +00:00
Sonny Martin 1fb11297d5 Rebase and address review comments 2019-02-27 11:32:21 +00:00
Sonny Martin ab3cb608d5 Adjustments for new location of program checks 2019-02-27 10:43:26 +00:00
Sonny Martin ca1116608b Add options structure to unit tests 2019-02-27 10:43:25 +00:00
Sonny Martin 6cc09c9d4b Add boolean constructor to options structure 2019-02-27 10:43:24 +00:00
Sonny Martin a3b55130ff Use catch exception macros 2019-02-27 10:43:24 +00:00
Sonny Martin 5fddbcdcd1 Validation checks for Goto Programs
There are several checks, implemented with separate methods, and
some flagged as optional.
NB use of validate_goto_model(*this, vm) in goto_functions.h is to avoid
circular inclusion as function_mapt is a nested type and so cannot be
forward declared.
2019-02-27 10:43:07 +00:00
Vojtech Forejt 0689f81fed Unit tests for cover-only 2019-02-26 22:04:40 +00:00
Michael Tautschnig 05af336b50 Byte-operator lowering: support structs containing bit-fields
This removes the constraint on aligned member accesses. Includes factoring out
of unpack_struct to avoid growing the size of unpack_rec even further.
2019-02-26 19:09:24 +00:00
Michael Tautschnig 6a0d998124 Rewrite byte_update lowering to respect endianness, support composite types
byte_update lowering now proceeds as follows:
1) Determine the size of the update, with the size of the object to be
updated as an upper bound. We fail if neither can be determined.
2) Turn the update value into a byte array of the size determined above.
3) If the offset is not constant, turn the object into a byte array, and
use a "with" expression to encode the update; else update the values in
place.
4) Construct a new object.
2019-02-26 19:09:24 +00:00
Daniel Kroening 85ba2253fe prefer .add over .emplace
This is easier to read.
2019-02-26 13:56:53 +00:00
Romain Brenguier e1fb6b7fec Add unit test for BDD
This adds a test case to check there are no mistakes in the BDD to expr
conversions.
This test can fail without the previous fix.
2019-02-25 17:28:16 +00:00
Michael Tautschnig 24bf054b07 Do not use has_prefix in source_location.h
source_location.h is transitivly included in almost every translation unit.
Avoid the prefix.h include by moving the a method definition to the cpp file.
2019-02-21 09:57:17 +00:00
Michael Tautschnig ec3ee8e039 byte_extract lowering for complex_typet
It may have worked before via the fallback to flattening of the entire
expression to a bitvector, but let's be on the safe side and construct
appropriate expressions.
2019-02-19 20:41:08 +00:00
Peter Schrammel 7cb1056b45 Add protected do_prop_solve for overriding
This will allow us to count solver invocations
without repeating the code in each propt implementation.
2019-02-18 22:41:39 +00:00
Daniel Kroening a5944a75a9 numeric_cast_v(expr) now requires constant_expr
This is follow-up from a discussion on PR #3998, and a comment by
@tautschnig.

This function always fails, with an exception, when given anything but a
constant_exprt.

This change means that the caller must do the type conversion.  The benefit
is to make the caller more aware of the requirement that this must be a
constant, and to make the caller handle the error appropriately (with an
user-friendly error message) in case this is not possible.

The disadvantage is additional code at the call site.
2019-02-17 16:27:44 +00:00
Daniel Kroening 93d5278b21 simplify_exprt::bits2expr now returns optionalt<exprt>
This prevents accidental modifications of a nil_exprt.
2019-02-16 19:34:52 +00:00
hannes-steffenhagen-diffblue a62b5daf44
Merge pull request #4192 from hannes-steffenhagen-diffblue/string_to_optional
Add string2optional conversion functions
2019-02-15 14:25:36 +00:00
Hannes Steffenhagen e9ccc27f97 Add string2optional conversion functions
These are intended as helpers for when you want to convert a string to
and integer, but don't want to assert the result (e.g. when dealing with
user input there's usually something better you can do than outright
crashing if the conversion fails), but also don't want to deal with
exceptions (which involve more code to write and read and it's easy to
handle the wrong set of exceptions, whether it is too many or too few).
2019-02-15 12:24:04 +00:00
Michael Tautschnig 9a67ec4d55 Lowering of byte_extract over string constants
These need to be handled like arrays of characters.
2019-02-15 09:48:37 +00:00
Michael Tautschnig 004bd27a49 byte_extract lowering of pointers
Bit operations cannot be performed on pointers, thus type cast them to unsigned
bitvectors first and then convert back the result.
2019-02-14 20:52:31 +00:00
Michael Tautschnig 761ad8a2cb byte_extract lowering of unions
We previously handled unions like PODs.
2019-02-14 16:47:04 +00:00
Michael Tautschnig 5c3860636e byte_extract lowering of vectors and array cleanup
Refactor the code used for arrays to make it re-usable for vectors and arrays.
2019-02-14 15:24:53 +00:00
Michael Tautschnig d24e63f018 byte_extract lowering over arrays: fix bits vs bytes error
The offset is computed in bits.
2019-02-14 08:37:52 +00:00
Michael Tautschnig a3d77e6ac0 byte_extract lowering: ensure type consistency
Make sure we construct concatenations that are type consistent.
2019-02-14 07:09:44 +00:00
Daniel Kroening f77bca3dce use goto_progamt::make_X API
This prevents partial construction of instructiont.
2019-02-13 15:45:49 +00:00
Daniel Kroening 9e0c5a3d51 remove the trivial constructor from symex_targett::sourcet
sourcet contains an interator, and the current interface explicitly allows
it to be uninitialised.  However, most parts of the code base access
source.pc without checking.  This commit removes the option to leave the
source uninitialized.
2019-02-12 17:37:29 +00:00
Daniel Kroening e0afefd72c use instructiont::make_goto variant that takes a guard
This prevents partial construction.
2019-02-08 22:04:37 +00:00
Tuttle 01f4ee2672 Added basic block source lines to source_locationt
Block coverage obtained with "cbmc --cover locations" now reports the file name
and line number of every line of source code contributing to a basic block in
the "description" field of the xml output. (The lines contributing to a block
can come from multiple files via function inlining and definitions in include
files, so reporting line numbers alone is not sufficient.)
2019-02-07 20:44:56 +00:00
Michael Tautschnig 864fa155e6 byte_extract lowering: Fail when we _don't_ have a constant
Fixes: #4116
2019-02-07 17:32:35 +00:00
Michael Tautschnig 2dc086356a
Merge pull request #4102 from tautschnig/remove-void_typet
Remove void_typet
2019-02-07 13:11:29 +00:00
Michael Tautschnig 1f94bceb73 byte_extract lowering: lower newly introduced byte_extract expressions
byte_extract lowering must not return any further byte_extract expressions.
2019-02-07 11:24:47 +00:00
Michael Tautschnig e15756d32e Always use empty_typet instead of void_typet
void_typet was only sometimes used.
2019-02-07 11:24:24 +00:00
Michael Tautschnig 5a2df0d8b5 Fixes to the byte_operator lowering unit test
Let's only test byte extracts within bounds for now (there is ample work to be
done to get those right), but make sure there is possible combination for each
pair of types. Endianness needs to be taken into account when constructing the
expected value. Disable any non-POD tests as they all need more work.
2019-02-06 19:02:46 +00:00
Michael Tautschnig 2df457856f Avoid deprecated symbol_exprt default construction in unit test
We don't care about either the type or the name in this test, so just use
symbol_exprt::typeless(irep_idt()).
2019-02-05 19:37:34 +00:00
Thomas Spriggs 52e95a6920 Add try_dynamic_cast from rvalue to optional
This commit adds templates for `expr_try_dynamic_cast` and
`type_try_dynamic_cast` where the parameter is an rvalue and the return
type is an `optionalt`. This is implemented by moving the parameter into
the `optionalt`.

Included are unit tests of the new templates, which show that they
return the types and values expected. As well as tests and a static
assert for the existing overloads which show that they still return a
pointer.

These new templates are useful in the case where we are using the
result of a function, which returns by value but only in the case where
the value can be cast to a given type. For example with the new
overloads the following code can be written -
```
exprt enig();
void handle_struct_case(const struct_exprt &struct_expr);

void myFunction()
{
  if(const auto my_struct = expr_try_dynamic_cast<struct_exprt>(enig()))
    handle_struct_case(*my_struct);
}
```
However without the new templates and because the old ones do not bind
to rvalues, an additional temporary variable otherwise would have to be
declared -
```
void myFunction2()
{
  const exprt enigma = enig();
  if(const auto my_struct = expr_try_dynamic_cast<struct_exprt>(enigma))
    handle_struct_case(*my_struct);
}
```
2019-02-05 12:29:03 +00:00
Michael Tautschnig 69a3cc44a6
Merge pull request #3824 from tautschnig/remove-language_uit
Remove language_uit as it is no longer used
2019-02-04 19:17:29 +00:00
Michael Tautschnig 4adcfd8074
Merge pull request #3126 from diffblue/goto-instruction-function
remove goto_programt::instructiont::function member [blocks: #3113]
2019-02-04 17:16:52 +00:00
Michael Tautschnig 884266786d
Merge pull request #4044 from tautschnig/propt-message-handler
Require a message handler when constructing a propt [blocks: #3800]
2019-02-04 16:48:18 +00:00
Michael Tautschnig 04c337b8a9 Remove unnecessary language_ui.h includes
This isn't used, we use cbmc_parse_optionst here.
2019-02-04 16:38:21 +00:00
Daniel Kroening c9c872e267 remove goto_programt::instructiont::function member 2019-02-04 14:35:09 +00:00
Michael Tautschnig 4cb4bc9653 Cleanup use of messaget in unit tests
Constructing a messaget without a message handler is deprecated. Don't
unnecessarily include iostream, use a (null) message handler instead.
2019-02-03 20:47:19 +00:00
Michael Tautschnig 89641a2b47 Require a message handler when constructing a propt
Constructing a messaget without a message handler is deprecated.
2019-02-03 02:20:18 +00:00
Michael Tautschnig 82e08a7d27 A decision_proceduret does not need a namespace
This is a generic interface towards decisions procedures, there is no reason all
decision procedures should need a namespace.
2019-02-03 01:07:38 +00:00
Daniel Kroening c78f239a09 Fix binary represenation in XML generated from constant_exprt
We no longer use binary as bitvector representation, and thus, conversion
must happen.
2019-02-02 10:15:53 +00:00
Daniel Kroening 4dc7725e34 vector_typet::size() is now a constant_exprt
The codebase assumes basically globally that vector_typet::size() is a
constant_exprt.  This is now enforced by the signature.
2019-02-01 21:03:00 +00:00
Peter Schrammel c74d257a1d
Merge pull request #3968 from peterschrammel/cover-verifier
Add cover goals verifier [blocks: 3969]
2019-02-01 16:01:28 +00:00
Peter Schrammel 27e3efd70b Fix unit test dependencies 2019-02-01 14:13:00 +00:00
Fotis Koutoulakis f98cbed9e7 Add new join_strings function that applies a function to the elements of the container it flattens
and add tests for it.
2019-02-01 11:28:50 +00:00
Michael Tautschnig 1bba22fcb9 Unit test of byte operator lowering
The test attempts to systematically explore combinations of types, and shows a
number of current bugs or limitations.
2019-02-01 07:44:13 +00:00
Romain Brenguier f02417343f
Merge pull request #3977 from romainbrenguier/refactor/bdd-module
Add Cudd as an alternative for miniBDD
2019-02-01 07:33:56 +00:00
Romain Brenguier f1a1bb75d2 Add CUDD to CMake
CMake instructions to download Cudd when the CMAKE_USE_CUDD parameter is
set to true.
2019-02-01 06:48:55 +00:00
Romain Brenguier 488652f96a Unit test for bdd_expr
Add a couple of basic tests for bdd_expr, in order to check that there
is no obvious mistake in the use of BDDs from bdd_expr.
2019-02-01 06:48:51 +00:00
Romain Brenguier 68bfb0b79b Move miniBDD to a new bdd module
This will allow us to have several implementations of BDD among which we
choose at compile time.
2019-02-01 06:48:46 +00:00
Romain Brenguier 8e8d11fb7e Reformatting miniBDD unit test 2019-02-01 06:48:44 +00:00
Peter Schrammel 0ab57df179 Fix whitespace 2019-01-31 15:29:14 +00:00
Peter Schrammel 2fcc886e4c Move counterexample beautification to goto_checker
This is language-independent and can be used by
incremental goto checkers that provide traces.
2019-01-31 15:29:14 +00:00
Fotis Koutoulakis 14cfc086bd Copy constructor parameter instead of storing reference
Previously we stored a reference to the name_prefix parameter in
allocate objects that led to segfaults if it was constructed with
a temporary. Now we store a copy instead, which prevents that from
happening.
2019-01-31 11:02:49 +00:00
Michael Tautschnig 267094c7eb Replace all uses of deprecated symbol_exprt constructors
This helps type safety has it avoids constructing symbol_exprts that never get a
proper type (or identifier).
2019-01-29 18:23:23 +00:00