From ecd730085d4e19709d76a10300a15bc9fd4fb562 Mon Sep 17 00:00:00 2001 From: Anna Zaks Date: Sat, 10 Dec 2011 23:36:51 +0000 Subject: [analyzer] Introduce IntSymExpr, where the integer is on the lhs. Fix a bug in SimpleSValBuilder, where we should swap lhs and rhs when calling generateUnknownVal(), - the function which creates symbolic expressions when data is tainted. The issue is not visible when we only create the expressions for taint since all expressions are commutative from taint perspective. Refactor SymExpr::symbol_iterator::expand() to use a switch instead of a chain of ifs. llvm-svn: 146336 --- clang/lib/StaticAnalyzer/Core/SymbolManager.cpp | 62 +++++++++++++++++++------ 1 file changed, 49 insertions(+), 13 deletions(-) (limited to 'clang/lib/StaticAnalyzer/Core/SymbolManager.cpp') diff --git a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp index e79075f4121..6f5d8f90bbd 100644 --- a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp @@ -57,6 +57,15 @@ void SymIntExpr::dumpToStream(raw_ostream &os) const { if (getRHS().isUnsigned()) os << 'U'; } +void IntSymExpr::dumpToStream(raw_ostream &os) const { + os << ' ' << getLHS().getZExtValue(); + if (getLHS().isUnsigned()) os << 'U'; + print(os, getOpcode()); + os << '('; + getRHS()->dumpToStream(os); + os << ") "; +} + void SymSymExpr::dumpToStream(raw_ostream &os) const { os << '('; getLHS()->dumpToStream(os); @@ -125,20 +134,29 @@ void SymExpr::symbol_iterator::expand() { const SymExpr *SE = itr.back(); itr.pop_back(); - if (const SymbolCast *SC = dyn_cast(SE)) { - itr.push_back(SC->getOperand()); - return; - } - if (const SymIntExpr *SIE = dyn_cast(SE)) { - itr.push_back(SIE->getLHS()); - return; - } - else if (const SymSymExpr *SSE = dyn_cast(SE)) { - itr.push_back(SSE->getLHS()); - itr.push_back(SSE->getRHS()); - return; + switch (SE->getKind()) { + case SymExpr::RegionValueKind: + case SymExpr::ConjuredKind: + case SymExpr::DerivedKind: + case SymExpr::ExtentKind: + case SymExpr::MetadataKind: + return; + case SymExpr::CastSymbolKind: + itr.push_back(cast(SE)->getOperand()); + return; + case SymExpr::SymIntKind: + itr.push_back(cast(SE)->getLHS()); + return; + case SymExpr::IntSymKind: + itr.push_back(cast(SE)->getRHS()); + return; + case SymExpr::SymSymKind: { + const SymSymExpr *x = cast(SE); + itr.push_back(x->getLHS()); + itr.push_back(x->getRHS()); + return; + } } - llvm_unreachable("unhandled expansion case"); } @@ -262,6 +280,24 @@ const SymIntExpr *SymbolManager::getSymIntExpr(const SymExpr *lhs, return cast(data); } +const IntSymExpr *SymbolManager::getIntSymExpr(const llvm::APSInt& lhs, + BinaryOperator::Opcode op, + const SymExpr *rhs, + QualType t) { + llvm::FoldingSetNodeID ID; + IntSymExpr::Profile(ID, lhs, op, rhs, t); + void *InsertPos; + SymExpr *data = DataSet.FindNodeOrInsertPos(ID, InsertPos); + + if (!data) { + data = (IntSymExpr*) BPAlloc.Allocate(); + new (data) IntSymExpr(lhs, op, rhs, t); + DataSet.InsertNode(data, InsertPos); + } + + return cast(data); +} + const SymSymExpr *SymbolManager::getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, -- cgit v1.2.3