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

[WIP]add AbstractValue #1423

Merged
merged 7 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
update symabs
  • Loading branch information
jiawei-95 committed Apr 2, 2024
commit ea97b2ac94cb44d11b185080fcaad3a6b486b15a
54 changes: 25 additions & 29 deletions svf-llvm/tools/AE/ae.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(0, 1)}, {1, IntervalValue(1, 2)}};
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(0, 1)}, {1, IntervalValue(1, 2)}};
assert(IntervalESBase::eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
}

Expand Down Expand Up @@ -163,9 +163,9 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(0, 1)}, {1, IntervalValue(0, 2)}};
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(0, 1)}, {1, IntervalValue(0, 2)}};
assert(IntervalESBase::eqVarToValMap(resBS.getVarToVal(), intendedRes) && "inconsistency occurs");
}

Expand Down Expand Up @@ -201,10 +201,10 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(0, 10)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(0, 10)},
{1, IntervalValue(0, 10)},
{2, IntervalValue(0, 0)}
};
Expand Down Expand Up @@ -244,10 +244,10 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(0, 100)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(0, 100)},
{1, IntervalValue(0, 100)},
{2, IntervalValue(0, 0)}
};
Expand Down Expand Up @@ -287,11 +287,10 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
// ground truth
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(0, 1000)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(0, 1000)},
{1, IntervalValue(0, 1000)},
{2, IntervalValue(0, 0)}
};
Expand Down Expand Up @@ -331,11 +330,10 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
// ground truth
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(0, 10000)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(0, 10000)},
{1, IntervalValue(0, 10000)},
{2, IntervalValue(0, 0)}
};
Expand Down Expand Up @@ -375,11 +373,10 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
// ground truth
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(0, 100000)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(0, 100000)},
{1, IntervalValue(0, 100000)},
{2, IntervalValue(0, 0)}
};
Expand Down Expand Up @@ -418,10 +415,10 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(1, 10)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(1, 10)},
{1, IntervalValue(1, 10)},
{2, IntervalValue(1, 1)}
};
Expand Down Expand Up @@ -460,10 +457,10 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(1, 1000)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(1, 1000)},
{1, IntervalValue(1, 1000)},
{2, IntervalValue(1, 1)}
};
Expand Down Expand Up @@ -502,13 +499,12 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
IntervalESBase::VarToValMap intendedRes =
Map<u32_t, IntervalValue>({{0, IntervalValue(1, 10000)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(1, 10000)},
{1, IntervalValue(1, 10000)},
{2, IntervalValue(1, 1)}});
{2, IntervalValue(1, 1)}};
}

void testRelExeState3_4()
Expand Down Expand Up @@ -543,10 +539,10 @@ class SymblicAbstractionTest
assert(resRSY == resBS && resBS == resBilateral && "inconsistency occurs");
for (auto r : resRSY.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(1, 100000)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(1, 100000)},
{1, IntervalValue(1, 100000)},
{2, IntervalValue(1, 1)}
};
Expand Down Expand Up @@ -588,10 +584,10 @@ class SymblicAbstractionTest
// assert(resRSY == resBS && resBS == resBilateral);
for (auto r : resBS.getVarToVal())
{
outs() << r.first << " " << r.second << "\n";
outs() << r.first << " " << r.second.getInterval() << "\n";
}
// ground truth
IntervalESBase::VarToValMap intendedRes = {{0, IntervalValue(0, 10)},
IntervalESBase::VarToAbsValMap intendedRes = {{0, IntervalValue(0, 10)},
{1, IntervalValue(0, 10)},
{2, IntervalValue(IntervalValue::minus_infinity(), IntervalValue::plus_infinity())}
};
Expand Down
8 changes: 7 additions & 1 deletion svf/include/AE/Core/IntervalExeState.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class IntervalESBase
for (auto &item: inv._varToAbsVal)
{
if (item.second.isInterval())
item.second.getInterval().set_to_bottom();
item.second.getInterval().set_to_top();
}
return inv;
}
Expand Down Expand Up @@ -178,6 +178,12 @@ class IntervalESBase
return _varToAbsVal[varId];
}

/// get interval value of variable
inline virtual const AbstractValue &operator[](u32_t varId) const
{
return _varToAbsVal.at(varId);
}

/// whether the variable is in varToAddrs table
inline bool inVarToAddrsTable(u32_t id) const
{
Expand Down
14 changes: 7 additions & 7 deletions svf/lib/AE/Core/RelationSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ IntervalESBase RelationSolver::abstract_consequence(
/// for variable in self.variables:
{
IntervalESBase proposed = domain.top(); /// proposed = self.top.copy()
proposed._varToItvVal[it->first] = lower._varToItvVal.at(it->first);
proposed[it->first] = lower[it->first].getInterval();
/// proposed.set_interval(variable, lower.interval_of(variable))
/// proposed._locToItvVal
if (!(proposed >= upper)) /// if not proposed >= upper:
Expand Down Expand Up @@ -218,7 +218,7 @@ Z3Expr RelationSolver::gamma_hat(const IntervalESBase& alpha,
Z3Expr res(Z3Expr::getContext().bool_val(true));
for (auto& item : exeState.getVarToVal())
{
IntervalValue interval = alpha._varToItvVal.at(item.first);
IntervalValue interval = alpha[item.first].getInterval();
if (interval.isBottom())
return Z3Expr::getContext().bool_val(false);
if (interval.isTop())
Expand Down Expand Up @@ -247,7 +247,7 @@ IntervalESBase RelationSolver::beta(const Map<u32_t, s32_t>& sigma,
IntervalESBase res;
for (const auto& item : exeState.getVarToVal())
{
res._varToItvVal[item.first] = IntervalValue(
res[item.first] = IntervalValue(
sigma.at(item.first), sigma.at(item.first));
}
return res;
Expand Down Expand Up @@ -318,16 +318,16 @@ IntervalESBase RelationSolver::BS(const IntervalESBase& domain, const Z3Expr &ph
if (item.first >= bias)
{
if (item.second.equal(infinity))
retInv._varToItvVal[item.first - bias].setLb(Z3Expr::getContext().int_const("-oo"));
retInv[item.first - bias].getInterval().setLb(Z3Expr::getContext().int_const("-oo"));
else
retInv._varToItvVal[item.first - bias].setLb(-item.second);
retInv[item.first - bias].getInterval().setLb(-item.second);
}
else
{
if (item.second.equal(infinity))
retInv._varToItvVal[item.first].setUb(Z3Expr::getContext().int_const("+oo"));
retInv[item.first].getInterval().setUb(Z3Expr::getContext().int_const("+oo"));
else
retInv._varToItvVal[item.first].setUb(item.second);
retInv[item.first].getInterval().setUb(item.second);
}
}
return retInv;
Expand Down