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 
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:
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:
73  SymbolRef sym, CheckerContext &Ctx);
74 
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
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:95
Stmt - This represents one statement.
Definition: Stmt.h:66
Symbolic value.
Definition: SymExpr.h:30
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:50
llvm::iterator_range< ranges_iterator > getRanges() override
Get the SourceRanges associated with the report.
virtual llvm::iterator_range< ranges_iterator > getRanges()
Get the SourceRanges associated with the report.
const char *const MemoryRefCount
PathDiagnosticLocation getLocation(const SourceManager &SM) const override
Return the "definitive" location of the reported bug.
virtual const char * getDescription() const =0
const SourceManager & SM
Definition: Format.cpp:1490
Dataflow Directional Tag Classes.
RefCountBug(const CheckerBase *checker, StringRef name)
A trivial tuple used to represent a source range.
This class provides an interface through which checkers can create individual bug reports...
Definition: BugReporter.h:76
This class handles loading and caching of source files into memory.