From 08e5f32e11923cdaa46f68c8cc5de1ff9e5036d0 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Sun, 7 Jun 2009 17:48:17 +0000 Subject: Make sure that ExprEvaluator will fold constant expressions (klee never creates these, but the parser can). git-svn-id: https://llvm.org/svn/llvm-project/klee/trunk@73033 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/klee/util/ExprEvaluator.h | 1 + lib/Expr/ExprEvaluator.cpp | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/klee/util/ExprEvaluator.h b/include/klee/util/ExprEvaluator.h index be98942d..739e51e6 100644 --- a/include/klee/util/ExprEvaluator.h +++ b/include/klee/util/ExprEvaluator.h @@ -18,6 +18,7 @@ namespace klee { protected: Action evalRead(const UpdateList &ul, unsigned index); Action visitRead(const ReadExpr &re); + Action visitExpr(const Expr &e); Action protectedDivOperation(const BinaryExpr &e); Action visitUDiv(const UDivExpr &e); diff --git a/lib/Expr/ExprEvaluator.cpp b/lib/Expr/ExprEvaluator.cpp index ca8f1611..eced0e87 100644 --- a/lib/Expr/ExprEvaluator.cpp +++ b/lib/Expr/ExprEvaluator.cpp @@ -33,6 +33,27 @@ ExprVisitor::Action ExprEvaluator::evalRead(const UpdateList &ul, return Action::changeTo(getInitialValue(*ul.root, index)); } +ExprVisitor::Action ExprEvaluator::visitExpr(const Expr &e) { + // Evaluate all constant expressions here, in case they weren't folded in + // construction. Don't do this for reads though, because we want them to go to + // the normal rewrite path. + unsigned N = e.getNumKids(); + if (!N || isa(e)) + return Action::doChildren(); + + for (unsigned i = 0; i != N; ++i) + if (!isa(e.getKid(i))) + return Action::doChildren(); + + ref Kids[3]; + for (unsigned i = 0; i != N; ++i) { + assert(i < 3); + Kids[i] = e.getKid(i); + } + + return Action::changeTo(e.rebuild(Kids)); +} + ExprVisitor::Action ExprEvaluator::visitRead(const ReadExpr &re) { ref v = visit(re.index); -- cgit 1.4.1