Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fce69b8
[fix] Evaluate only one branch corresponding to the evaluated condition
misonijnik Jun 27, 2023
d0aa951
[fix] Replace multiset with a set
misonijnik Jun 27, 2023
e55ed7d
[fix] Fix tricky independence related bug: `ConcretizingSolver` shoul…
misonijnik Jun 27, 2023
ee47874
[fix] Symbolic size needs to be evaluated
misonijnik Jun 27, 2023
43caa96
[chore] A few minor fixes
misonijnik Jun 27, 2023
5e1872b
[fix] Separate code related to error guided mode
misonijnik Jun 27, 2023
75ec56f
[feat] Improve `SelectExpr` simplification [feat] Consider full symbo…
misonijnik Jun 27, 2023
e525407
[fix] Rework resolution related functions
misonijnik Jun 27, 2023
1c67fa3
[fix] Collect full assigment for logging `computeInitialValues`
misonijnik Jun 22, 2023
8e88097
Factor out distance calculations for searchers in DistanceCalculator
May 22, 2023
6ac696c
[chore] Add an easy to use build script
misonijnik Jun 27, 2023
0d93dc6
[chore] Add `options.json` file
misonijnik Jun 27, 2023
e40996f
[feat] Add Cooddy report parser
misonijnik Jun 8, 2023
ad9c928
[feat] Target progress report
Columpio Jun 22, 2023
20e8e1d
[fix] Fixed 0 weight for targets on the same frame
Columpio Jun 27, 2023
6f77fef
[test] Added report tests
Columpio Jun 27, 2023
a4af7bf
[feat] Added targets to fork
Columpio Jun 21, 2023
0f2dd85
[feat] Not calling solver if target is unreachable
Columpio Jun 21, 2023
1d90d4b
[test] Added reach fork opt. test
Columpio Jun 27, 2023
0fbec00
[fix] Small fixes
Columpio Jun 29, 2023
c7ed0e9
[chore] Make analysis results generation options independent of test …
misonijnik Jun 30, 2023
c6299c8
[fix] `ExprPPrinter`
misonijnik Jun 28, 2023
8f1a95d
[fix] Add a few fixes
misonijnik Jun 30, 2023
f4e77c1
[fix] Revert `getLabel`: this function should not return anything oth…
misonijnik Jun 30, 2023
9c8e608
[feat] Add new test
misonijnik Jun 30, 2023
caa57ff
[fix] Fix `strcmp` model
misonijnik Jul 1, 2023
77b5edf
[chore] Add new test for 'write-kpaths'
misonijnik Jul 4, 2023
721f4fb
[fix] Add `History::size()`
misonijnik Jun 30, 2023
027f212
[feat] Update expressions building and simplifying
misonijnik Jun 30, 2023
9690f62
[fix] Report `MissedAllTargets` states
misonijnik Jul 3, 2023
152d6bf
[feat] Add `LazyInitCat` and some their options
misonijnik Jul 3, 2023
fd87c86
[chore] Update `options.json`
misonijnik Jul 3, 2023
90c6307
[fix] Use getWrtiable only with writes
ocelaiwo Jul 3, 2023
c6a1b96
[chore] Update `MemoryLimit.c`
misonijnik Jul 3, 2023
9a9cf2d
[style] Fix typo
misonijnik Jul 4, 2023
3f1bbcc
[feat] Add `TargetManager`
misonijnik Jul 14, 2023
957bc6f
[fix] Create a whole symbolic array for `MockMutableGlobalsPolicy::All`
misonijnik Jul 14, 2023
8c51eec
[clean] Remove `ConcretizationManager` as unnecessary
misonijnik Jul 14, 2023
a40fed1
[fix] Update tests
misonijnik Jul 14, 2023
8319e6b
[refactor] Replace `stack_ty`
misonijnik Jul 14, 2023
6d78dc0
[reafctor] Refine the target's system
misonijnik Jul 16, 2023
6fd7ab9
[refactor] Add `computeConcretization`
misonijnik Jul 17, 2023
63778b2
[fixup] Replace `stack_ty`
misonijnik Jul 17, 2023
dbafb8a
[fixup] Add `TargetManager`
misonijnik Jul 17, 2023
faebfae
save
ocelaiwo Jul 17, 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
86 changes: 51 additions & 35 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,51 @@
#!/bin/bash
# This script is used to build KLEE as UTBot backend

set -e
set -o pipefail
mkdir -p build
cd build

