[cfe-commits] r79588 - in /cfe/trunk: include/clang/Analysis/LocalCheckers.h lib/Analysis/BasicObjCFoundationChecks.cpp lib/Analysis/BasicObjCFoundationChecks.h lib/Analysis/CheckNSError.cpp lib/Frontend/AnalysisConsumer.cpp
Zhongxing Xu
xuzhongxing at gmail.com
Thu Aug 20 19:18:44 PDT 2009
Author: zhongxingxu
Date: Thu Aug 20 21:18:44 2009
New Revision: 79588
URL: http://llvm.org/viewvc/llvm-project?rev=79588&view=rev
Log:
Tie the local check NSErrorCheck to a Decl to pave the way
to untie the ExplodedGraph from a specific Decl.
Modified:
cfe/trunk/include/clang/Analysis/LocalCheckers.h
cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.h
cfe/trunk/lib/Analysis/CheckNSError.cpp
cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
Modified: cfe/trunk/include/clang/Analysis/LocalCheckers.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/LocalCheckers.h?rev=79588&r1=79587&r2=79588&view=diff
==============================================================================
--- cfe/trunk/include/clang/Analysis/LocalCheckers.h (original)
+++ cfe/trunk/include/clang/Analysis/LocalCheckers.h Thu Aug 20 21:18:44 2009
@@ -46,7 +46,7 @@
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);
Modified: cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp?rev=79588&r1=79587&r2=79588&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp (original)
+++ cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.cpp Thu Aug 20 21:18:44 2009
@@ -535,7 +535,7 @@
// 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 @@
Eng.AddCheck(CreateAuditCFNumberCreate(Ctx, BR), Stmt::CallExprClass);
Eng.AddCheck(CreateAuditCFRetainRelease(Ctx, BR), Stmt::CallExprClass);
- RegisterNSErrorChecks(BR, Eng);
+ RegisterNSErrorChecks(BR, Eng, D);
}
Modified: cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.h?rev=79588&r1=79587&r2=79588&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.h (original)
+++ cfe/trunk/lib/Analysis/BasicObjCFoundationChecks.h Thu Aug 20 21:18:44 2009
@@ -41,7 +41,7 @@
GRSimpleAPICheck *CreateAuditCFRetainRelease(ASTContext& Ctx,
BugReporter& BR);
-void RegisterNSErrorChecks(BugReporter& BR, GRExprEngine &Eng);
+void RegisterNSErrorChecks(BugReporter& BR, GRExprEngine &Eng, const Decl &D);
} // end clang namespace
Modified: cfe/trunk/lib/Analysis/CheckNSError.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CheckNSError.cpp?rev=79588&r1=79587&r2=79588&view=diff
==============================================================================
--- cfe/trunk/lib/Analysis/CheckNSError.cpp (original)
+++ cfe/trunk/lib/Analysis/CheckNSError.cpp Thu Aug 20 21:18:44 2009
@@ -28,14 +28,15 @@
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 @@
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 @@
} // 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::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::CheckSignature(ObjCMethodDecl& M, QualType& ResultTy,
+NSErrorCheck::CheckSignature(const ObjCMethodDecl& M, QualType& ResultTy,
llvm::SmallVectorImpl<VarDecl*>& ErrorParams) {
ResultTy = M.getResultType();
@@ -140,13 +140,13 @@
}
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();
Modified: cfe/trunk/lib/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/AnalysisConsumer.cpp?rev=79588&r1=79587&r2=79588&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/Frontend/AnalysisConsumer.cpp Thu Aug 20 21:18:44 2009
@@ -304,7 +304,7 @@
if (StandardWarnings) {
Eng.RegisterInternalChecks();
- RegisterAppleChecks(Eng);
+ RegisterAppleChecks(Eng, *mgr.getCodeDecl());
}
// Set the graph auditor.
More information about the cfe-commits
mailing list