clang  9.0.0
RetainCountDiagnostics.h
Go to the documentation of this file.
1 //== RetainCountDiagnostics.h - Checks for leaks and other issues -*- C++ -*--//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines diagnostics for RetainCountChecker, which implements
10 // a reference count checker for Core Foundation and Cocoa on (Mac OS X).
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_DIAGNOSTICS_H
15 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_DIAGNOSTICS_H
16 
22 
23 namespace clang {
24 namespace ento {
25 namespace retaincountchecker {
26 
27 class RefCountBug : public BugType {
28 public:
38  };
39  RefCountBug(const CheckerBase *checker, RefCountBugType BT);
40  StringRef getDescription() const;
41 
43  return BT;
44  }
45 
46  const CheckerBase *getChecker() const {
47  return Checker;
48  }
49 
50 private:
51  RefCountBugType BT;
52  const CheckerBase *Checker;
53  static StringRef bugTypeToName(RefCountBugType BT);
54 };
55 
56 class RefCountReport : public BugReport {
57 protected:
59  bool isLeak = false;
60 
61 public:
62  RefCountReport(const RefCountBug &D, const LangOptions &LOpts,
63  ExplodedNode *n, SymbolRef sym,
64  bool isLeak=false);
65 
66  RefCountReport(const RefCountBug &D, const LangOptions &LOpts,
67  ExplodedNode *n, SymbolRef sym,
68  StringRef endText);
69 
70  llvm::iterator_range<ranges_iterator> getRanges() override {
71  if (!isLeak)
72  return BugReport::getRanges();
73  return llvm::make_range(ranges_iterator(), ranges_iterator());
74  }
75 };
76 
77 class RefLeakReport : public RefCountReport {
78  const MemRegion* AllocBinding;
79  const Stmt *AllocStmt;
80 
81  // Finds the function declaration where a leak warning for the parameter
82  // 'sym' should be raised.
83  void deriveParamLocation(CheckerContext &Ctx, SymbolRef sym);
84  // Finds the location where a leak warning for 'sym' should be raised.
85  void deriveAllocLocation(CheckerContext &Ctx, SymbolRef sym);
86  // Produces description of a leak warning which is printed on the console.
87  void createDescription(CheckerContext &Ctx);
88 
89 public:
90  RefLeakReport(const RefCountBug &D, const LangOptions &LOpts, ExplodedNode *n,
91  SymbolRef sym, CheckerContext &Ctx);
92 
94  assert(Location.isValid());
95  return Location;
96  }
97 };
98 
99 } // end namespace retaincountchecker
100 } // end namespace ento
101 } // end namespace clang
102 
103 #endif
MemRegion - The root abstract class for all memory regions.
Definition: MemRegion.h:94
Stmt - This represents one statement.
Definition: Stmt.h:66
Symbolic value.
Definition: SymExpr.h:29
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:49
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.
PathDiagnosticLocation getLocation(const SourceManager &SM) const override
Return the "definitive" location of the reported bug.
const SourceManager & SM
Definition: Format.cpp:1572
Dataflow Directional Tag Classes.
RefCountBug(const CheckerBase *checker, RefCountBugType BT)
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:75
This class handles loading and caching of source files into memory.