diff options
author | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-08-21 02:18:44 +0000 |
---|---|---|
committer | Zhongxing Xu <xuzhongxing@gmail.com> | 2009-08-21 02:18:44 +0000 |
commit | 5ab128b02d3b10413fb30738ec9f401dcfb47252 (patch) | |
tree | 9ffe3e7f1e19d17190915bf55b4f5aa4442da7ad | |
parent | b9871a253d351e8776cfa5483d6330d5dffe4562 (diff) |
Tie the local check NSErrorCheck to a Decl to pave the way
to untie the ExplodedGraph from a specific Decl.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@79588 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Analysis/LocalCheckers.h | 2 | ||||
-rw-r--r-- | lib/Analysis/BasicObjCFoundationChecks.cpp | 4 | ||||
-rw-r--r-- | lib/Analysis/BasicObjCFoundationChecks.h | 2 | ||||
-rw-r--r-- | lib/Analysis/CheckNSError.cpp | 40 | ||||
-rw-r--r-- | lib/Frontend/AnalysisConsumer.cpp | 2 |
5 files changed, 25 insertions, 25 deletions
diff --git a/include/clang/Analysis/LocalCheckers.h b/include/clang/Analysis/LocalCheckers.h index 88fc8797ab..2322f5ebb7 100644 --- a/include/clang/Analysis/LocalCheckers.h +++ b/include/clang/Analysis/LocalCheckers.h @@ -46,7 +46,7 @@ void CheckObjCDealloc(ObjCImplementationDecl* D, const LangOptions& L, void CheckObjCInstMethSignature(ObjCImplementationDecl* ID, BugReporter& BR); void CheckObjCUnusedIvar(ObjCImplementationDecl* D, BugReporter& BR); -void RegisterAppleChecks(GRExprEngine& Eng); +void RegisterAppleChecks(GRExprEngine& Eng, const Decl &D); void CheckSecuritySyntaxOnly(Decl *D, BugReporter &BR); diff --git a/lib/Analysis/BasicObjCFoundationChecks.cpp b/lib/Analysis/BasicObjCFoundationChecks.cpp index 6e9dd909fc..88910990ce 100644 --- a/lib/Analysis/BasicObjCFoundationChecks.cpp +++ b/lib/Analysis/BasicObjCFoundationChecks.cpp @@ -535,7 +535,7 @@ clang::CreateAuditCFRetainRelease(ASTContext& Ctx, BugReporter& BR) { // Check registration. //===----------------------------------------------------------------------===// -void clang::RegisterAppleChecks(GRExprEngine& Eng) { +void clang::RegisterAppleChecks(GRExprEngine& Eng, const Decl &D) { ASTContext& Ctx = Eng.getContext(); BugReporter &BR = Eng.getBugReporter(); @@ -544,5 +544,5 @@ void clang::RegisterAppleChecks(GRExprEngine& Eng) { Eng.AddCheck(CreateAuditCFNumberCreate(Ctx, BR), Stmt::CallExprClass); Eng.AddCheck(CreateAuditCFRetainRelease(Ctx, BR), Stmt::CallExprClass); - RegisterNSErrorChecks(BR, Eng); + RegisterNSErrorChecks(BR, Eng, D); } diff --git a/lib/Analysis/BasicObjCFoundationChecks.h b/lib/Analysis/BasicObjCFoundationChecks.h index 13f55fcb96..8aa996095b 100644 --- a/lib/Analysis/BasicObjCFoundationChecks.h +++ b/lib/Analysis/BasicObjCFoundationChecks.h @@ -41,7 +41,7 @@ GRSimpleAPICheck *CreateAuditCFNumberCreate(ASTContext& Ctx, GRSimpleAPICheck *CreateAuditCFRetainRelease(ASTContext& Ctx, BugReporter& BR); -void RegisterNSErrorChecks(BugReporter& BR, GRExprEngine &Eng); +void RegisterNSErrorChecks(BugReporter& BR, GRExprEngine &Eng, const Decl &D); } // end clang namespace diff --git a/lib/Analysis/CheckNSError.cpp b/lib/Analysis/CheckNSError.cpp index b9599ceb6a..f152d4451d 100644 --- a/lib/Analysis/CheckNSError.cpp +++ b/lib/Analysis/CheckNSError.cpp @@ -28,14 +28,15 @@ using namespace clang; namespace { class VISIBILITY_HIDDEN NSErrorCheck : public BugType { + const Decl &CodeDecl; const bool isNSErrorWarning; IdentifierInfo * const II; GRExprEngine &Eng; - void CheckSignature(ObjCMethodDecl& MD, QualType& ResultTy, + void CheckSignature(const ObjCMethodDecl& MD, QualType& ResultTy, llvm::SmallVectorImpl<VarDecl*>& ErrorParams); - void CheckSignature(FunctionDecl& MD, QualType& ResultTy, + void CheckSignature(const FunctionDecl& MD, QualType& ResultTy, llvm::SmallVectorImpl<VarDecl*>& ErrorParams); bool CheckNSErrorArgument(QualType ArgTy); @@ -43,13 +44,14 @@ class VISIBILITY_HIDDEN NSErrorCheck : public BugType { void CheckParamDeref(VarDecl* V, const GRState *state, BugReporter& BR); - void EmitRetTyWarning(BugReporter& BR, Decl& CodeDecl); + void EmitRetTyWarning(BugReporter& BR, const Decl& CodeDecl); public: - NSErrorCheck(bool isNSError, GRExprEngine& eng) - : BugType(isNSError ? "NSError** null dereference" - : "CFErrorRef* null dereference", - "Coding Conventions (Apple)"), + NSErrorCheck(const Decl &D, bool isNSError, GRExprEngine& eng) + : BugType(isNSError ? "NSError** null dereference" + : "CFErrorRef* null dereference", + "Coding Conventions (Apple)"), + CodeDecl(D), isNSErrorWarning(isNSError), II(&eng.getContext().Idents.get(isNSErrorWarning ? "NSError":"CFErrorRef")), Eng(eng) {} @@ -59,27 +61,25 @@ public: } // end anonymous namespace -void clang::RegisterNSErrorChecks(BugReporter& BR, GRExprEngine &Eng) { - BR.Register(new NSErrorCheck(true, Eng)); - BR.Register(new NSErrorCheck(false, Eng)); +void clang::RegisterNSErrorChecks(BugReporter& BR, GRExprEngine &Eng, + const Decl &D) { + BR.Register(new NSErrorCheck(D, true, Eng)); + BR.Register(new NSErrorCheck(D, false, Eng)); } void NSErrorCheck::FlushReports(BugReporter& BR) { // Get the analysis engine and the exploded analysis graph. ExplodedGraph& G = Eng.getGraph(); - // Get the declaration of the method/function that was analyzed. - Decl& CodeDecl = G.getCodeDecl(); - // Get the ASTContext, which is useful for querying type information. ASTContext &Ctx = BR.getContext(); QualType ResultTy; llvm::SmallVector<VarDecl*, 5> ErrorParams; - if (ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(&CodeDecl)) + if (const ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(&CodeDecl)) CheckSignature(*MD, ResultTy, ErrorParams); - else if (FunctionDecl* FD = dyn_cast<FunctionDecl>(&CodeDecl)) + else if (const FunctionDecl* FD = dyn_cast<FunctionDecl>(&CodeDecl)) CheckSignature(*FD, ResultTy, ErrorParams); else return; @@ -99,7 +99,7 @@ void NSErrorCheck::FlushReports(BugReporter& BR) { } } -void NSErrorCheck::EmitRetTyWarning(BugReporter& BR, Decl& CodeDecl) { +void NSErrorCheck::EmitRetTyWarning(BugReporter& BR, const Decl& CodeDecl) { std::string sbuf; llvm::raw_string_ostream os(sbuf); @@ -121,7 +121,7 @@ void NSErrorCheck::EmitRetTyWarning(BugReporter& BR, Decl& CodeDecl) { } void -NSErrorCheck::CheckSignature(ObjCMethodDecl& M, QualType& ResultTy, +NSErrorCheck::CheckSignature(const ObjCMethodDecl& M, QualType& ResultTy, llvm::SmallVectorImpl<VarDecl*>& ErrorParams) { ResultTy = M.getResultType(); @@ -140,13 +140,13 @@ NSErrorCheck::CheckSignature(ObjCMethodDecl& M, QualType& ResultTy, } void -NSErrorCheck::CheckSignature(FunctionDecl& F, QualType& ResultTy, +NSErrorCheck::CheckSignature(const FunctionDecl& F, QualType& ResultTy, llvm::SmallVectorImpl<VarDecl*>& ErrorParams) { ResultTy = F.getResultType(); - for (FunctionDecl::param_iterator I=F.param_begin(), - E=F.param_end(); I!=E; ++I) { + for (FunctionDecl::param_const_iterator I = F.param_begin(), + E = F.param_end(); I != E; ++I) { QualType T = (*I)->getType(); diff --git a/lib/Frontend/AnalysisConsumer.cpp b/lib/Frontend/AnalysisConsumer.cpp index 16639e0371..2b718d56fc 100644 --- a/lib/Frontend/AnalysisConsumer.cpp +++ b/lib/Frontend/AnalysisConsumer.cpp @@ -304,7 +304,7 @@ static void ActionGRExprEngine(AnalysisManager& mgr, GRTransferFuncs* tf, if (StandardWarnings) { Eng.RegisterInternalChecks(); - RegisterAppleChecks(Eng); + RegisterAppleChecks(Eng, *mgr.getCodeDecl()); } // Set the graph auditor. |