From: Anna Zaks Date: Sat, 10 Dec 2011 23:42:38 +0000 (+0000) Subject: [analyzer]Fixup r146336. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6d6a83c3754b449ac24cb83bc6d3a50b10535061;p=clang [analyzer]Fixup r146336. Forgot to commit the Header files. Rename generateUnknownVal -> makeGenericVal. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146337 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h index fd29e45c3d..76df8c28e5 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -109,7 +109,7 @@ public: /// handle the given binary expression. Depending on the state, decides to /// either keep the expression or forget the history and generate an /// UnknownVal. - SVal generateUnknownVal(const ProgramState *state, BinaryOperator::Opcode op, + SVal makeGenericVal(const ProgramState *state, BinaryOperator::Opcode op, NonLoc lhs, NonLoc rhs, QualType resultTy); SVal evalBinOp(const ProgramState *state, BinaryOperator::Opcode op, @@ -253,6 +253,9 @@ public: NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, const llvm::APSInt& rhs, QualType type); + NonLoc makeNonLoc(const llvm::APSInt& rhs, BinaryOperator::Opcode op, + const SymExpr *lhs, QualType type); + NonLoc makeNonLoc(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType type); diff --git a/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h b/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h index 0d311b8183..2a56c541ee 100644 --- a/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h +++ b/include/clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h @@ -48,7 +48,7 @@ public: MetadataKind, BEGIN_SYMBOLS = RegionValueKind, END_SYMBOLS = MetadataKind, - SymIntKind, SymSymKind, CastSymbolKind }; + SymIntKind, IntSymKind, SymSymKind, CastSymbolKind }; private: Kind K; @@ -379,6 +379,47 @@ public: } }; +/// IntSymExpr - Represents symbolic expression like 3 - 'x'. +class IntSymExpr : public SymExpr { + const llvm::APSInt& LHS; + BinaryOperator::Opcode Op; + const SymExpr *RHS; + QualType T; + +public: + IntSymExpr(const llvm::APSInt& lhs, BinaryOperator::Opcode op, + const SymExpr *rhs, QualType t) + : SymExpr(IntSymKind), LHS(lhs), Op(op), RHS(rhs), T(t) {} + + QualType getType(ASTContext &C) const { return T; } + + BinaryOperator::Opcode getOpcode() const { return Op; } + + void dumpToStream(raw_ostream &os) const; + + const SymExpr *getRHS() const { return RHS; } + const llvm::APSInt &getLHS() const { return LHS; } + + static void Profile(llvm::FoldingSetNodeID& ID, const llvm::APSInt& lhs, + BinaryOperator::Opcode op, const SymExpr *rhs, + QualType t) { + ID.AddInteger((unsigned) IntSymKind); + ID.AddPointer(&lhs); + ID.AddInteger(op); + ID.AddPointer(rhs); + ID.Add(t); + } + + void Profile(llvm::FoldingSetNodeID& ID) { + Profile(ID, LHS, Op, RHS, T); + } + + // Implement isa support. + static inline bool classof(const SymExpr *SE) { + return SE->getKind() == IntSymKind; + } +}; + /// SymSymExpr - Represents symbolic expression like 'x' + 'y'. class SymSymExpr : public SymExpr { const SymExpr *LHS; @@ -479,6 +520,10 @@ public: return getSymIntExpr(&lhs, op, rhs, t); } + const IntSymExpr *getIntSymExpr(const llvm::APSInt& lhs, + BinaryOperator::Opcode op, + const SymExpr *rhs, QualType t); + const SymSymExpr *getSymSymExpr(const SymExpr *lhs, BinaryOperator::Opcode op, const SymExpr *rhs, QualType t); diff --git a/lib/StaticAnalyzer/Core/SValBuilder.cpp b/lib/StaticAnalyzer/Core/SValBuilder.cpp index 81f84f90ae..cc2a8cb4d6 100644 --- a/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -167,7 +167,7 @@ DefinedSVal SValBuilder::getBlockPointer(const BlockDecl *block, //===----------------------------------------------------------------------===// -SVal SValBuilder::generateUnknownVal(const ProgramState *State, +SVal SValBuilder::makeGenericVal(const ProgramState *State, BinaryOperator::Opcode Op, NonLoc LHS, NonLoc RHS, QualType ResultTy) { diff --git a/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp b/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp index 70901aa608..4826c88aea 100644 --- a/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp +++ b/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp @@ -303,7 +303,7 @@ SVal SimpleSValBuilder::evalBinOpNN(const ProgramState *state, while (1) { switch (lhs.getSubKind()) { default: - return generateUnknownVal(state, op, lhs, rhs, resultTy); + return makeGenericVal(state, op, lhs, rhs, resultTy); case nonloc::LocAsIntegerKind: { Loc lhsL = cast(lhs).getLoc(); switch (rhs.getSubKind()) { @@ -326,7 +326,7 @@ SVal SimpleSValBuilder::evalBinOpNN(const ProgramState *state, return makeTruthVal(true, resultTy); default: // This case also handles pointer arithmetic. - return generateUnknownVal(state, op, lhs, rhs, resultTy); + return makeGenericVal(state, op, lhs, rhs, resultTy); } } } @@ -388,9 +388,9 @@ SVal SimpleSValBuilder::evalBinOpNN(const ProgramState *state, if (lhsValue == 0) // At this point lhs and rhs have been swapped. return rhs; - return generateUnknownVal(state, op, rhs, lhs, resultTy); + return makeGenericVal(state, op, rhs, lhs, resultTy); default: - return generateUnknownVal(state, op, rhs, lhs, resultTy); + return makeGenericVal(state, op, rhs, lhs, resultTy); } } } @@ -405,7 +405,7 @@ SVal SimpleSValBuilder::evalBinOpNN(const ProgramState *state, dyn_cast(selhs->getSymbol()); if (!symIntExpr) - return generateUnknownVal(state, op, lhs, rhs, resultTy); + return makeGenericVal(state, op, lhs, rhs, resultTy); // Is this a logical not? (!x is represented as x == 0.) if (op == BO_EQ && rhs.isZeroConstant()) { @@ -453,7 +453,7 @@ SVal SimpleSValBuilder::evalBinOpNN(const ProgramState *state, // For now, only handle expressions whose RHS is a constant. const nonloc::ConcreteInt *rhsInt = dyn_cast(&rhs); if (!rhsInt) - return generateUnknownVal(state, op, lhs, rhs, resultTy); + return makeGenericVal(state, op, lhs, rhs, resultTy); // If both the LHS and the current expression are additive, // fold their constants. @@ -538,7 +538,7 @@ SVal SimpleSValBuilder::evalBinOpNN(const ProgramState *state, resultTy); } - return generateUnknownVal(state, op, lhs, rhs, resultTy); + return makeGenericVal(state, op, lhs, rhs, resultTy); } } }