1 //== RetainCountDiagnostics.h - Checks for leaks and other issues -*- C++ -*--//
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
7 //===----------------------------------------------------------------------===//
9 // This file defines diagnostics for RetainCountChecker, which implements
10 // a reference count checker for Core Foundation and Cocoa on (Mac OS X).
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_DIAGNOSTICS_H
15 #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_DIAGNOSTICS_H
17 #include "clang/Analysis/RetainSummaryManager.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/PathSensitive/CallEvent.h"
25 namespace retaincountchecker {
27 class RefCountBug : public BugType {
29 enum RefCountBugType {
35 ReturnNotOwnedForOwned,
39 RefCountBug(const CheckerBase *checker, RefCountBugType BT);
40 StringRef getDescription() const;
42 RefCountBugType getBugType() const {
46 const CheckerBase *getChecker() const {
52 const CheckerBase *Checker;
53 static StringRef bugTypeToName(RefCountBugType BT);
56 class RefCountReport : public BugReport {
62 RefCountReport(const RefCountBug &D, const LangOptions &LOpts,
63 ExplodedNode *n, SymbolRef sym,
66 RefCountReport(const RefCountBug &D, const LangOptions &LOpts,
67 ExplodedNode *n, SymbolRef sym,
70 llvm::iterator_range<ranges_iterator> getRanges() override {
72 return BugReport::getRanges();
73 return llvm::make_range(ranges_iterator(), ranges_iterator());
77 class RefLeakReport : public RefCountReport {
78 const MemRegion* AllocBinding;
79 const Stmt *AllocStmt;
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);
90 RefLeakReport(const RefCountBug &D, const LangOptions &LOpts, ExplodedNode *n,
91 SymbolRef sym, CheckerContext &Ctx);
93 PathDiagnosticLocation getLocation(const SourceManager &SM) const override {
94 assert(Location.isValid());
99 } // end namespace retaincountchecker
100 } // end namespace ento
101 } // end namespace clang