From fa34b33e43ca9d8364286d6d6b77265c8b7c5e7c Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Wed, 9 Apr 2008 01:10:13 +0000 Subject: [PATCH] Added some boilerplate for emitting warnings from the CF-reference count checker. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@49414 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CFRefCount.cpp | 79 ++++++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/lib/Analysis/CFRefCount.cpp b/lib/Analysis/CFRefCount.cpp index 2e7b410065..d73b771b52 100644 --- a/lib/Analysis/CFRefCount.cpp +++ b/lib/Analysis/CFRefCount.cpp @@ -16,9 +16,12 @@ #include "clang/Analysis/PathSensitive/ValueState.h" #include "clang/Analysis/PathDiagnostic.h" #include "clang/Analysis/LocalCheckers.h" +#include "clang/Analysis/PathDiagnostic.h" +#include "clang/Analysis/PathSensitive/BugReporter.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/ImmutableMap.h" +#include "llvm/Support/Compiler.h" #include using namespace clang; @@ -511,6 +514,17 @@ public: GRStmtNodeBuilder& Builder, CallExpr* CE, LVal L, ExplodedNode* Pred); + + // Error iterators. + + typedef UseAfterReleasesTy::iterator use_after_iterator; + typedef ReleasesNotOwnedTy::iterator bad_release_iterator; + + use_after_iterator begin_use_after() { return UseAfterReleases.begin(); } + use_after_iterator end_use_after() { return UseAfterReleases.end(); } + + bad_release_iterator begin_bad_release() { return ReleasesNotOwned.begin(); } + bad_release_iterator end_bad_release() { return ReleasesNotOwned.end(); } }; } // end anonymous namespace @@ -771,26 +785,61 @@ CFRefCount::RefBindings CFRefCount::Update(RefBindings B, SymbolID sym, return RefBFactory.Add(B, sym, V); } + +//===----------------------------------------------------------------------===// +// Bug Descriptions. +//===----------------------------------------------------------------------===// + +namespace { + +class VISIBILITY_HIDDEN UseAfterRelease : public BugDescription { + +public: + virtual const char* getName() const { + return "(CoreFoundation) use-after-release"; + } + virtual const char* getDescription() const { + return "(CoreFoundation) Reference-counted object is used" + " after it is released."; + } +}; + +class VISIBILITY_HIDDEN BadRelease : public BugDescription { + +public: + virtual const char* getName() const { + return "(CoreFoundation) release of non-owned object"; + } + virtual const char* getDescription() const { + return "Incorrect decrement of reference count of CoreFoundation object:\n" + "The object is not owned at this point by the caller."; + } +}; + +} // end anonymous namespace + //===----------------------------------------------------------------------===// // Driver for the CFRefCount Checker. //===----------------------------------------------------------------------===// namespace clang { - void CheckCFRefCount(CFG& cfg, Decl& CD, ASTContext& Ctx, - Diagnostic& Diag, PathDiagnosticClient* PD) { - - if (Diag.hasErrorOccurred()) - return; - - // FIXME: Refactor some day so this becomes a single function invocation. - - GRCoreEngine Eng(cfg, CD, Ctx); - GRExprEngine* CS = &Eng.getCheckerState(); - CFRefCount TF; - CS->setTransferFunctions(TF); - Eng.ExecuteWorkList(20000); - - } +void CheckCFRefCount(CFG& cfg, Decl& CD, ASTContext& Ctx, + Diagnostic& Diag, PathDiagnosticClient* PD) { + + if (Diag.hasErrorOccurred()) + return; + + // FIXME: Refactor some day so this becomes a single function invocation. + GRCoreEngine Eng(cfg, CD, Ctx); + GRExprEngine* CS = &Eng.getCheckerState(); + CFRefCount TF; + CS->setTransferFunctions(TF); + Eng.ExecuteWorkList(); + + // Emit warnings. + +} + } // end clang namespace -- 2.40.0