]> granicus.if.org Git - clang/commitdiff
Tie the local check NSErrorCheck to a Decl to pave the way
authorZhongxing Xu <xuzhongxing@gmail.com>
Fri, 21 Aug 2009 02:18:44 +0000 (02:18 +0000)
committerZhongxing Xu <xuzhongxing@gmail.com>
Fri, 21 Aug 2009 02:18:44 +0000 (02:18 +0000)
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

include/clang/Analysis/LocalCheckers.h
lib/Analysis/BasicObjCFoundationChecks.cpp
lib/Analysis/BasicObjCFoundationChecks.h
lib/Analysis/CheckNSError.cpp
lib/Frontend/AnalysisConsumer.cpp

index 88fc8797abc7a78764d8efd8df9218f5c080f1b6..2322f5ebb7a4f6633c55f37a6080029bceeba2e7 100644 (file)
@@ -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);
 
index 6e9dd909fcde24743ff19a516260832c990ec5d4..88910990ce29d255697416a3c2baaec0476c0f79 100644 (file)
@@ -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);
 }
index 13f55fcb969bf6f97c4da38e19890237730ed316..8aa996095b9b326133a7b4c2556e1c3c166ba9c1 100644 (file)
@@ -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
 
index b9599ceb6ab27234f3ce361dba4354c8e39ea7ec..f152d4451d8d26958fe20dcb53eaf46db72e24bc 100644 (file)
@@ -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();    
     
index 16639e037199806097d036125b0e76df02ef7a0c..2b718d56fcf759c250b66d4481cb291c01fa425a 100644 (file)
@@ -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.