diff --git a/include/klee/Expr/AlphaBuilder.h b/include/klee/Expr/AlphaBuilder.h index b56e9563cf..79c09bf457 100644 --- a/include/klee/Expr/AlphaBuilder.h +++ b/include/klee/Expr/AlphaBuilder.h @@ -34,7 +34,7 @@ class AlphaBuilder final : public ExprVisitor { public: AlphaBuilder(ArrayCache &_arrayCache); constraints_ty visitConstraints(constraints_ty cs); - ref visitExpr(ref v); + ref build(ref v); }; } // namespace klee diff --git a/lib/Expr/AlphaBuilder.cpp b/lib/Expr/AlphaBuilder.cpp index fa52783660..b3b98723c9 100644 --- a/lib/Expr/AlphaBuilder.cpp +++ b/lib/Expr/AlphaBuilder.cpp @@ -75,7 +75,7 @@ constraints_ty AlphaBuilder::visitConstraints(constraints_ty cs) { } return result; } -ref AlphaBuilder::visitExpr(ref v) { +ref AlphaBuilder::build(ref v) { ref e = visit(v); reverseExprMap[e] = v; reverseExprMap[Expr::createIsZero(e)] = Expr::createIsZero(v); diff --git a/lib/Solver/AlphaEquivalenceSolver.cpp b/lib/Solver/AlphaEquivalenceSolver.cpp index 4f29759cc3..b8e5e1f8b7 100644 --- a/lib/Solver/AlphaEquivalenceSolver.cpp +++ b/lib/Solver/AlphaEquivalenceSolver.cpp @@ -55,10 +55,14 @@ class AlphaEquivalenceSolver : public SolverImpl { void notifyStateTermination(std::uint32_t id); ValidityCore changeVersion(const ValidityCore &validityCore, const ExprHashMap> &reverse); - const std::vector + std::vector changeVersion(const std::vector &objects, const ArrayCache::ArrayHashMap &reverse); Assignment + changeVersion(const std::vector &objects, + const std::vector> &values, + const ArrayCache::ArrayHashMap &reverse); + Assignment changeVersion(const Assignment &a, const ArrayCache::ArrayHashMap &reverse); ref changeVersion(ref res, @@ -80,12 +84,29 @@ AlphaEquivalenceSolver::changeVersion(const ValidityCore &validityCore, return reverseValidityCore; } -const std::vector AlphaEquivalenceSolver::changeVersion( +Assignment AlphaEquivalenceSolver::changeVersion( + const std::vector &objects, + const std::vector> &values, + const ArrayCache::ArrayHashMap &reverse) { + std::vector reverseObjects; + std::vector> reverseValues; + for (size_t i = 0; i < objects.size(); i++) { + if (reverse.count(objects.at(i)) != 0) { + reverseObjects.push_back(reverse.at(objects.at(i))); + reverseValues.push_back(values.at(i)); + } + } + return Assignment(reverseObjects, reverseValues); +} + +std::vector AlphaEquivalenceSolver::changeVersion( const std::vector &objects, const ArrayCache::ArrayHashMap &reverse) { std::vector reverseObjects; - for (auto it : objects) { - reverseObjects.push_back(reverse.at(it)); + for (size_t i = 0; i < objects.size(); i++) { + if (reverse.count(objects.at(i)) != 0) { + reverseObjects.push_back(reverse.at(objects.at(i))); + } } return reverseObjects; } @@ -95,8 +116,7 @@ Assignment AlphaEquivalenceSolver::changeVersion( const ArrayCache::ArrayHashMap &reverse) { std::vector objects = a.keys(); std::vector> values = a.values(); - objects = changeVersion(objects, reverse); - return Assignment(objects, values); + return changeVersion(objects, values, reverse); } ref @@ -136,7 +156,7 @@ bool AlphaEquivalenceSolver::computeValidity(const Query &query, PartialValidity &result) { AlphaBuilder builder(arrayCache); constraints_ty alphaQuery = builder.visitConstraints(query.constraints.cs()); - ref alphaQueryExpr = builder.visitExpr(query.expr); + ref alphaQueryExpr = builder.build(query.expr); return solver->impl->computeValidity( Query(ConstraintSet(alphaQuery, {}, {}), alphaQueryExpr, query.id), result); @@ -145,7 +165,7 @@ bool AlphaEquivalenceSolver::computeValidity(const Query &query, bool AlphaEquivalenceSolver::computeTruth(const Query &query, bool &isValid) { AlphaBuilder builder(arrayCache); constraints_ty alphaQuery = builder.visitConstraints(query.constraints.cs()); - ref alphaQueryExpr = builder.visitExpr(query.expr); + ref alphaQueryExpr = builder.build(query.expr); return solver->impl->computeTruth( Query(ConstraintSet(alphaQuery, {}, {}), alphaQueryExpr, query.id), isValid); @@ -155,7 +175,7 @@ bool AlphaEquivalenceSolver::computeValue(const Query &query, ref &result) { AlphaBuilder builder(arrayCache); constraints_ty alphaQuery = builder.visitConstraints(query.constraints.cs()); - ref alphaQueryExpr = builder.visitExpr(query.expr); + ref alphaQueryExpr = builder.build(query.expr); return solver->impl->computeValue( Query(ConstraintSet(alphaQuery, {}, {}), alphaQueryExpr, query.id), result); @@ -166,7 +186,7 @@ bool AlphaEquivalenceSolver::computeInitialValues( std::vector> &values, bool &hasSolution) { AlphaBuilder builder(arrayCache); constraints_ty alphaQuery = builder.visitConstraints(query.constraints.cs()); - ref alphaQueryExpr = builder.visitExpr(query.expr); + ref alphaQueryExpr = builder.build(query.expr); const std::vector newObjects = changeVersion(objects, builder.alphaArrayMap); @@ -183,7 +203,7 @@ bool AlphaEquivalenceSolver::check(const Query &query, AlphaBuilder builder(arrayCache); constraints_ty alphaQuery = builder.visitConstraints(query.constraints.cs()); - ref alphaQueryExpr = builder.visitExpr(query.expr); + ref alphaQueryExpr = builder.build(query.expr); result = createAlphaVersion(result, builder); if (!solver->impl->check( Query(ConstraintSet(alphaQuery, {}, {}), alphaQueryExpr, query.id), @@ -201,7 +221,7 @@ bool AlphaEquivalenceSolver::computeValidityCore(const Query &query, AlphaBuilder builder(arrayCache); constraints_ty alphaQuery = builder.visitConstraints(query.constraints.cs()); - ref alphaQueryExpr = builder.visitExpr(query.expr); + ref alphaQueryExpr = builder.build(query.expr); if (!solver->impl->computeValidityCore( Query(ConstraintSet(alphaQuery, {}, {}), alphaQueryExpr, query.id), validityCore, isValid)) {