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

Add a bunch of features and fixes #202

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
81ebffa
fix: Terminate only not `CoveredNew` states
dim8art Nov 14, 2024
685dd82
fix: Do not cache ConstantExpr's
misonijnik Sep 22, 2024
61c6c52
chore(kleef): Add debug option to kleef
misonijnik Nov 8, 2024
1b589e1
fix: Fix the `cover-error-call` tests
misonijnik Sep 17, 2024
2438382
feat: Add FreezeLower
misonijnik Nov 16, 2024
0d4679c
chore: Update `constructSolverChain`
misonijnik Nov 16, 2024
53e50b2
feat: Cache LocationInfo
misonijnik Nov 16, 2024
98fe275
fix: Rewrite equalities intermittently
misonijnik Nov 5, 2024
680cd90
chore: Bump Bitwuzla version up to 0.6.0
misonijnik Nov 10, 2024
f058168
fix: Fix `eqExpr` in BitwuzlaBuilder
misonijnik Oct 16, 2024
d347369
fix(kleef): Use batching search in kleef script.
misonijnik Oct 16, 2024
ae7b12f
chore: Get gid of unnecessary constraints
misonijnik Nov 12, 2024
e0165af
chore(module): Intern `LocationInfo`
misonijnik Nov 16, 2024
dbc64de
fix: Fix SubExpr simplify
misonijnik Nov 13, 2024
9ff07b8
feat: Add `MaxCoreSolverMemory` (only for Bitwuzla)
misonijnik Nov 14, 2024
213540d
test: Update tests
misonijnik Nov 16, 2024
cf0a885
fix(freeze): Add include
misonijnik Nov 16, 2024
f2c5f68
fix(floats): Fix `FPToI` encoding, restrict on domain of definition
misonijnik Nov 19, 2024
f8881d4
test(options): Use `--debug` option in `kleef`
misonijnik Nov 19, 2024
a9765e9
test: Update
misonijnik Nov 19, 2024
5828c5b
chore(floats): Add description fo `FPToI` workaround
misonijnik Nov 19, 2024
fc15d93
chore(bitwuzla): Bump version
misonijnik Nov 19, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ env:
USE_LIBCXX: 1
Z3_VERSION: 4.8.15
SQLITE_VERSION: 3400100
BITWUZLA_VERSION: 0.3.1
BITWUZLA_VERSION: 0.6.1
JSON_VERSION: v3.11.3
IMMER_VERSION: v0.8.1

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Z3_VERSION=4.8.15
STP_VERSION=2.3.3
MINISAT_VERSION=master

BITWUZLA_VERSION=0.3.1
BITWUZLA_VERSION=0.6.1

KEEP_PARSE="true"
while [ $KEEP_PARSE = "true" ]; do
Expand Down
10 changes: 1 addition & 9 deletions include/klee/Expr/Constraints.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,29 +120,21 @@ class PathConstraints {
void advancePath(KInstruction *ki);
void advancePath(const Path &path);

ExprHashSet addConstraint(ref<Expr> e, Path::PathIndex currIndex);
ExprHashSet addConstraint(ref<Expr> e);
bool isSymcretized(ref<Expr> expr) const;
void addSymcrete(ref<Symcrete> s);
void rewriteConcretization(const Assignment &a);

const constraints_ty &original() const;
const ExprHashMap<ExprHashSet> &simplificationMap() const;
const ConstraintSet &cs() const;
const Path &path() const;
const ExprHashMap<Path::PathIndex> &indexes() const;
const ordered_constraints_ty &orderedCS() const;

static PathConstraints concat(const PathConstraints &l,
const PathConstraints &r);

private:
Path _path;
constraints_ty _original;
ConstraintSet constraints;
ExprHashMap<Path::PathIndex> pathIndexes;
ordered_constraints_ty orderedConstraints;
ExprHashMap<ExprHashSet> _simplificationMap;
unsigned long addingCounter = 0UL;
};

struct Conflict {
Expand Down
23 changes: 5 additions & 18 deletions include/klee/Expr/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,7 @@ class Expr {
}
};

struct ConstantExprCacheSet {
std::unordered_map<llvm::APInt, ConstantExpr *, APIntHash, APIntEq> cache;
~ConstantExprCacheSet();
};

