Skip to content

Commit 8513a6d

Browse files
misonijnikdim8art
andauthored
feat: Add a bunch of features and fixes (#202)
* fix: Terminate only not `CoveredNew` states * fix: Do not cache ConstantExpr's * chore(kleef): Add debug option to kleef * fix: Fix the `cover-error-call` tests * feat: Add FreezeLower * chore: Update `constructSolverChain` * feat: Cache LocationInfo * fix: Rewrite equalities intermittently * chore: Bump Bitwuzla version up to 0.7.0 * fix: Fix `eqExpr` in BitwuzlaBuilder * fix(kleef): Use batching search in kleef script. fix(kleef): Disable concretizing solver in kleef fix(kleef): Disable tree-solver * chore: Get rid of unnecessary constraints * chore(module): Intern `LocationInfo` * fix: Fix SubExpr simplify * feat: Add `MaxCoreSolverMemory` (only for Bitwuzla) * test: Update tests * fix(freeze): Add include * fix(floats): Fix `FPToI` encoding, restrict on the domain of definition * test(options): Use `--debug` option in `kleef` * chore(floats): Add description fo `FPToI` workaround * fix(ci): Disable sanitizers because of bitwuzla crashing with an assertion failure --------- Co-authored-by: dim8art <dim8art@yandex.ru>
1 parent 75bf174 commit 8513a6d

64 files changed

Lines changed: 54893 additions & 432 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ env:
3737
USE_LIBCXX: 1
3838
Z3_VERSION: 4.8.15
3939
SQLITE_VERSION: 3400100
40-
BITWUZLA_VERSION: 0.3.1
40+
BITWUZLA_VERSION: 0.7.0
4141
JSON_VERSION: v3.11.3
4242
IMMER_VERSION: v0.8.1
4343

build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Z3_VERSION=4.8.15
5656
STP_VERSION=2.3.3
5757
MINISAT_VERSION=master
5858

59-
BITWUZLA_VERSION=0.3.1
59+
BITWUZLA_VERSION=0.7.0
6060

6161
KEEP_PARSE="true"
6262
while [ $KEEP_PARSE = "true" ]; do

include/klee/Expr/Constraints.h

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,29 +120,21 @@ class PathConstraints {
120120
void advancePath(KInstruction *ki);
121121
void advancePath(const Path &path);
122122

123-
ExprHashSet addConstraint(ref<Expr> e, Path::PathIndex currIndex);
124123
ExprHashSet addConstraint(ref<Expr> e);
125124
bool isSymcretized(ref<Expr> expr) const;
126125
void addSymcrete(ref<Symcrete> s);
127126
void rewriteConcretization(const Assignment &a);
128127

129-
const constraints_ty &original() const;
130-
const ExprHashMap<ExprHashSet> &simplificationMap() const;
131128
const ConstraintSet &cs() const;
132129
const Path &path() const;
133-
const ExprHashMap<Path::PathIndex> &indexes() const;
134-
const ordered_constraints_ty &orderedCS() const;
135130

136131
static PathConstraints concat(const PathConstraints &l,
137132
const PathConstraints &r);
138133

139134
private:
140135
Path _path;
141-
constraints_ty _original;
142136
ConstraintSet constraints;
143-
ExprHashMap<Path::PathIndex> pathIndexes;
144-
ordered_constraints_ty orderedConstraints;
145-
ExprHashMap<ExprHashSet> _simplificationMap;
137+
unsigned long addingCounter = 0UL;
146138
};
147139

148140
struct Conflict {

include/klee/Expr/Expr.h

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,7 @@ class Expr {
150150
}
151151
};
152152

153-
struct ConstantExprCacheSet {
154-
std::unordered_map<llvm::APInt, ConstantExpr *, APIntHash, APIntEq> cache;
155-
~ConstantExprCacheSet();
156-
};
157-
158153
static ExprCacheSet cachedExpressions;
159-
static ConstantExprCacheSet cachedConstantExpressions;
160154
static ref<Expr> createCachedExpr(ref<Expr> e);
161155
bool isCached = false;
162156
bool toBeCleared = false;
@@ -1538,24 +1532,17 @@ class ConstantExpr : public Expr {
15381532
void toMemory(void *address);
15391533

15401534
static ref<ConstantExpr> alloc(const llvm::APInt &v) {
1541-
auto success = cachedConstantExpressions.cache.find(v);
1542-
if (success == cachedConstantExpressions.cache.end()) {
1543-
// Cache miss
1544-
ref<ConstantExpr> r = new ConstantExpr(v);
1545-
r->computeHash();
1546-
r->computeHeight();
1547-
r->isCached = true;
1548-
cachedConstantExpressions.cache[v] = r.get();
1549-
return r;
1550-
}
1551-
return success->second;
1535+
ref<ConstantExpr> r = new ConstantExpr(v);
1536+
r->computeHash();
1537+
r->computeHeight();
1538+
return r;
15521539
}
15531540

15541541
static ref<ConstantExpr> alloc(const llvm::APFloat &f) {
15551542
ref<ConstantExpr> r(new ConstantExpr(f.bitcastToAPInt(), true));
15561543
r->computeHash();
15571544
r->computeHeight();
1558-
return createCachedExpr(r);
1545+
return r;
15591546
}
15601547

15611548
static ref<ConstantExpr> alloc(uint64_t v, Width w) {

include/klee/Module/KInstruction.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@
1212

1313
#include "KModule.h"
1414
#include "KValue.h"
15+
#include "LocationInfo.h"
1516

1617
#include "llvm/Support/raw_ostream.h"
1718

19+
#include <optional>
1820
#include <unordered_map>
1921
#include <vector>
2022

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

7578
private:
7679
// Instruction index in the basic block

include/klee/Module/KModule.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,7 @@ class KModule {
352352
/// @param forceSourceOutput true if assembly.ll should be created
353353
///
354354
// FIXME: ihandler should not be here
355-
void manifest(InterpreterHandler *ih, Interpreter::GuidanceKind guidance,
356-
bool forceSourceOutput);
355+
void manifest(InterpreterHandler *ih, bool forceSourceOutput);
357356

358357
/// Link the provided modules together as one KLEE module.
359358
///

include/klee/Module/LocationInfo.h

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@
1010
#ifndef KLEE_LOCATIONINFO_H
1111
#define KLEE_LOCATIONINFO_H
1212

13+
#include "klee/ADT/Ref.h"
14+
1315
#include <cstdint>
16+
#include <functional>
1417
#include <optional>
1518
#include <string>
19+
#include <unordered_set>
1620

1721
namespace llvm {
1822
class Function;
@@ -23,12 +27,16 @@ class Module;
2327

2428
namespace klee {
2529
struct PhysicalLocationJson;
26-
}
30+
struct LocationInfo;
31+
} // namespace klee
2732

2833
namespace klee {
2934

3035
/// @brief Immutable struct representing location in source code.
3136
struct LocationInfo {
37+
/// @brief Required by klee::ref-managed objects
38+
class ReferenceCounter _refCount;
39+
3240
/// @brief Path to source file for that location.
3341
const std::string file;
3442

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

55+
static ref<LocationInfo> create(std::string file, uint64_t line,
56+
std::optional<uint64_t> column) {
57+
LocationInfo *locationInfo = new LocationInfo(file, line, column);
58+
return createCachedLocationInfo(locationInfo);
59+
}
60+
4761
bool operator==(const LocationInfo &rhs) const {
4862
return file == rhs.file && line == rhs.line && column == rhs.column;
4963
}
64+
65+
bool equals(const LocationInfo &b) const { return *this == b; }
66+
67+
~LocationInfo() {
68+
if (isCached) {
69+
toBeCleared = true;
70+
cachedLocationInfo.cache.erase(this);
71+
}
72+
}
73+
74+
private:
75+
LocationInfo(std::string file, uint64_t line, std::optional<uint64_t> column)
76+
: file(file), line(line), column(column) {}
77+
78+
struct LocationInfoHash {
79+
std::size_t operator()(LocationInfo *const s) const noexcept {
80+
std::size_t r = 0;
81+
std::size_t h1 = std::hash<std::string>{}(s->file);
82+
std::size_t h2 = std::hash<uint64_t>{}(s->line);
83+
std::size_t h3 = std::hash<std::optional<uint64_t>>{}(s->column);
84+
r ^= h1 + 0x9e3779b9 + (r << 6) + (r >> 2);
85+
r ^= h2 + 0x9e3779b9 + (r << 6) + (r >> 2);
86+
r ^= h3 + 0x9e3779b9 + (r << 6) + (r >> 2);
87+
return r;
88+
}
89+
};
90+
91+
struct LocationInfoCmp {
92+
bool operator()(LocationInfo *const a, LocationInfo *const b) const {
93+
return *a == *b;
94+
}
95+
};
96+
97+
using CacheType =
98+
std::unordered_set<LocationInfo *, LocationInfoHash, LocationInfoCmp>;
99+
100+
struct LocationInfoCacheSet {
101+
CacheType cache;
102+
~LocationInfoCacheSet() {
103+
while (cache.size() != 0) {
104+
ref<LocationInfo> tmp = *cache.begin();
105+
tmp->isCached = false;
106+
cache.erase(cache.begin());
107+
}
108+
}
109+
};
110+
111+
static LocationInfoCacheSet cachedLocationInfo;
112+
bool isCached = false;
113+
bool toBeCleared = false;
114+
115+
static ref<LocationInfo>
116+
createCachedLocationInfo(ref<LocationInfo> locationInfo);
50117
};
51118

52-
LocationInfo getLocationInfo(const llvm::Function *func);
53-
LocationInfo getLocationInfo(const llvm::Instruction *inst);
54-
LocationInfo getLocationInfo(const llvm::GlobalVariable *global);
119+
ref<LocationInfo> getLocationInfo(const llvm::Function *func);
120+
ref<LocationInfo> getLocationInfo(const llvm::Instruction *inst);
121+
ref<LocationInfo> getLocationInfo(const llvm::GlobalVariable *global);
55122

56123
} // namespace klee
57124

include/klee/Solver/IncompleteSolver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class StagedSolverImpl : public SolverImpl {
7979
bool &hasSolution);
8080
SolverRunStatus getOperationStatusCode();
8181
std::string getConstraintLog(const Query &) final;
82-
void setCoreSolverTimeout(time::Span timeout);
82+
void setCoreSolverLimits(time::Span timeout, unsigned memoryLimit);
8383
void notifyStateTermination(std::uint32_t id);
8484
};
8585

include/klee/Solver/Solver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class Solver {
191191
getRange(const Query &, time::Span timeout = time::Span());
192192

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

196196
/// @brief Notify the solver that the state with specified id has been
197197
/// terminated

include/klee/Solver/SolverCmdLine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ extern llvm::cl::opt<bool> LogTimedOutQueries;
4141

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

44+
extern llvm::cl::opt<unsigned> MaxCoreSolverMemory;
45+
4446
extern llvm::cl::opt<bool> UseForkedCoreSolver;
4547

4648
extern llvm::cl::opt<bool> CoreSolverOptimizeDivides;

0 commit comments

Comments
 (0)