clang 8.0.0

RetainCountDiagnostics.h
Go to the documentation of this file.
1 //== RetainCountDiagnostics.h - Checks for leaks and other issues -*- C++ -*--//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines diagnostics for RetainCountChecker, which implements
11 // a reference count checker for Core Foundation and Cocoa on (Mac OS X).
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_DIAGNOSTICS_H
16 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_DIAGNOSTICS_H
17
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"
22
23 namespace clang {
24 namespace ento {
25 namespace retaincountchecker {
26
27 class RefCountBug : public BugType {
28 protected:
29 RefCountBug(const CheckerBase *checker, StringRef name)
30 : BugType(checker, name, categories::MemoryRefCount) {}
31
32 public:
33 virtual const char *getDescription() const = 0;
34
35 virtual bool isLeak() const { return false; }
36 };
37
38 class RefCountReport : public BugReport {
39 protected:
40 SymbolRef Sym;
41
42 public:
43 RefCountReport(RefCountBug &D, const LangOptions &LOpts,
44 ExplodedNode *n, SymbolRef sym,
45 bool registerVisitor = true);
46
47 RefCountReport(RefCountBug &D, const LangOptions &LOpts,
48 ExplodedNode *n, SymbolRef sym,
49 StringRef endText);
50
51 llvm::iterator_range<ranges_iterator> getRanges() override {
52 const RefCountBug& BugTy = static_cast<RefCountBug&>(getBugType());
53 if (!BugTy.isLeak())
54 return BugReport::getRanges();
55 return llvm::make_range(ranges_iterator(), ranges_iterator());
56 }
57 };
58
59 class RefLeakReport : public RefCountReport {
60 const MemRegion* AllocBinding;
61 const Stmt *AllocStmt;
62
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);
70
71 public:
72 RefLeakReport(RefCountBug &D, const LangOptions &LOpts, ExplodedNode *n,
73 SymbolRef sym, CheckerContext &Ctx);
74
75 PathDiagnosticLocation getLocation(const SourceManager &SM) const override {
76 assert(Location.isValid());
77 return Location;
78 }
79 };
80
81 } // end namespace retaincountchecker
82 } // end namespace ento
83 } // end namespace clang
84
85 #endif
ento
clang::ento::MemRegion
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:95
clang::ento::retaincountchecker::RefCountReport::Sym
SymbolRef Sym
Definition: RetainCountDiagnostics.h:40
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:66
clang::ento::retaincountchecker::RefCountBug
Definition: RetainCountDiagnostics.h:27
retaincountchecker
BugType.h
clang::ento::SymExpr
Symbolic value.
Definition: SymExpr.h:30
clang::ento::PathDiagnosticLocation
Definition: PathDiagnostic.h:156
clang::ento::ExplodedNode
Definition: ExplodedGraph.h:66
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
clang::ento::retaincountchecker::RefCountReport::getRanges
llvm::iterator_range< ranges_iterator > getRanges() override
Get the SourceRanges associated with the report.
Definition: RetainCountDiagnostics.h:51
clang::ento::BugReport::getRanges
virtual llvm::iterator_range< ranges_iterator > getRanges()
Get the SourceRanges associated with the report.
Definition: BugReporter.cpp:2196
clang::ento::categories::MemoryRefCount
const char *const MemoryRefCount
Definition: CommonBugCategories.cpp:17
clang::ento::CheckerContext
Definition: CheckerContext.h:24
clang::ento::retaincountchecker::RefLeakReport::getLocation
PathDiagnosticLocation getLocation(const SourceManager &SM) const override
Return the "definitive" location of the reported bug.
Definition: RetainCountDiagnostics.h:75
clang::ento::retaincountchecker::RefCountBug::getDescription
virtual const char * getDescription() const =0
clang::ento::retaincountchecker::RefCountBug::isLeak
virtual bool isLeak() const
Definition: RetainCountDiagnostics.h:35
PathDiagnostic.h
BugReporterVisitors.h
RetainSummaryManager.h
SM
const SourceManager & SM
Definition: Format.cpp:1490
clang
Dataflow Directional Tag Classes.
Definition: CFGReachabilityAnalysis.h:22
clang::ento::BugType
Definition: BugType.h:30
clang::ento::CheckerBase
Definition: Checker.h:491
clang::ento::retaincountchecker::RefLeakReport
Definition: RetainCountDiagnostics.h:59
clang::ento::retaincountchecker::RefCountReport
Definition: RetainCountDiagnostics.h:38
clang::ento::retaincountchecker::RefCountBug::RefCountBug
RefCountBug(const CheckerBase *checker, StringRef name)
Definition: RetainCountDiagnostics.h:29
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:198
clang::ento::BugReport
This class provides an interface through which checkers can create individual bug reports...
Definition: BugReporter.h:76
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:582