static ExprCacheSet cachedExpressions;
static ConstantExprCacheSet cachedConstantExpressions;
static ref<Expr> createCachedExpr(ref<Expr> e);
bool isCached = false;
bool toBeCleared = false;
Expand Down Expand Up @@ -1538,24 +1532,17 @@ class ConstantExpr : public Expr {
void toMemory(void *address);

static ref<ConstantExpr> alloc(const llvm::APInt &v) {
auto success = cachedConstantExpressions.cache.find(v);
if (success == cachedConstantExpressions.cache.end()) {
// Cache miss
ref<ConstantExpr> r = new ConstantExpr(v);
r->computeHash();
r->computeHeight();
r->isCached = true;
cachedConstantExpressions.cache[v] = r.get();
return r;
}
return success->second;
ref<ConstantExpr> r = new ConstantExpr(v);
r->computeHash();
r->computeHeight();
return r;
}

static ref<ConstantExpr> alloc(const llvm::APFloat &f) {
ref<ConstantExpr> r(new ConstantExpr(f.bitcastToAPInt(), true));
r->computeHash();
r->computeHeight();
return createCachedExpr(r);
return r;
}

static ref<ConstantExpr> alloc(uint64_t v, Width w) {
Expand Down
3 changes: 3 additions & 0 deletions include/klee/Module/KInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@

#include "KModule.h"
#include "KValue.h"
#include "LocationInfo.h"

#include "llvm/Support/raw_ostream.h"

#include <optional>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -71,6 +73,7 @@ struct KInstruction : public KValue {
/// register indices.
int *operands;
KBlock *parent;
mutable std::optional<ref<LocationInfo>> locationInfo;

private:
// Instruction index in the basic block
Expand Down
3 changes: 1 addition & 2 deletions include/klee/Module/KModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ class KModule {
/// @param forceSourceOutput true if assembly.ll should be created
///
// FIXME: ihandler should not be here
void manifest(InterpreterHandler *ih, Interpreter::GuidanceKind guidance,
bool forceSourceOutput);
void manifest(InterpreterHandler *ih, bool forceSourceOutput);

/// Link the provided modules together as one KLEE module.
///
Expand Down
75 changes: 71 additions & 4 deletions include/klee/Module/LocationInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@
#ifndef KLEE_LOCATIONINFO_H
#define KLEE_LOCATIONINFO_H

#include "klee/ADT/Ref.h"

#include <cstdint>
#include <functional>
#include <optional>
#include <string>
#include <unordered_set>

namespace llvm {
class Function;
Expand All @@ -23,12 +27,16 @@ class Module;

namespace klee {
struct PhysicalLocationJson;
}
struct LocationInfo;
} // namespace klee

namespace klee {

/// @brief Immutable struct representing location in source code.
struct LocationInfo {
/// @brief Required by klee::ref-managed objects
class ReferenceCounter _refCount;

/// @brief Path to source file for that location.
const std::string file;

Expand All @@ -44,14 +52,73 @@ struct LocationInfo {
/// @return SARIFs representation of location.
PhysicalLocationJson serialize() const;

static ref<LocationInfo> create(std::string file, uint64_t line,
std::optional<uint64_t> column) {
LocationInfo *locationInfo = new LocationInfo(file, line, column);
return createCachedLocationInfo(locationInfo);
}

bool operator==(const LocationInfo &rhs) const {
return file == rhs.file && line == rhs.line && column == rhs.column;
}

bool equals(const LocationInfo &b) const { return *this == b; }

~LocationInfo() {
if (isCached) {
toBeCleared = true;
cachedLocationInfo.cache.erase(this);
}
}

private:
LocationInfo(std::string file, uint64_t line, std::optional<uint64_t> column)
: file(file), line(line), column(column) {}

struct LocationInfoHash {
std::size_t operator()(LocationInfo *const s) const noexcept {
std::size_t r = 0;
std::size_t h1 = std::hash<std::string>{}(s->file);
std::size_t h2 = std::hash<uint64_t>{}(s->line);
std::size_t h3 = std::hash<std::optional<uint64_t>>{}(s->column);
r ^= h1 + 0x9e3779b9 + (r << 6) + (r >> 2);
r ^= h2 + 0x9e3779b9 + (r << 6) + (r >> 2);
r ^= h3 + 0x9e3779b9 + (r << 6) + (r >> 2);
return r;
}
};

struct LocationInfoCmp {
bool operator()(LocationInfo *const a, LocationInfo *const b) const {
return *a == *b;
}
};

using CacheType =
std::unordered_set<LocationInfo *, LocationInfoHash, LocationInfoCmp>;

struct LocationInfoCacheSet {
CacheType cache;
~LocationInfoCacheSet() {
while (cache.size() != 0) {
ref<LocationInfo> tmp = *cache.begin();
tmp->isCached = false;
cache.erase(cache.begin());
}
}
};

static LocationInfoCacheSet cachedLocationInfo;
bool isCached = false;
bool toBeCleared = false;

static ref<LocationInfo>
createCachedLocationInfo(ref<LocationInfo> locationInfo);
};

LocationInfo getLocationInfo(const llvm::Function *func);
LocationInfo getLocationInfo(const llvm::Instruction *inst);
LocationInfo getLocationInfo(const llvm::GlobalVariable *global);
ref<LocationInfo> getLocationInfo(const llvm::Function *func);
ref<LocationInfo> getLocationInfo(const llvm::Instruction *inst);
ref<LocationInfo> getLocationInfo(const llvm::GlobalVariable *global);

} // namespace klee

Expand Down
2 changes: 1 addition & 1 deletion include/klee/Solver/IncompleteSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class StagedSolverImpl : public SolverImpl {
bool &hasSolution);
SolverRunStatus getOperationStatusCode();
std::string getConstraintLog(const Query &) final;
void setCoreSolverTimeout(time::Span timeout);
void setCoreSolverLimits(time::Span timeout, unsigned memoryLimit);
void notifyStateTermination(std::uint32_t id);
};

Expand Down
2 changes: 1 addition & 1 deletion include/klee/Solver/Solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class Solver {
getRange(const Query &, time::Span timeout = time::Span());

virtual std::string getConstraintLog(const Query &query);
virtual void setCoreSolverTimeout(time::Span timeout);
virtual void setCoreSolverLimits(time::Span timeout, unsigned memoryLimit);

/// @brief Notify the solver that the state with specified id has been
/// terminated
Expand Down
2 changes: 2 additions & 0 deletions include/klee/Solver/SolverCmdLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ extern llvm::cl::opt<bool> LogTimedOutQueries;

extern llvm::cl::opt<std::string> MaxCoreSolverTime;

extern llvm::cl::opt<unsigned> MaxCoreSolverMemory;

extern llvm::cl::opt<bool> UseForkedCoreSolver;

extern llvm::cl::opt<bool> CoreSolverOptimizeDivides;
Expand Down
2 changes: 1 addition & 1 deletion include/klee/Solver/SolverImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SolverImpl {
return {};
}

virtual void setCoreSolverTimeout(time::Span) {}
virtual void setCoreSolverLimits(time::Span, unsigned) {}

virtual void notifyStateTermination(std::uint32_t id) = 0;
};
Expand Down
6 changes: 3 additions & 3 deletions lib/Core/CodeLocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ CodeLocation::CodeLocation(const Path::PathIndex &pathIndex,
uint64_t sourceCodeLine,
std::optional<uint64_t> sourceCodeColumn)
: pathIndex(pathIndex), source(source),
location(LocationInfo{sourceFilename, sourceCodeLine, sourceCodeColumn}) {
}
location(LocationInfo::create(sourceFilename, sourceCodeLine,
sourceCodeColumn)) {}

ref<CodeLocation>
CodeLocation::create(const Path::PathIndex &pathIndex, const KValue *source,
Expand All @@ -44,7 +44,7 @@ CodeLocation::create(const KValue *source, const std::string &sourceFilename,
}

PhysicalLocationJson CodeLocation::serialize() const {
return location.serialize();
return location->serialize();
}

bool CodeLocation::equals(const CodeLocation &b) const {
Expand Down
3 changes: 2 additions & 1 deletion lib/Core/CodeLocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <cstdint>
#include <optional>
#include <string>
#include <unordered_set>

namespace klee {

Expand All @@ -35,7 +36,7 @@ struct CodeLocation {
const KValue *source;

/// @brief Location in source code.
const LocationInfo location;
const ref<LocationInfo> location;

private:
CodeLocation(const Path::PathIndex &pathIndex, const KValue *source,
Expand Down
Loading
Loading