1 //== RetainCountDiagnostics.h - Checks for leaks and other issues -*- C++ -*--//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines diagnostics for RetainCountChecker, which implements
11 // a reference count checker for Core Foundation and Cocoa on (Mac OS X).
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_DIAGNOSTICS_H
16 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_DIAGNOSTICS_H
18 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
19 #include "clang/StaticAnalyzer/Core/BugReporter/BugReporterVisitors.h"
20 #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
21 #include "clang/StaticAnalyzer/Core/RetainSummaryManager.h"
25 namespace retaincountchecker {
27 class RefCountBug : public BugType {
29 RefCountBug(const CheckerBase *checker, StringRef name)
30 : BugType(checker, name, categories::MemoryRefCount) {}
33 virtual const char *getDescription() const = 0;
35 virtual bool isLeak() const { return false; }
38 class RefCountReport : public BugReport {
43 RefCountReport(RefCountBug &D, const LangOptions &LOpts,
44 ExplodedNode *n, SymbolRef sym,
45 bool registerVisitor = true);
47 RefCountReport(RefCountBug &D, const LangOptions &LOpts,
48 ExplodedNode *n, SymbolRef sym,
51 llvm::iterator_range<ranges_iterator> getRanges() override {
52 const RefCountBug& BugTy = static_cast<RefCountBug&>(getBugType());
54 return BugReport::getRanges();
55 return llvm::make_range(ranges_iterator(), ranges_iterator());
59 class RefLeakReport : public RefCountReport {
60 const MemRegion* AllocBinding;
61 const Stmt *AllocStmt;
63 // Finds the function declaration where a leak warning for the parameter
64 // 'sym' should be raised.
65 void deriveParamLocation(CheckerContext &Ctx, SymbolRef sym);
66 // Finds the location where a leak warning for 'sym' should be raised.
67 void deriveAllocLocation(CheckerContext &Ctx, SymbolRef sym);
68 // Produces description of a leak warning which is printed on the console.
69 void createDescription(CheckerContext &Ctx);
72 RefLeakReport(RefCountBug &D, const LangOptions &LOpts, ExplodedNode *n,
73 SymbolRef sym, CheckerContext &Ctx);
75 PathDiagnosticLocation getLocation(const SourceManager &SM) const override {
76 assert(Location.isValid());
81 } // end namespace retaincountchecker
82 } // end namespace ento
83 } // end namespace clang