From: Ted Kremenek Date: Wed, 6 Feb 2008 04:31:33 +0000 (+0000) Subject: Fixed signedness bug in cast transfer function when casting integers to pointers. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=08b66255e2605adfa8777dbff293db1c69bc1092;p=clang Fixed signedness bug in cast transfer function when casting integers to pointers. Removed lval::SymIntConstraintVal; wrappers for symbolic constraints are not lvalues (only integers that evaluate to !0 or 0). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46796 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/Analysis/GRConstants.cpp b/Analysis/GRConstants.cpp index 39a50a55ce..8656d776c8 100644 --- a/Analysis/GRConstants.cpp +++ b/Analysis/GRConstants.cpp @@ -234,6 +234,9 @@ public: StateTy AssumeSymEQ(StateTy St, SymbolID sym, const llvm::APSInt& V, bool& isFeasible); + StateTy AssumeSymInt(StateTy St, bool Assumption, const SymIntConstraint& C, + bool& isFeasible); + void Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St); /// Nodify - This version of Nodify is used to batch process a set of states. @@ -874,6 +877,7 @@ GRConstants::StateTy GRConstants::Assume(StateTy St, LValue Cond, return AssumeSymEQ(St, cast(Cond).getSymbol(), ValMgr.getZeroWithPtrWidth(), isFeasible); + case lval::DeclValKind: isFeasible = Assumption; return St; @@ -895,6 +899,12 @@ GRConstants::StateTy GRConstants::Assume(StateTy St, NonLValue Cond, assert (false && "'Assume' not implemented for this NonLValue."); return St; + case nonlval::SymIntConstraintValKind: + return + AssumeSymInt(St, Assumption, + cast(Cond).getConstraint(), + isFeasible); + case nonlval::ConcreteIntKind: { bool b = cast(Cond).getValue() != 0; isFeasible = b ? Assumption : !Assumption; @@ -949,6 +959,29 @@ GRConstants::AssumeSymEQ(StateTy St, SymbolID sym, return StateMgr.AddEQ(St, sym, V); } +GRConstants::StateTy +GRConstants::AssumeSymInt(StateTy St, bool Assumption, + const SymIntConstraint& C, bool& isFeasible) { + + switch (C.getOpcode()) { + default: + // No logic yet for other operators. + return St; + + case BinaryOperator::EQ: + if (Assumption) + return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); + else + return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); + + case BinaryOperator::NE: + if (Assumption) + return AssumeSymNE(St, C.getSymbol(), C.getInt(), isFeasible); + else + return AssumeSymEQ(St, C.getSymbol(), C.getInt(), isFeasible); + } +} + //===----------------------------------------------------------------------===// // Driver. //===----------------------------------------------------------------------===// diff --git a/Analysis/RValues.cpp b/Analysis/RValues.cpp index 33d9d656a7..fba59b42ac 100644 --- a/Analysis/RValues.cpp +++ b/Analysis/RValues.cpp @@ -138,7 +138,7 @@ RValue NonLValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { APSInt V = cast(this)->getValue(); QualType T = CastExpr->getType(); - V.setIsUnsigned(T->isUnsignedIntegerType()); + V.setIsUnsigned(T->isUnsignedIntegerType() || T->isPointerType()); V.extOrTrunc(ValMgr.getContext().getTypeSize(T, CastExpr->getLocStart())); if (CastExpr->getType()->isPointerType()) @@ -425,17 +425,7 @@ void LValue::print(std::ostream& Out) const { case lval::SymbolValKind: Out << '$' << cast(this)->getSymbol(); break; - - case lval::SymIntConstraintValKind: { - const lval::SymIntConstraintVal& C = - *cast(this); - - Out << '$' << C.getConstraint().getSymbol() << ' '; - printOpcode(Out, C.getConstraint().getOpcode()); - Out << ' ' << C.getConstraint().getInt().toString(); - break; - } - + case lval::DeclValKind: Out << '&' << cast(this)->getDecl()->getIdentifier()->getName(); diff --git a/Analysis/RValues.h b/Analysis/RValues.h index cd74262384..9bb97caf40 100644 --- a/Analysis/RValues.h +++ b/Analysis/RValues.h @@ -446,7 +446,6 @@ namespace nonlval { namespace lval { enum Kind { SymbolValKind, - SymIntConstraintValKind, DeclValKind, ConcreteIntKind, NumKind }; @@ -465,20 +464,6 @@ namespace lval { } }; - class SymIntConstraintVal : public LValue { - public: - SymIntConstraintVal(const SymIntConstraint& C) - : LValue(SymIntConstraintValKind, reinterpret_cast(&C)) {} - - const SymIntConstraint& getConstraint() const { - return *reinterpret_cast(getRawPtr()); - } - - static inline bool classof(const RValue* V) { - return isa(V) && V->getSubKind() == SymIntConstraintValKind; - } - }; - class DeclVal : public LValue { public: DeclVal(const ValueDecl* vd) : LValue(DeclValKind,vd) {}