$UTBOT_CMAKE_BINARY -G Ninja \
-DCMAKE_PREFIX_PATH=$UTBOT_INSTALL_DIR/lib/cmake/z3 \
-DCMAKE_LIBRARY_PATH=$UTBOT_INSTALL_DIR/lib \
-DCMAKE_INCLUDE_PATH=$UTBOT_INSTALL_DIR/include \
-DENABLE_SOLVER_Z3=TRUE \
-DENABLE_POSIX_RUNTIME=TRUE \
-DENABLE_KLEE_UCLIBC=ON \
-DKLEE_UCLIBC_PATH=$UTBOT_ALL/klee-uclibc \
-DENABLE_FLOATING_POINT=TRUE \
-DENABLE_FP_RUNTIME=TRUE \
-DLLVM_CONFIG_BINARY=$UTBOT_INSTALL_DIR/bin/llvm-config \
-DLLVMCC=/utbot_distr/install/bin/clang \
-DLLVMCXX=/utbot_distr/install/bin/clang++ \
-DENABLE_UNIT_TESTS=TRUE \
-DENABLE_SYSTEM_TESTS=TRUE \
-DGTEST_SRC_DIR=$UTBOT_ALL/gtest \
-DGTEST_INCLUDE_DIR=$UTBOT_ALL/gtest/googletest/include \
-DCMAKE_INSTALL_PREFIX=$UTBOT_ALL/klee \
-DENABLE_KLEE_LIBCXX=TRUE \
-DKLEE_LIBCXX_DIR=$UTBOT_ALL/libcxx/install \
-DKLEE_LIBCXX_INCLUDE_DIR=$UTBOT_ALL/libcxx/install/include/c++/v1 \
-DENABLE_KLEE_EH_CXX=TRUE \
-DKLEE_LIBCXXABI_SRC_DIR=$UTBOT_ALL/libcxx/libcxxabi \
..

$UTBOT_CMAKE_BINARY --build .
$UTBOT_CMAKE_BINARY --install .
#!/bin/sh

# For more build options, visit
# https://klee.github.io/build-script/

# Base folder where dependencies and KLEE itself are installed
BASE=$HOME/klee_build

## KLEE Required options
# Build type for KLEE. The options are:
# Release
# Release+Debug
# Release+Asserts
# Release+Debug+Asserts
# Debug
# Debug+Asserts
# KLEE_RUNTIME_BUILD="Debug+Asserts"
KLEE_RUNTIME_BUILD="Debug" # "Debug+Asserts"

COVERAGE=0
ENABLE_DOXYGEN=0
USE_TCMALLOC=0
USE_LIBCXX=1
# Also required despite not being mentioned in the guide
SQLITE_VERSION="3370200"


## LLVM Required options
LLVM_VERSION=11
ENABLE_OPTIMIZED=1
ENABLE_DEBUG=0
DISABLE_ASSERTIONS=1
REQUIRES_RTTI=1

## Solvers Required options
# SOLVERS=STP
SOLVERS=Z3

## Google Test Required options
GTEST_VERSION=1.11.0

## UClibC Required options
UCLIBC_VERSION=klee_0_9_29
# LLVM_VERSION is also required for UClibC

## Z3 Required options
Z3_VERSION=4.8.15
STP_VERSION=2.3.3
MINISAT_VERSION=master

BASE="$BASE" KLEE_RUNTIME_BUILD=$KLEE_RUNTIME_BUILD COVERAGE=$COVERAGE ENABLE_DOXYGEN=$ENABLE_DOXYGEN USE_TCMALLOC=$USE_TCMALLOC USE_LIBCXX=$USE_LIBCXX LLVM_VERSION=$LLVM_VERSION ENABLE_OPTIMIZED=$ENABLE_OPTIMIZED ENABLE_DEBUG=$ENABLE_DEBUG DISABLE_ASSERTIONS=$DISABLE_ASSERTIONS REQUIRES_RTTI=$REQUIRES_RTTI SOLVERS=$SOLVERS GTEST_VERSION=$GTEST_VERSION UCLIBC_VERSION=$UCLIBC_VERSION STP_VERSION=$STP_VERSION MINISAT_VERSION=$MINISAT_VERSION Z3_VERSION=$Z3_VERSION SQLITE_VERSION=$SQLITE_VERSION ./scripts/build/build.sh klee --install-system-deps
52 changes: 52 additions & 0 deletions configs/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"inputs" : {
"buildPath" : "",
"sarifTracesFilePath" : ".json",
"bytecodeFilePath" : ".bc",
"maxTime" : "240",
"maxSolverTime" : "5",
"maxForks" : "200",
"maxSymAlloc" : "32",
"SymbolicAllocationThreshold" : "2048",
"minNumberElements" : "4",
"maxCycles" : 10,
"useSymbolicSizeLI" : false,
"writeKpaths": false
},
"configurations": [
{
"program": "${buildPath}/bin/klee",
"args": [
"--use-guided-search=error",
"--mock-external-calls",
"--posix-runtime",
"--check-out-of-memory",
"--suppress-external-warnings",
"--libc=klee",
"--skip-not-lazy-initialized",
"--external-calls=all",
"--output-source=false",
"--output-istats=false",
"--output-stats=false",
"--max-time=${maxTime}s",
"--max-sym-alloc=${maxSymAlloc}",
"--max-forks=${maxForks}",
"--max-solver-time=${maxSolverTime}s",
"--mock-all-externals",
"--smart-resolve-entry-function",
"--extern-calls-can-return-null",
"--align-symbolic-pointers=false",
"--write-no-tests",
"--write-kpaths=${writeKpaths}",
"--use-lazy-initialization=only",
"--min-number-elements-li=${minNumberElements}",
"--use-sym-size-li=${useSymbolicSizeLI}",
"--max-cycles-before-stuck=${maxCycles}",
"--rewrite-equalities=simple",
"--symbolic-allocation-threshold=${SymbolicAllocationThreshold}",
"--analysis-reproduce=${sarifTracesFilePath}",
"${bytecodeFilePath}"
]
}
]
}
33 changes: 33 additions & 0 deletions include/klee/ADT/Ticker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// -*- C++ -*-
#ifndef KLEE_TICKER_H
#define KLEE_TICKER_H

