Skip to content

Commit

Permalink
Refactored MaxStatis*Pct conditions into a separate function.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccadar authored and MartinNowack committed Apr 20, 2021
1 parent 536f363 commit 8889369
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
66 changes: 39 additions & 27 deletions lib/Core/Executor.cpp
Expand Up @@ -962,40 +962,52 @@ void Executor::branch(ExecutionState &state,
addConstraint(*result[i], conditions[i]);
}

ref<Expr> Executor::maxStaticPctChecks(ExecutionState &current,
ref<Expr> condition) {
if (isa<klee::ConstantExpr>(condition))
return condition;

if (MaxStaticForkPct == 1. && MaxStaticSolvePct == 1. &&
MaxStaticCPForkPct == 1. && MaxStaticCPSolvePct == 1.)
return condition;

if (statsTracker->elapsed() <= time::seconds(60))
return condition;

StatisticManager &sm = *theStatisticManager;
CallPathNode *cpn = current.stack.back().callPathNode;
if ((MaxStaticForkPct < 1. &&
sm.getIndexedValue(stats::forks, sm.getIndex()) >
stats::forks * MaxStaticForkPct) ||
(MaxStaticCPForkPct < 1. && cpn &&
(cpn->statistics.getValue(stats::forks) >
stats::forks * MaxStaticCPForkPct)) ||
(MaxStaticSolvePct < 1 &&
sm.getIndexedValue(stats::solverTime, sm.getIndex()) >
stats::solverTime * MaxStaticSolvePct) ||
(MaxStaticCPForkPct < 1. && cpn &&
(cpn->statistics.getValue(stats::solverTime) >
stats::solverTime * MaxStaticCPSolvePct))) {
ref<klee::ConstantExpr> value;
bool success = solver->getValue(current.constraints, condition, value,
current.queryMetaData);
assert(success && "FIXME: Unhandled solver failure");
(void)success;
addConstraint(current, EqExpr::create(value, condition));
condition = value;
}
return condition;
}

Executor::StatePair
Executor::fork(ExecutionState &current, ref<Expr> condition, bool isInternal) {
Solver::Validity res;
std::map< ExecutionState*, std::vector<SeedInfo> >::iterator it =
seedMap.find(&current);
bool isSeeding = it != seedMap.end();

if (!isSeeding && !isa<ConstantExpr>(condition) &&
(MaxStaticForkPct!=1. || MaxStaticSolvePct != 1. ||
MaxStaticCPForkPct!=1. || MaxStaticCPSolvePct != 1.) &&
statsTracker->elapsed() > time::seconds(60)) {
StatisticManager &sm = *theStatisticManager;
CallPathNode *cpn = current.stack.back().callPathNode;
if ((MaxStaticForkPct<1. &&
sm.getIndexedValue(stats::forks, sm.getIndex()) >
stats::forks*MaxStaticForkPct) ||
(MaxStaticCPForkPct<1. &&
cpn && (cpn->statistics.getValue(stats::forks) >
stats::forks*MaxStaticCPForkPct)) ||
(MaxStaticSolvePct<1 &&
sm.getIndexedValue(stats::solverTime, sm.getIndex()) >
stats::solverTime*MaxStaticSolvePct) ||
(MaxStaticCPForkPct<1. &&
cpn && (cpn->statistics.getValue(stats::solverTime) >
stats::solverTime*MaxStaticCPSolvePct))) {
ref<ConstantExpr> value;
bool success = solver->getValue(current.constraints, condition, value,
current.queryMetaData);
assert(success && "FIXME: Unhandled solver failure");
(void) success;
addConstraint(current, EqExpr::create(value, condition));
condition = value;
}
}
if (!isSeeding)
condition = maxStaticPctChecks(current, condition);

time::Span timeout = coreSolverTimeout;
if (isSeeding)
Expand Down
4 changes: 4 additions & 0 deletions lib/Core/Executor.h
Expand Up @@ -355,6 +355,10 @@ class Executor : public Interpreter {
// current state, and one of the states may be null.
StatePair fork(ExecutionState &current, ref<Expr> condition, bool isInternal);

// If the MaxStatic*Pct limits have been reached, concretize the condition and
// return it. Otherwise, return the unmodified condition.
ref<Expr> maxStaticPctChecks(ExecutionState &current, ref<Expr> condition);

/// Add the given (boolean) condition as a constraint on state. This
/// function is a wrapper around the state's addConstraint function
/// which also manages propagation of implied values,
Expand Down

0 comments on commit 8889369

Please sign in to comment.