diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-12-16 07:46:53 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-12-16 07:46:53 +0000 |
commit | 892697dd2287caf7c29aaaa82909b0e90b8b63fe (patch) | |
tree | 0b6e5e8d01ef17d240bc41ca53a77705cba6228c /include/clang/Checker/PathSensitive | |
parent | 48263bae23707b11cfdc89944233d03089a01f97 (diff) |
Start migration of static analyzer to using the
implicit lvalue-to-rvalue casts that John McCall
recently introduced. This causes a whole bunch
of logic in the analyzer for handling lvalues
to vanish. It does, however, raise a few issues
in the analyzer w.r.t to modeling various constructs
(e.g., field accesses to compound literals).
The .c/.m analysis test cases that fail are
due to a missing lvalue-to-rvalue cast that
will get introduced into the AST. The .cpp
failures were more than I could investigate in
one go, and the patch was already getting huge.
I have XFAILED some of these tests, and they
should obviously be further investigated.
Some highlights of this patch include:
- CFG no longer requires an lvalue bit for
CFGElements
- StackFrameContext doesn't need an 'asLValue'
flag
- The "VisitLValue" path from GRExprEngine has
been eliminated.
Besides the test case failures (XFAILed), there
are surely other bugs that are fallout from
this change.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@121960 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Checker/PathSensitive')
4 files changed, 26 insertions, 45 deletions
diff --git a/include/clang/Checker/PathSensitive/AnalysisManager.h b/include/clang/Checker/PathSensitive/AnalysisManager.h index ce33269da0..473772b82e 100644 --- a/include/clang/Checker/PathSensitive/AnalysisManager.h +++ b/include/clang/Checker/PathSensitive/AnalysisManager.h @@ -178,23 +178,23 @@ public: const StackFrameContext *getStackFrame(AnalysisContext *Ctx, LocationContext const *Parent, - const Stmt *S, bool asLValue, + const Stmt *S, const CFGBlock *Blk, unsigned Idx) { - return LocCtxMgr.getStackFrame(Ctx, Parent, S, asLValue, Blk, Idx); + return LocCtxMgr.getStackFrame(Ctx, Parent, S, Blk, Idx); } // Get the top level stack frame. const StackFrameContext *getStackFrame(Decl const *D, idx::TranslationUnit *TU) { - return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D, TU), 0, 0, 0, 0, 0); + return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D, TU), 0, 0, 0, 0); } // Get a stack frame with parent. StackFrameContext const *getStackFrame(const Decl *D, LocationContext const *Parent, - const Stmt *S, bool asLValue, + const Stmt *S, const CFGBlock *Blk, unsigned Idx) { - return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D), Parent, S, asLValue, + return LocCtxMgr.getStackFrame(AnaCtxMgr.getContext(D), Parent, S, Blk,Idx); } }; diff --git a/include/clang/Checker/PathSensitive/CheckerVisitor.def b/include/clang/Checker/PathSensitive/CheckerVisitor.def index 4f9c48c2fe..3ee8071985 100644 --- a/include/clang/Checker/PathSensitive/CheckerVisitor.def +++ b/include/clang/Checker/PathSensitive/CheckerVisitor.def @@ -22,9 +22,12 @@ PREVISIT(ArraySubscriptExpr, Stmt) PREVISIT(BinaryOperator, Stmt) PREVISIT(CallExpr, GenericCall) +PREVISIT(CStyleCastExpr, CastExpr) +PREVISIT(CXXFunctionalCastExpr, CastExpr) PREVISIT(CXXOperatorCallExpr, GenericCall) PREVISIT(CXXMemberCallExpr, GenericCall) PREVISIT(DeclStmt, Stmt) +PREVISIT(ImplicitCastExpr, CastExpr) PREVISIT(ObjCAtSynchronizedStmt, Stmt) PREVISIT(ObjCMessageExpr, Stmt) PREVISIT(ReturnStmt, Stmt) diff --git a/include/clang/Checker/PathSensitive/CheckerVisitor.h b/include/clang/Checker/PathSensitive/CheckerVisitor.h index 6d45bd3546..241d9e39ad 100644 --- a/include/clang/Checker/PathSensitive/CheckerVisitor.h +++ b/include/clang/Checker/PathSensitive/CheckerVisitor.h @@ -40,13 +40,6 @@ public: default: assert(false && "Unsupport statement."); return; - - case Stmt::ImplicitCastExprClass: - case Stmt::CStyleCastExprClass: - static_cast<ImplClass*>(this)->PreVisitCastExpr(C, - static_cast<const CastExpr*>(S)); - break; - case Stmt::CompoundAssignOperatorClass: static_cast<ImplClass*>(this)->PreVisitBinaryOperator(C, static_cast<const BinaryOperator*>(S)); diff --git a/include/clang/Checker/PathSensitive/GRExprEngine.h b/include/clang/Checker/PathSensitive/GRExprEngine.h index 2a0298f963..0b44c32ec3 100644 --- a/include/clang/Checker/PathSensitive/GRExprEngine.h +++ b/include/clang/Checker/PathSensitive/GRExprEngine.h @@ -297,14 +297,10 @@ public: /// other functions that handle specific kinds of statements. void Visit(const Stmt* S, ExplodedNode* Pred, ExplodedNodeSet& Dst); - /// VisitLValue - evaluate the lvalue of the expression. For example, if Ex is - /// a DeclRefExpr, it evaluates to the MemRegionVal which represents its - /// storage location. Note that not all kinds of expressions has lvalue. - void VisitLValue(const Expr* Ex, ExplodedNode* Pred, ExplodedNodeSet& Dst); - /// VisitArraySubscriptExpr - Transfer function for array accesses. - void VisitArraySubscriptExpr(const ArraySubscriptExpr* Ex, ExplodedNode* Pred, - ExplodedNodeSet& Dst, bool asLValue); + void VisitLvalArraySubscriptExpr(const ArraySubscriptExpr* Ex, + ExplodedNode* Pred, + ExplodedNodeSet& Dst); /// VisitAsmStmt - Transfer function logic for inline asm. void VisitAsmStmt(const AsmStmt* A, ExplodedNode* Pred, ExplodedNodeSet& Dst); @@ -325,35 +321,26 @@ public: /// VisitBinaryOperator - Transfer function logic for binary operators. void VisitBinaryOperator(const BinaryOperator* B, ExplodedNode* Pred, - ExplodedNodeSet& Dst, bool asLValue); + ExplodedNodeSet& Dst); /// VisitCall - Transfer function for function calls. void VisitCall(const CallExpr* CE, ExplodedNode* Pred, CallExpr::const_arg_iterator AI, CallExpr::const_arg_iterator AE, - ExplodedNodeSet& Dst, bool asLValue); + ExplodedNodeSet& Dst); /// VisitCast - Transfer function logic for all casts (implicit and explicit). void VisitCast(const CastExpr *CastE, const Expr *Ex, ExplodedNode *Pred, - ExplodedNodeSet &Dst, bool asLValue); + ExplodedNodeSet &Dst); /// VisitCompoundLiteralExpr - Transfer function logic for compound literals. void VisitCompoundLiteralExpr(const CompoundLiteralExpr* CL, - ExplodedNode* Pred, ExplodedNodeSet& Dst, - bool asLValue); - - /// VisitDeclRefExpr - Transfer function logic for DeclRefExprs. - void VisitDeclRefExpr(const DeclRefExpr* DR, ExplodedNode* Pred, - ExplodedNodeSet& Dst, bool asLValue); + ExplodedNode* Pred, ExplodedNodeSet& Dst); - /// VisitBlockDeclRefExpr - Transfer function logic for BlockDeclRefExprs. - void VisitBlockDeclRefExpr(const BlockDeclRefExpr* DR, ExplodedNode* Pred, - ExplodedNodeSet& Dst, bool asLValue); - + /// Transfer function logic for DeclRefExprs and BlockDeclRefExprs. void VisitCommonDeclRefExpr(const Expr* DR, const NamedDecl *D, - ExplodedNode* Pred, ExplodedNodeSet& Dst, - bool asLValue); + ExplodedNode* Pred, ExplodedNodeSet& Dst); /// VisitDeclStmt - Transfer function logic for DeclStmts. void VisitDeclStmt(const DeclStmt* DS, ExplodedNode* Pred, @@ -377,15 +364,15 @@ public: /// VisitMemberExpr - Transfer function for member expressions. void VisitMemberExpr(const MemberExpr* M, ExplodedNode* Pred, - ExplodedNodeSet& Dst, bool asLValue); + ExplodedNodeSet& Dst); /// Transfer function logic for ObjCAtSynchronizedStmts. void VisitObjCAtSynchronizedStmt(const ObjCAtSynchronizedStmt *S, ExplodedNode *Pred, ExplodedNodeSet &Dst); - /// VisitObjCIvarRefExpr - Transfer function logic for ObjCIvarRefExprs. - void VisitObjCIvarRefExpr(const ObjCIvarRefExpr* DR, ExplodedNode* Pred, - ExplodedNodeSet& Dst, bool asLValue); + /// Transfer function logic for computing the lvalue of an Objective-C ivar. + void VisitLvalObjCIvarRefExpr(const ObjCIvarRefExpr* DR, ExplodedNode* Pred, + ExplodedNodeSet& Dst); /// VisitObjCForCollectionStmt - Transfer function logic for /// ObjCForCollectionStmt. @@ -398,7 +385,7 @@ public: /// VisitObjCMessageExpr - Transfer function for ObjC message expressions. void VisitObjCMessageExpr(const ObjCMessageExpr* ME, ExplodedNode* Pred, - ExplodedNodeSet& Dst, bool asLValue); + ExplodedNodeSet& Dst); /// VisitReturnStmt - Transfer function logic for return statements. void VisitReturnStmt(const ReturnStmt* R, ExplodedNode* Pred, @@ -414,20 +401,18 @@ public: /// VisitUnaryOperator - Transfer function logic for unary operators. void VisitUnaryOperator(const UnaryOperator* B, ExplodedNode* Pred, - ExplodedNodeSet& Dst, bool asLValue); + ExplodedNodeSet& Dst); void VisitCXXThisExpr(const CXXThisExpr *TE, ExplodedNode *Pred, ExplodedNodeSet & Dst); void VisitCXXTemporaryObjectExpr(const CXXTemporaryObjectExpr *expr, - ExplodedNode *Pred, ExplodedNodeSet &Dst, - bool asLValue) { - VisitCXXConstructExpr(expr, 0, Pred, Dst, asLValue); + ExplodedNode *Pred, ExplodedNodeSet &Dst) { + VisitCXXConstructExpr(expr, 0, Pred, Dst); } void VisitCXXConstructExpr(const CXXConstructExpr *E, const MemRegion *Dest, - ExplodedNode *Pred, ExplodedNodeSet &Dst, - bool asLValue); + ExplodedNode *Pred, ExplodedNodeSet &Dst); void VisitCXXDestructor(const CXXDestructorDecl *DD, const MemRegion *Dest, const Stmt *S, |