From acdde6f099e797ecc366cf39381fae632f2eff2e Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Fri, 9 May 2008 23:45:33 +0000 Subject: [PATCH] Rename IsPointerType to LVal::IsLValType, and update CFRefCount::EvalSummary to use IsLValType when conjuring symbols for return values (this fixes a bug with an assertion firing in the analyzer when two qualified objective-c types were compared). llvm-svn: 50924 --- .../Analysis/PathSensitive/GRExprEngine.h | 12 ------------ .../clang/Analysis/PathSensitive/RValues.h | 4 ++++ clang/lib/Analysis/CFRefCount.cpp | 6 +++--- clang/lib/Analysis/GRExprEngine.cpp | 18 +++++++++--------- clang/lib/Analysis/GRSimpleVals.cpp | 10 +++++----- 5 files changed, 21 insertions(+), 29 deletions(-) diff --git a/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h b/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h index 7caa200326fe..fb8af773c1bf 100644 --- a/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h +++ b/clang/include/clang/Analysis/PathSensitive/GRExprEngine.h @@ -648,18 +648,6 @@ protected: ValueState* MarkBranch(ValueState* St, Stmt* Terminator, bool branchTaken); }; -} // end clang namespace - - -//===----------------------------------------------------------------------===// -// Utility -//===----------------------------------------------------------------------===// - -namespace clang { - -static inline bool IsPointerType(QualType T) { - return T->isPointerType() || T->isObjCQualifiedIdType(); -} } // end clang namespace diff --git a/clang/include/clang/Analysis/PathSensitive/RValues.h b/clang/include/clang/Analysis/PathSensitive/RValues.h index 9db6850be68e..5a010dd0dc80 100644 --- a/clang/include/clang/Analysis/PathSensitive/RValues.h +++ b/clang/include/clang/Analysis/PathSensitive/RValues.h @@ -157,6 +157,10 @@ public: static inline bool classof(const RVal* V) { return V->getBaseKind() == LValKind; } + + static inline bool IsLValType(QualType T) { + return T->isPointerType() || T->isObjCQualifiedIdType(); + } }; //==------------------------------------------------------------------------==// diff --git a/clang/lib/Analysis/CFRefCount.cpp b/clang/lib/Analysis/CFRefCount.cpp index 7a9d608b71ce..fd47f03d3e12 100644 --- a/clang/lib/Analysis/CFRefCount.cpp +++ b/clang/lib/Analysis/CFRefCount.cpp @@ -1230,9 +1230,9 @@ void CFRefCount::EvalSummary(ExplodedNodeSet& Dst, unsigned Count = Builder.getCurrentBlockCount(); SymbolID Sym = Eng.getSymbolManager().getConjuredSymbol(Ex, Count); - RVal X = Ex->getType()->isPointerType() - ? cast(lval::SymbolVal(Sym)) - : cast(nonlval::SymbolVal(Sym)); + RVal X = LVal::IsLValType(Ex->getType()) + ? cast(lval::SymbolVal(Sym)) + : cast(nonlval::SymbolVal(Sym)); St = StateMgr.SetRVal(St, Ex, X, Eng.getCFG().isBlkExpr(Ex), false); } diff --git a/clang/lib/Analysis/GRExprEngine.cpp b/clang/lib/Analysis/GRExprEngine.cpp index e34d180283b2..a974c7a6b0c4 100644 --- a/clang/lib/Analysis/GRExprEngine.cpp +++ b/clang/lib/Analysis/GRExprEngine.cpp @@ -795,7 +795,7 @@ void GRExprEngine::VisitArraySubscriptExpr(ArraySubscriptExpr* A, NodeTy* Pred, // abstract address of the base object. NodeSet Tmp; - if (IsPointerType(Base->getType())) // Base always is an LVal. + if (LVal::IsLValType(Base->getType())) // Base always is an LVal. Visit(Base, Pred, Tmp); else VisitLVal(Base, Pred, Tmp); @@ -842,7 +842,7 @@ void GRExprEngine::VisitMemberExpr(MemberExpr* M, NodeTy* Pred, if (asLVal) { - if (IsPointerType(Base->getType())) // Base always is an LVal. + if (LVal::IsLValType(Base->getType())) // Base always is an LVal. Visit(Base, Pred, Tmp); else VisitLVal(Base, Pred, Tmp); @@ -869,7 +869,7 @@ void GRExprEngine::VisitMemberExpr(MemberExpr* M, NodeTy* Pred, ValueState* St = GetState(*I); RVal BaseV = GetRVal(St, Base); - if (IsPointerType(Base->getType())) { + if (LVal::IsLValType(Base->getType())) { assert (M->isArrow()); @@ -1389,7 +1389,7 @@ void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst){ } // Check for casts from pointers to integers. - if (T->isIntegerType() && IsPointerType(ExTy)) { + if (T->isIntegerType() && LVal::IsLValType(ExTy)) { unsigned bits = getContext().getTypeSize(ExTy); // FIXME: Determine if the number of bits of the target type is @@ -1402,7 +1402,7 @@ void GRExprEngine::VisitCast(Expr* CastE, Expr* Ex, NodeTy* Pred, NodeSet& Dst){ } // Check for casts from integers to pointers. - if (IsPointerType(T) && ExTy->isIntegerType()) + if (LVal::IsLValType(T) && ExTy->isIntegerType()) if (nonlval::LValAsInteger *LV = dyn_cast(&V)) { // Just unpackage the lval and return it. V = LV->getLVal(); @@ -1481,7 +1481,7 @@ void GRExprEngine::VisitDeclStmtAux(DeclStmt* DS, ScopedDecl* D, QualType T = VD->getType(); - if (IsPointerType(T)) + if (LVal::IsLValType(T)) St = SetRVal(St, lval::DeclVal(VD), lval::ConcreteInt(BasicVals.getValue(0, T))); else if (T->isIntegerType()) @@ -1499,7 +1499,7 @@ void GRExprEngine::VisitDeclStmtAux(DeclStmt* DS, ScopedDecl* D, QualType T = VD->getType(); - if (IsPointerType(T) || T->isIntegerType()) { + if (LVal::IsLValType(T) || T->isIntegerType()) { RVal V = Ex ? GetRVal(St, Ex) : UndefinedVal(); @@ -1510,7 +1510,7 @@ void GRExprEngine::VisitDeclStmtAux(DeclStmt* DS, ScopedDecl* D, unsigned Count = Builder->getCurrentBlockCount(); SymbolID Sym = SymMgr.getConjuredSymbol(Ex, Count); - V = IsPointerType(Ex->getType()) + V = LVal::IsLValType(Ex->getType()) ? cast(lval::SymbolVal(Sym)) : cast(nonlval::SymbolVal(Sym)); } @@ -1965,7 +1965,7 @@ void GRExprEngine::VisitBinaryOperator(BinaryOperator* B, unsigned Count = Builder->getCurrentBlockCount(); SymbolID Sym = SymMgr.getConjuredSymbol(B->getRHS(), Count); - RightV = IsPointerType(B->getRHS()->getType()) + RightV = LVal::IsLValType(B->getRHS()->getType()) ? cast(lval::SymbolVal(Sym)) : cast(nonlval::SymbolVal(Sym)); } diff --git a/clang/lib/Analysis/GRSimpleVals.cpp b/clang/lib/Analysis/GRSimpleVals.cpp index f6053dc418c7..b57cb57c3244 100644 --- a/clang/lib/Analysis/GRSimpleVals.cpp +++ b/clang/lib/Analysis/GRSimpleVals.cpp @@ -379,10 +379,10 @@ RVal GRSimpleVals::EvalCast(GRExprEngine& Eng, NonLVal X, QualType T) { BasicValueFactory& BasicVals = Eng.getBasicVals(); llvm::APSInt V = cast(X).getValue(); - V.setIsUnsigned(T->isUnsignedIntegerType() || IsPointerType(T)); + V.setIsUnsigned(T->isUnsignedIntegerType() || LVal::IsLValType(T)); V.extOrTrunc(Eng.getContext().getTypeSize(T)); - if (IsPointerType(T)) + if (LVal::IsLValType(T)) return lval::ConcreteInt(BasicVals.getValue(V)); else return nonlval::ConcreteInt(BasicVals.getValue(V)); @@ -398,7 +398,7 @@ RVal GRSimpleVals::EvalCast(GRExprEngine& Eng, LVal X, QualType T) { // can be introduced by the frontend for corner cases, e.g // casting from va_list* to __builtin_va_list&. // - if (IsPointerType(T) || T->isReferenceType()) + if (LVal::IsLValType(T) || T->isReferenceType()) return X; assert (T->isIntegerType()); @@ -409,7 +409,7 @@ RVal GRSimpleVals::EvalCast(GRExprEngine& Eng, LVal X, QualType T) { BasicValueFactory& BasicVals = Eng.getBasicVals(); llvm::APSInt V = cast(X).getValue(); - V.setIsUnsigned(T->isUnsignedIntegerType() || IsPointerType(T)); + V.setIsUnsigned(T->isUnsignedIntegerType() || LVal::IsLValType(T)); V.extOrTrunc(Eng.getContext().getTypeSize(T)); return nonlval::ConcreteInt(BasicVals.getValue(V)); @@ -672,7 +672,7 @@ void GRSimpleVals::EvalCall(ExplodedNodeSet& Dst, unsigned Count = Builder.getCurrentBlockCount(); SymbolID Sym = Eng.getSymbolManager().getConjuredSymbol(CE, Count); - RVal X = IsPointerType(CE->getType()) + RVal X = LVal::IsLValType(CE->getType()) ? cast(lval::SymbolVal(Sym)) : cast(nonlval::SymbolVal(Sym));