#include <vector>

class Ticker {
std::vector<unsigned> ticks;
unsigned index = 0;
unsigned counter = 0;

public:
Ticker(std::vector<unsigned> ticks) : ticks(ticks) {}

unsigned getCurrent() {
unsigned current = index;
counter += 1;
if (counter == ticks[index]) {
index = (index + 1) % ticks.size();
counter = 0;
}
return current;
}

void moveToNext() {
if (counter != 0) {
index = (index + 1) % ticks.size();
counter = 0;
}
}
};

#endif
10 changes: 8 additions & 2 deletions include/klee/Core/Interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ class InterpreterHandler {

virtual void incPathsCompleted() = 0;
virtual void incPathsExplored(std::uint32_t num = 1) = 0;
virtual void incSummarizedLocations() = 0;

virtual void processTestCase(const ExecutionState &state, const char *err,
const char *suffix) = 0;
virtual void processTestCase(const ExecutionState &state, const char *message,
const char *suffix, bool isError = false) = 0;
};

enum class ExecutionKind {
Forward,
Bidirectional
};

class Interpreter {
Expand Down
2 changes: 1 addition & 1 deletion include/klee/Core/TargetedExecutionReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ty min(ty left, ty right);
}; // namespace confidence

void reportFalsePositive(confidence::ty confidence,
const std::set<ReachWithError> &errors, unsigned id,
const std::vector<ReachWithError> &errors, unsigned id,
std::string whatToIncrease);

} // namespace klee
Expand Down
7 changes: 5 additions & 2 deletions include/klee/Core/TerminationTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
TTYPE(MaxDepth, 3U, "early") \
TTYPE(OutOfMemory, 4U, "early") \
TTYPE(OutOfStackMemory, 5U, "early") \
MARK(EARLY, 5U) \
TTYPE(MaxCycles, 6U, "early") \
TTYPE(MissedAllTargets, 7U, "miss_all_targets.early") \
MARK(EARLY, 7U) \
TTYPE(Solver, 8U, "solver.err") \
MARK(SOLVERERR, 8U) \
TTYPE(Abort, 10U, "abort.err") \
Expand All @@ -33,7 +35,7 @@
TTYPE(ReadOnly, 17U, "read_only.err") \
TTYPE(ReportError, 18U, "report_error.err") \
TTYPE(UndefinedBehavior, 19U, "undefined_behavior.err") \
TTYPE(InternalOutOfMemory, 20U, "out_of_memory.er") \
TTYPE(InternalOutOfMemory, 20U, "out_of_memory.err") \
MARK(PROGERR, 20U) \
TTYPE(User, 23U, "user.err") \
MARK(USERERR, 23U) \
Expand All @@ -60,6 +62,7 @@ enum Reason {
MaxInstructions,
MaxSteppedInstructions,
MaxTime,
MaxCycles,
CovCheck,
NoMoreStates,
ReachedTarget,
Expand Down
1 change: 1 addition & 0 deletions include/klee/Expr/Assignment.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Assignment {

bindings_ty::const_iterator begin() const { return bindings.begin(); }
bindings_ty::const_iterator end() const { return bindings.end(); }
bool isEmpty() { return begin() == end(); }

std::vector<const Array *> keys() const;
std::vector<SparseStorage<unsigned char>> values() const;
Expand Down
9 changes: 5 additions & 4 deletions include/klee/Expr/Constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class ConstraintSet {

class PathConstraints {
public:
using ordered_constraints_ty =
std::map<Path::PathIndex, constraints_ty, Path::PathIndexCompare>;
using ordered_constraints_ty = std::vector<ref<Expr>>;
using path_ordered_constraints_ty =
std::map<Path::PathIndex, ordered_constraints_ty, Path::PathIndexCompare>;

void advancePath(KInstruction *ki);
void advancePath(const Path &path);
Expand All @@ -90,7 +91,7 @@ class PathConstraints {
const ConstraintSet &cs() const;
const Path &path() const;
const ExprHashMap<Path::PathIndex> &indexes() const;
const ordered_constraints_ty &orderedCS() const;
const path_ordered_constraints_ty &orderedCS() const;

static PathConstraints concat(const PathConstraints &l,
const PathConstraints &r);
Expand All @@ -100,7 +101,7 @@ class PathConstraints {
constraints_ty _original;
ConstraintSet constraints;
ExprHashMap<Path::PathIndex> pathIndexes;
ordered_constraints_ty orderedConstraints;
path_ordered_constraints_ty orderedConstraints;
ExprHashMap<ExprHashSet> _simplificationMap;
};

Expand Down
13 changes: 11 additions & 2 deletions include/klee/Expr/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class Expr {
};

static ExprCacheSet cachedExpressions;
static ref<Expr> createCachedExpr(const ref<Expr> &e);
static ref<Expr> createCachedExpr(ref<Expr> e);
bool isCached = false;
bool toBeCleared = false;

Expand Down Expand Up @@ -321,6 +321,9 @@ class Expr {
/// isZero - Is this a constant zero.
bool isZero() const;

/// isZero - Is this a constant one.
bool isOne() const;

/// isTrue - Is this the true expression.
bool isTrue() const;

Expand Down Expand Up @@ -391,7 +394,7 @@ struct Expr::CreateArg {
// Comparison operators

inline bool operator==(const Expr &lhs, const Expr &rhs) {
return lhs.compare(rhs) == 0;
return lhs.equals(rhs);
}

inline bool operator<(const Expr &lhs, const Expr &rhs) {
Expand Down Expand Up @@ -1553,6 +1556,12 @@ inline bool Expr::isZero() const {
return false;
}

inline bool Expr::isOne() const {
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this))
return CE->isOne();
return false;
}

inline bool Expr::isTrue() const {
assert(getWidth() == Expr::Bool && "Invalid isTrue() call!");
if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(this))
Expand Down
15 changes: 8 additions & 7 deletions include/klee/Expr/ExprEvaluator.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ namespace klee {
class ExprEvaluator : public ExprVisitor {
protected:
Action evalRead(const UpdateList &ul, unsigned index);
Action visitRead(const ReadExpr &re);
Action visitExpr(const Expr &e);
Action visitRead(const ReadExpr &re) override;
Action visitSelect(const SelectExpr &se) override;
Action visitExpr(const Expr &e) override;

Action protectedDivOperation(const BinaryExpr &e);
Action visitUDiv(const UDivExpr &e);
Action visitSDiv(const SDivExpr &e);
Action visitURem(const URemExpr &e);
Action visitSRem(const SRemExpr &e);
Action visitExprPost(const Expr &e);
Action visitUDiv(const UDivExpr &e) override;
Action visitSDiv(const SDivExpr &e) override;
Action visitURem(const URemExpr &e) override;
Action visitSRem(const SRemExpr &e) override;
Action visitExprPost(const Expr &e) override;

public:
ExprEvaluator() {}
Expand Down
3 changes: 3 additions & 0 deletions include/klee/Expr/ExprPPrinter.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define KLEE_EXPRPPRINTER_H

#include "klee/Expr/Expr.h"
#include "klee/Expr/Lemma.h"

namespace llvm {
class raw_ostream;
Expand Down Expand Up @@ -69,6 +70,8 @@ class ExprPPrinter {
const Array *const *evalArraysBegin = 0,
const Array *const *evalArraysEnd = 0,
bool printArrayDecls = true);

static void printLemma(llvm::raw_ostream &os, const Lemma &l);
};

} // namespace klee
Expand Down
5 changes: 2 additions & 3 deletions include/klee/Expr/ExprVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,9 @@ class ExprVisitor {
virtual Action visitFNeg(const FNegExpr &);
virtual Action visitFRint(const FRintExpr &);

protected:
VisitorHash visited;

private:
typedef ExprHashMap<ref<Expr>> visited_ty;
visited_ty visited;
bool recursive;

ref<Expr> visitActual(const ref<Expr> &e);
Expand Down
Loading