Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent object state #11

Draft
wants to merge 103 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
ffae884
Add DisjointSetUnion
dim8art Aug 20, 2023
850ae7f
Rework IndependentSolver using persistent DSU
dim8art Aug 20, 2023
15bd87d
Reworking ConcretizingSolver
dim8art Aug 20, 2023
3316cb0
Add persistency to Assignment
dim8art Aug 20, 2023
f72486f
Rework solver chain + small refactoring changes
dim8art Aug 20, 2023
9a96f85
[fix] Solvers performance fixes
Columpio Aug 15, 2023
7f5db38
[feat] Z3 Tree incremental solver
Columpio Sep 12, 2023
2428e2b
[feat] Improve `TargetCalculator`
misonijnik Sep 12, 2023
2d8e12b
[refactor] `CodeGraphDistance` -> `CodeGraphInfo`
misonijnik Sep 14, 2023
4486529
[feat] Improve `only-output-states-covering-new` option
misonijnik Sep 15, 2023
d3344b5
[feat] Add `cover-on-the-fly` option
misonijnik Sep 16, 2023
8d69a9f
[fix] Make `isReachedTarget` consistent with `reportTruePositive`
misonijnik Sep 18, 2023
fcfef9d
Created shadow copy of errno in 32bit space to work with 32bit programs.
S1eGa Aug 18, 2023
0a16747
Added building of uClibc for 32 and 64-bit archs.
S1eGa Aug 21, 2023
12c647a
[feat] tc support
S1eGa Jul 25, 2023
97cd057
[fix] float and double symbolics
S1eGa Jul 27, 2023
c54358b
[fix] z3-tree with 0 size pool
Columpio Sep 21, 2023
dff6af1
[refactor] Use `bit_suffix` explicit
misonijnik Sep 21, 2023
e1a57bb
[fix] Fix a few bugs
misonijnik Sep 20, 2023
026da46
[fix] Make the tests independent of default search strategies
misonijnik Sep 21, 2023
aa7528b
[fix] Incremental DT with no frames
Columpio Sep 26, 2023
8de31b5
[fix] Improve `IndependentConstraintSetUnion`
misonijnik Sep 22, 2023
847ed62
[feat] Add optimization in case all constraints are dependent
misonijnik Sep 25, 2023
3fae575
[fix] Rebuild constraint dsu after constraints simplification
misonijnik Sep 29, 2023
a0bb3ca
[fix] Fix MemorySubobject warning
misonijnik Sep 27, 2023
390866f
[fix] Fix `CachingSolver`
misonijnik Sep 27, 2023
f5f7574
[fix] Tests for states with mocks
Columpio Oct 2, 2023
37f0da6
Memory optimize, remove InstructionInfoTable, add immutable list for …
ladisgin Aug 15, 2023
90e8cbf
[feat] uint128
Columpio Oct 4, 2023
27b6ed1
[chore] Optimized KBlock mem
Columpio Oct 5, 2023
2dc5efa
[fix] Error testcase processing doesn't affect `coveredNew`
misonijnik Oct 5, 2023
16155cd
[fix] Fix `computeValidity` in partial response case
misonijnik Oct 5, 2023
c934eb7
[chore] Disable test
misonijnik Oct 5, 2023
4ac9163
[chore] Add a test
misonijnik Oct 5, 2023
532bcff
[chore] Add an option to disable loop deletion pass
misonijnik Oct 5, 2023
8798ea5
[fix] Fix stats
misonijnik Oct 5, 2023
d5095be
[feat] Differentiate `isCoveredNew` and `isCoveredNewError`
misonijnik Oct 6, 2023
c9c1419
[chore] Z3 is not required in a lot of tests, so remove the requirements
misonijnik Oct 6, 2023
f1e8720
[feat] Improved Iterative Deepening Searcher
Columpio Oct 10, 2023
ca88a99
[fix] Fixed inner types for unnamed structs.
S1eGa Oct 12, 2023
2171ce3
[feat] Separate branch and block coverage
misonijnik Sep 22, 2023
d0e280b
[chore] Update build.sh
misonijnik Oct 16, 2023
cdc1f7f
[feat] Prefer a smaller integer vaule in a model
misonijnik Oct 16, 2023
bfaabef
[chore] Optimized IterativeDeepeningSearcher
Columpio Oct 20, 2023
febf79d
[chore] Optimized getDistance
Columpio Oct 20, 2023
4d9ad3e
[chore] Strip llvm.dbg.declare
Columpio Oct 20, 2023
d5ff4df
[fix] Compare exprs by height in simplifier
ocelaiwo Oct 20, 2023
c3553c0
[feat] Uninitialized Memory [feat] Sizeless ObjectState
ocelaiwo Oct 17, 2023
6408e41
[chore] Disable test
misonijnik Oct 21, 2023
c70df43
[fix] Fix performance bugs
misonijnik Oct 22, 2023
341510c
[fix] Change satisfies function in InvalidReponse
dim8art Oct 21, 2023
c4f7c5c
Change CacheEntry to store constraints_ty
dim8art Oct 21, 2023
001f9ef
Create AlphaEquvalenceSolver
dim8art Oct 21, 2023
8529980
[fix] Propagation of without filter
Columpio Oct 23, 2023
ecfca38
[fix] Small fixes
Columpio Oct 23, 2023
8991cbc
[fix] Generate test only for successful solution found
misonijnik Oct 24, 2023
0583657
[chore] Deal with compiler warnings
Columpio Oct 24, 2023
d8ff87b
[feat] Cover on the fly based on time
Columpio Oct 24, 2023
d74463a
[fix] rewriting ordering for terms with equal height
Columpio Oct 24, 2023
b4fbe6d
[fix] Update test
misonijnik Oct 24, 2023
6569119
[feat] Removed unwanted calls pass
Columpio Oct 25, 2023
1e08227
[fix] Filter objects and values in `changeVersion`
misonijnik Oct 25, 2023
200db1d
[fix] Clean memory operations
misonijnik Oct 26, 2023
0cb981d
[fix] Fix `AlphaEquivalenceSolver`
misonijnik Oct 27, 2023
0a80185
[fix] Halt when LLVM passes already proved unreachability
Columpio Oct 27, 2023
803fabc
[chore] Update version and `README.md`
misonijnik Oct 30, 2023
8865af3
[fix] Improved call remover
Columpio Oct 31, 2023
06bfbc0
[feat] Add `OptimizeAggressive` option
misonijnik Nov 1, 2023
1a472d9
[feat] Getting the performance/memory consumption balance in `Disjoin…
misonijnik Nov 2, 2023
f14b8ac
[fix] Fix performance for unbalanced expressions
misonijnik Nov 2, 2023
1689ece
[refactor] Separate `isStuck` and `isCycled`, `isStuck` is smarter now
misonijnik Nov 2, 2023
ab185fe
[fix] Limit the cexPreferences size
misonijnik Nov 2, 2023
fa0c7b6
[fix] Remove unused field
misonijnik Nov 2, 2023
7c002e7
[fix] Fix memory consumption
misonijnik Nov 2, 2023
1b1e789
[feat] Enable `coverOnTheFly` after approaching memory cup
misonijnik Nov 2, 2023
2872586
[style]
misonijnik Nov 2, 2023
8b91d6a
[fix] Consider all not empty and not fully covered functions
misonijnik Nov 3, 2023
01ddb65
[fix] Fix perfomance bug
misonijnik Nov 3, 2023
9f054a9
[fix] Fix `isStuck`
misonijnik Nov 3, 2023
2477ed7
[fix] klee-test-comp.c
Columpio Nov 3, 2023
0cf7c49
[feat] Single-file run script
Columpio Nov 3, 2023
3b81fd8
[chore] Updated README
Columpio Nov 7, 2023
984f5e6
[feat] Improve coverage branches tests
misonijnik Nov 5, 2023
c57d898
[fix] `CexCachingSolver`
misonijnik Nov 6, 2023
16d8098
[fix] Slightly improve performance
misonijnik Nov 5, 2023
b394cb3
[fix] `AlphaEquivalenceSolver`
misonijnik Nov 7, 2023
14b89d4
[feat] Add `X86FPAsX87FP80`
misonijnik Nov 7, 2023
ee3b200
[chore] Update `scripts/kleef`
misonijnik Nov 7, 2023
ccf75c6
[chore] Disable `libc++` tests on msan run because they time out on CI
misonijnik Nov 8, 2023
08d24ad
[fix] Must consider the whole concretization
misonijnik Nov 8, 2023
2677745
[chore] Update `kleef` script
misonijnik Nov 10, 2023
82b0cfd
[chore] Update tests
misonijnik Nov 10, 2023
00770eb
[fix] `MemoryTriggerCoverOnTheFly`
misonijnik Nov 12, 2023
22dadeb
[chore] Update `kleef`
misonijnik Nov 12, 2023
5f27906
[fix] Optimized free-standing functions are broken
misonijnik Nov 13, 2023
a8bbfb5
[chore] Update `kleef` script
misonijnik Nov 10, 2023
b2d233c
[fix] Address may be symbolic but unique, try resolve firstly
misonijnik Nov 14, 2023
2b513ac
[fix] Put in order `fp-runtime` functions
misonijnik Nov 14, 2023
c1648ab
[fix] Bring calls to `SparseStorage` constructor up to date
misonijnik Nov 15, 2023
44f64ed
[experiment] SparseStorage persistent on threshold
ocelaiwo Nov 21, 2023
6459807
[] start CI
ocelaiwo Nov 21, 2023
312ff29
[fix]
ocelaiwo Nov 21, 2023
c91e602
[fix] Don't persist constant objects + test always persist
ocelaiwo Nov 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: CI

on:
pull_request:
branches: [main, utbot-main]
branches: [persistent_object_state]
push:
branches: [main, utbot-main]
branches: [persistent_object_state]

# Defaults for building KLEE
env:
Expand Down
38 changes: 27 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ project(KLEE CXX C)
# Project version
###############################################################################
set(KLEE_VERSION_MAJOR 3)
set(KLEE_VERSION_MINOR 0-utbot)
set(KLEE_VERSION_MINOR 0)
set(KLEE_VERSION "${KLEE_VERSION_MAJOR}.${KLEE_VERSION_MINOR}")

# If a patch is needed, we can add KLEE_VERSION_PATCH
# set(KLEE_VERSION_PATCH 0)
# set(KLEE_VERSION "${KLEE_VERSION_MAJOR}.${KLEE_VERSION_MINOR}.${KLEE_VERSION_PATCH}")

message(STATUS "KLEE version ${KLEE_VERSION}")
set(PACKAGE_STRING "\"KLEE ${KLEE_VERSION}\"")
set(PACKAGE_URL "\"https://klee.github.io\"")
message(STATUS "KLEEF version ${KLEE_VERSION}")
set(PACKAGE_STRING "\"KLEEF ${KLEE_VERSION}\"")
set(PACKAGE_URL "\"https://toolchain-labs.com/projects/kleef.html\"")

################################################################################
# Sanity check - Disallow building in source.
Expand Down Expand Up @@ -506,19 +506,29 @@ endif()
# KLEE uclibc support
################################################################################
set(KLEE_UCLIBC_PATH "" CACHE PATH "Path to klee-uclibc root directory")
set(KLEE_UCLIBC_BCA_NAME "klee-uclibc.bca")

set(KLEE_UCLIBC_BCA_32_NAME "klee-uclibc-32.bca")
set(KLEE_UCLIBC_BCA_64_NAME "klee-uclibc-64.bca")

if (NOT KLEE_UCLIBC_PATH STREQUAL "")
# Find the C library bitcode archive
set(KLEE_UCLIBC_C_BCA "${KLEE_UCLIBC_PATH}/lib/libc.a")
if (NOT EXISTS "${KLEE_UCLIBC_C_BCA}")
set(KLEE_UCLIBC_C_32_BCA "${KLEE_UCLIBC_PATH}-32/lib/libc.a")
set(KLEE_UCLIBC_C_64_BCA "${KLEE_UCLIBC_PATH}-64/lib/libc.a")

if (NOT EXISTS "${KLEE_UCLIBC_C_32_BCA}" OR NOT EXISTS "${KLEE_UCLIBC_C_64_BCA}")
message(FATAL_ERROR
"klee-uclibc library not found at \"${KLEE_UCLIBC_C_BCA}\". Set KLEE_UCLIBC_PATH to klee-uclibc root directory or empty string.")
"klee-uclibc library not found at \"${KLEE_UCLIBC_C_32_BCA}\" or \"${KLEE_UCLIBC_C_64_BCA}\". Set KLEE_UCLIBC_PATH to klee-uclibc root directory or empty string.")
endif()
message(STATUS "Found klee-uclibc library: \"${KLEE_UCLIBC_C_BCA}\"")
message(STATUS "Found klee-uclibc library: \"${KLEE_UCLIBC_C_32_BCA}\" and \"${KLEE_UCLIBC_C_64_BCA}\"")
# Copy KLEE_UCLIBC_C_BCA so KLEE can find it where it is expected.
# Create 32 and 64 bit versions
execute_process(COMMAND ${CMAKE_COMMAND} -E copy
"${KLEE_UCLIBC_C_32_BCA}"
"${KLEE_RUNTIME_DIRECTORY}/${KLEE_UCLIBC_BCA_32_NAME}"
)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy
"${KLEE_UCLIBC_C_BCA}"
"${KLEE_RUNTIME_DIRECTORY}/${KLEE_UCLIBC_BCA_NAME}"
"${KLEE_UCLIBC_C_64_BCA}"
"${KLEE_RUNTIME_DIRECTORY}/${KLEE_UCLIBC_BCA_64_NAME}"
)
else()
message(STATUS "Skipping copying of klee-uclibc runtime")
Expand Down Expand Up @@ -633,6 +643,12 @@ unset(_flags)
configure_file(${CMAKE_SOURCE_DIR}/include/klee/Config/config.h.cmin
${CMAKE_BINARY_DIR}/include/klee/Config/config.h)

################################################################################
# Generate `klee/klee.h` and `klee-test-comp.c`
################################################################################
configure_file(${CMAKE_SOURCE_DIR}/include/klee/klee.h ${CMAKE_BINARY_DIR}/include/klee/klee.h COPYONLY)
configure_file(${CMAKE_SOURCE_DIR}/include/klee-test-comp.c ${CMAKE_BINARY_DIR}/include/klee-test-comp.c COPYONLY)

################################################################################
# Generate `CompileTimeInfo.h`
################################################################################
Expand Down
28 changes: 5 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
KLEE Symbolic Virtual Machine
KLEEF Symbolic Virtual Machine
=============================

[![Build Status](https://github.com/klee/klee/workflows/CI/badge.svg)](https://github.com/klee/klee/actions?query=workflow%3ACI)
[![Build Status](https://api.cirrus-ci.com/github/klee/klee.svg)](https://cirrus-ci.com/github/klee/klee)
[![Coverage](https://codecov.io/gh/klee/klee/branch/master/graph/badge.svg)](https://codecov.io/gh/klee/klee)
[![Build Status](https://github.com/UnitTestBot/klee/workflows/CI/badge.svg)](https://github.com/UnitTestBot/klee/actions?query=workflow%3ACI)
[![Coverage](https://codecov.io/gh/UnitTestBot/klee/branch/main/graph/badge.svg)](https://codecov.io/gh/UnitTestBot/klee)

`KLEE` is a symbolic virtual machine built on top of the LLVM compiler
infrastructure. Currently, there are two primary components:
`KLEEF` is a complete overhaul of the KLEE symbolic execution engine for LLVM, fine-tuned for a robust analysis of industrial C/C++ code.

1. The core symbolic virtual machine engine; this is responsible for
executing LLVM bitcode modules with support for symbolic
values. This is comprised of the code in lib/.

2. A POSIX/Linux emulation layer oriented towards supporting uClibc,
with additional support for making parts of the operating system
environment symbolic.

Additionally, there is a simple library for replaying computed inputs
on native code (for closed programs). There is also a more complicated
infrastructure for replaying the inputs generated for the POSIX/Linux
emulation layer, which handles running native programs in an
environment that matches a computed test input, including setting up
files, pipes, environment variables, and passing command line
arguments.

For further information, see the [webpage](http://klee.github.io/).
For further information, see the [webpage](https://toolchain-labs.com/projects/kleef.html).
4 changes: 2 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ SQLITE_VERSION="3400100"
## LLVM Required options
LLVM_VERSION=14
ENABLE_OPTIMIZED=1
ENABLE_DEBUG=1
ENABLE_DEBUG=0
DISABLE_ASSERTIONS=1
REQUIRES_RTTI=1
REQUIRES_RTTI=0

## Solvers Required options
# SOLVERS=STP
Expand Down
17 changes: 14 additions & 3 deletions include/klee-test-comp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,42 @@
//
//===----------------------------------------------------------------------===//

#include <stdint.h>
#ifdef EXTERNAL
#include "klee.h"
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#else
void klee_make_symbolic(void *addr, unsigned int nbytes, const char *name);
void klee_assume(_Bool condition);
__attribute__((noreturn)) void klee_silent_exit(int status);
void __assert_fail(const char *assertion, const char *file, unsigned int line,
const char *function);
void klee_prefer_cex(void *, uintptr_t);
#endif

int __VERIFIER_nondet_int(void) {
int x;
klee_make_symbolic(&x, sizeof(x), "int");
klee_prefer_cex(&x, x < 1024);
return x;
}

unsigned int __VERIFIER_nondet_uint(void) {
unsigned int x;
klee_make_symbolic(&x, sizeof(x), "unsigned int");
klee_prefer_cex(&x, x < 1024);
return x;
}

#ifdef __x86_64__
unsigned __int128 __VERIFIER_nondet_uint128(void) {
unsigned __int128 x;
klee_make_symbolic(&x, sizeof(x), "unsigned __int128");
return x;
}
#endif

unsigned __VERIFIER_nondet_unsigned(void) {
unsigned x;
Expand Down Expand Up @@ -82,7 +93,7 @@ unsigned long __VERIFIER_nondet_ulong(void) {
}

double __VERIFIER_nondet_double(void) {
long x;
double x;
klee_make_symbolic(&x, sizeof(x), "double");
return x;
}
Expand All @@ -96,7 +107,7 @@ void *__VERIFIER_nondet_pointer(void) {
}

float __VERIFIER_nondet_float(void) {
int x;
float x;
klee_make_symbolic(&x, sizeof(x), "float");
return x;
}
Expand Down
172 changes: 172 additions & 0 deletions include/klee/ADT/DisjointSetUnion.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
#ifndef KLEE_DISJOINEDSETUNION_H
#define KLEE_DISJOINEDSETUNION_H

#include "klee/ADT/Either.h"
#include "klee/ADT/PersistentMap.h"
#include "klee/ADT/PersistentSet.h"
#include "klee/ADT/Ref.h"
#include "klee/Expr/Expr.h"
#include "klee/Expr/Symcrete.h"

#include "klee/Support/CompilerWarning.h"
DISABLE_WARNING_PUSH
DISABLE_WARNING_DEPRECATED_DECLARATIONS
#include "llvm/Support/raw_ostream.h"
DISABLE_WARNING_POP

#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace klee {
using ExprEitherSymcrete = either<Expr, Symcrete>;

template <typename ValueType, typename SetType,
typename HASH = std::hash<ValueType>,
typename PRED = std::equal_to<ValueType>,
typename CMP = std::less<ValueType>>
class DisjointSetUnion {
public:
using internal_storage_ty = std::unordered_set<ValueType, HASH, PRED>;
using disjoint_sets_ty =
std::unordered_map<ValueType, ref<const SetType>, HASH, PRED>;
using iterator = typename internal_storage_ty::iterator;

protected:
std::unordered_map<ValueType, ValueType, HASH, PRED> parent;
std::set<ValueType, CMP> roots;
std::unordered_map<ValueType, size_t, HASH, PRED> rank;

std::unordered_set<ValueType, HASH, PRED> internalStorage;
std::unordered_map<ValueType, ref<const SetType>, HASH, PRED> disjointSets;

ValueType find(const ValueType &v) { // findparent
assert(parent.find(v) != parent.end());
if (v == parent.at(v))
return v;
parent.insert_or_assign(v, find(parent.at(v)));
return parent.at(v);
}

ValueType constFind(const ValueType &v) const {
assert(parent.find(v) != parent.end());
ValueType v1 = parent.at(v);
if (v == v1)
return v;
return constFind(v1);
}

void merge(ValueType a, ValueType b) {
a = find(a);
b = find(b);
if (a == b) {
return;
}

if (rank.at(a) < rank.at(b)) {
std::swap(a, b);
}
parent.insert_or_assign(b, a);
if (rank.at(a) == rank.at(b)) {
rank.insert_or_assign(a, rank.at(a) + 1);
}

roots.erase(b);
disjointSets.insert_or_assign(
a, SetType::merge(disjointSets.at(a), disjointSets.at(b)));
disjointSets.erase(b);
}

bool areJoined(const ValueType &i, const ValueType &j) const {
return constFind(i) == constFind(j);
}

public:
iterator begin() const { return internalStorage.begin(); }
iterator end() const { return internalStorage.end(); }

size_t numberOfValues() const noexcept { return internalStorage.size(); }

size_t numberOfGroups() const noexcept { return disjointSets.size(); }

bool empty() const noexcept { return numberOfValues() == 0; }

ref<const SetType> findGroup(const ValueType &i) const {
return disjointSets.find(constFind(i))->second;
}

ref<const SetType> findGroup(iterator it) const {
return disjointSets.find(constFind(*it))->second;
}

void addValue(const ValueType value) {
if (internalStorage.find(value) != internalStorage.end()) {
return;
}
parent.insert({value, value});
roots.insert(value);
rank.insert({value, 0});
disjointSets.insert({value, new SetType(value)});

internalStorage.insert(value);
std::set<ValueType, CMP> oldRoots = roots;
for (ValueType v : oldRoots) {
if (!areJoined(v, value) &&
SetType::intersects(disjointSets.at(find(v)),
disjointSets.at(find(value)))) {
merge(v, value);
}
}
}
void getAllIndependentSets(std::vector<ref<const SetType>> &result) const {
for (ValueType v : roots)
result.push_back(findGroup(v));
}

void add(const DisjointSetUnion &b) {
std::set<ValueType, CMP> oldRoots = roots;
std::set<ValueType, CMP> newRoots = b.roots;
for (auto it : b.parent) {
parent.insert(it);
}
for (auto it : b.roots) {
roots.insert(it);
}
for (auto it : b.rank) {
rank.insert(it);
}
for (auto it : b.internalStorage) {
internalStorage.insert(it);
}
for (auto it : b.disjointSets) {
disjointSets.insert(it);
}
for (ValueType nv : newRoots) {
for (ValueType ov : oldRoots) {
if (!areJoined(ov, nv) &&
SetType::intersects(disjointSets.at(find(ov)),
disjointSets.at(find(nv)))) {
merge(ov, nv);
}
}
}
}

DisjointSetUnion() {}

DisjointSetUnion(const internal_storage_ty &is) {
for (ValueType v : is) {
addValue(v);
}
}

public:
internal_storage_ty is() const { return internalStorage; }

disjoint_sets_ty ds() const { return disjointSets; }
};
} // namespace klee

#endif /* KLEE_DISJOINEDSETUNION_H */
Loading