Skip to content

Commit 26c9917

Browse files
remove unused & resize before update environment
1 parent b75a627 commit 26c9917

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

headers/wasm/concolic_driver.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ inline void ConcolicDriver::run() {
4747
return;
4848
}
4949
auto cond = unexplored->collect_path_conds();
50-
std::vector<Num> new_env;
51-
std::set<int> valid_ids;
5250
auto result = solver.solve(cond);
5351
if (!result.has_value()) {
5452
// TODO: current implementation is buggy, there could be other reachable
@@ -58,8 +56,8 @@ inline void ConcolicDriver::run() {
5856
unexplored->fillUnreachableNode();
5957
continue;
6058
}
61-
std::tie(new_env, valid_ids) = std::move(result.value());
62-
SymEnv.update(std::move(new_env), std::move(valid_ids));
59+
auto new_env = result.value();
60+
SymEnv.update(std::move(new_env));
6361
try {
6462
entrypoint();
6563
std::cout << "Execution finished successfully with symbolic environment:"

headers/wasm/smt_solver.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
class Solver {
1414
public:
1515
Solver() {}
16-
std::optional<std::tuple<std::vector<Num>, std::set<int>>>
17-
solve(const std::vector<SymVal> &conditions) {
16+
std::optional<std::vector<Num>> solve(const std::vector<SymVal> &conditions) {
1817
// make an conjunction of all conditions
1918
z3::expr conjunction = z3_ctx.bool_val(true);
2019
for (const auto &cond : conditions) {
@@ -33,26 +32,27 @@ class Solver {
3332
return std::nullopt; // No solution found
3433
case z3::sat: {
3534
z3::model model = z3_solver.get_model();
36-
std::vector<Num> result(max_id + 1, Num(0));
35+
std::vector<Num> result;
3736
// Reference:
3837
// https://github.com/Z3Prover/z3/blob/master/examples/c%2B%2B/example.cpp#L59
3938

40-
std::cout << "Solved Z3 model" << model << std::endl;
41-
std::set<int> seen_ids;
39+
std::cout << "Solved Z3 model" << std::endl << model << std::endl;
4240
for (unsigned i = 0; i < model.size(); ++i) {
4341
z3::func_decl var = model[i];
4442
z3::expr value = model.get_const_interp(var);
4543
std::string name = var.name().str();
4644
if (name.starts_with("s_")) {
4745
int id = std::stoi(name.substr(2));
48-
seen_ids.insert(id);
46+
if (id >= result.size()) {
47+
result.resize(id + 1);
48+
}
4949
result[id] = Num(value.get_numeral_int());
5050
} else {
5151
std::cout << "Find a variable that is not created by GenSym: " << name
5252
<< std::endl;
5353
}
5454
}
55-
return std::make_tuple(result, seen_ids);
55+
return result;
5656
}
5757
case z3::unknown:
5858
throw std::runtime_error("Z3 solver returned unknown status");

headers/wasm/symbolic_rt.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ class SymEnv_t {
531531
return map[symbol->get_id()];
532532
}
533533

534-
void update(std::vector<Num> new_env, std::set<int> valid_ids) {
534+
void update(std::vector<Num> new_env) {
535535
map = std::move(new_env);
536536
}
537537

@@ -549,7 +549,6 @@ class SymEnv_t {
549549

550550
private:
551551
std::vector<Num> map; // The symbolic environment, a vector of Num
552-
std::set<int> valid_ids; // The set of valid IDs in the symbolic environment
553552
};
554553

555554
static SymEnv_t SymEnv;

0 commit comments

Comments
 (0)