"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h" between
cfe-8.0.1.src.tar.xz and cfe-9.0.0.src.tar.xz

About: Clang is an LLVM front end for the C, C++, and Objective-C languages. Clang aims to provide a better user experience through expressive diagnostics, a high level of conformance to language standards, fast compilation, and low memory use.

RetainCountChecker.h  (cfe-8.0.1.src.tar.xz):RetainCountChecker.h  (cfe-9.0.0.src.tar.xz)
//==--- RetainCountChecker.h - Checks for leaks and other issues -*- C++ -*--// //==--- RetainCountChecker.h - Checks for leaks and other issues -*- C++ -*--//
// //
// The LLVM Compiler Infrastructure // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// // See https://llvm.org/LICENSE.txt for license information.
// This file is distributed under the University of Illinois Open Source // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// License. See LICENSE.TXT for details.
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// //
// This file defines the methods for RetainCountChecker, which implements // This file defines the methods for RetainCountChecker, which implements
// a reference count checker for Core Foundation and Cocoa on (Mac OS X). // a reference count checker for Core Foundation and Cocoa on (Mac OS X).
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H #ifndef LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H
#define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H #define LLVM_CLANG_LIB_STATICANALYZER_CHECKERS_RETAINCOUNTCHECKER_H
#include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h" #include "clang/StaticAnalyzer/Checkers/BuiltinCheckerRegistration.h"
#include "RetainCountDiagnostics.h" #include "RetainCountDiagnostics.h"
#include "clang/AST/Attr.h" #include "clang/AST/Attr.h"
#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h" #include "clang/AST/DeclObjC.h"
#include "clang/AST/ParentMap.h" #include "clang/AST/ParentMap.h"
#include "clang/Analysis/DomainSpecific/CocoaConventions.h" #include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/Analysis/RetainSummaryManager.h"
#include "clang/Basic/LangOptions.h" #include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceManager.h" #include "clang/Basic/SourceManager.h"
#include "clang/Analysis/SelectorExtras.h" #include "clang/Analysis/SelectorExtras.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h" #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h" #include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
#include "clang/StaticAnalyzer/Core/Checker.h" #include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h" #include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h" #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h" #include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
#include "clang/StaticAnalyzer/Core/RetainSummaryManager.h"
#include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/ImmutableList.h" #include "llvm/ADT/ImmutableList.h"
#include "llvm/ADT/ImmutableMap.h" #include "llvm/ADT/ImmutableMap.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringExtras.h"
#include <cstdarg> #include <cstdarg>
#include <utility> #include <utility>
skipping to change at line 254 skipping to change at line 253
check::PostStmt<BlockExpr>, check::PostStmt<BlockExpr>,
check::PostStmt<CastExpr>, check::PostStmt<CastExpr>,
check::PostStmt<ObjCArrayLiteral>, check::PostStmt<ObjCArrayLiteral>,
check::PostStmt<ObjCDictionaryLiteral>, check::PostStmt<ObjCDictionaryLiteral>,
check::PostStmt<ObjCBoxedExpr>, check::PostStmt<ObjCBoxedExpr>,
check::PostStmt<ObjCIvarRefExpr>, check::PostStmt<ObjCIvarRefExpr>,
check::PostCall, check::PostCall,
check::RegionChanges, check::RegionChanges,
eval::Assume, eval::Assume,
eval::Call > { eval::Call > {
mutable std::unique_ptr<RefCountBug> useAfterRelease, releaseNotOwned;
mutable std::unique_ptr<RefCountBug> deallocNotOwned; RefCountBug useAfterRelease{this, RefCountBug::UseAfterRelease};
mutable std::unique_ptr<RefCountBug> overAutorelease, returnNotOwnedForOwned; RefCountBug releaseNotOwned{this, RefCountBug::ReleaseNotOwned};
mutable std::unique_ptr<RefCountBug> leakWithinFunction, leakAtReturn; RefCountBug deallocNotOwned{this, RefCountBug::DeallocNotOwned};
RefCountBug freeNotOwned{this, RefCountBug::FreeNotOwned};
RefCountBug overAutorelease{this, RefCountBug::OverAutorelease};
RefCountBug returnNotOwnedForOwned{this, RefCountBug::ReturnNotOwnedForOwned};
RefCountBug leakWithinFunction{this, RefCountBug::LeakWithinFunction};
RefCountBug leakAtReturn{this, RefCountBug::LeakAtReturn};
CheckerProgramPointTag DeallocSentTag{this, "DeallocSent"};
CheckerProgramPointTag CastFailTag{this, "DynamicCastFail"};
mutable std::unique_ptr<RetainSummaryManager> Summaries; mutable std::unique_ptr<RetainSummaryManager> Summaries;
public: public:
static constexpr const char *DeallocTagDescription = "DeallocSent";
/// Track Objective-C and CoreFoundation objects. /// Track Objective-C and CoreFoundation objects.
bool TrackObjCAndCFObjects = false; bool TrackObjCAndCFObjects = false;
/// Track sublcasses of OSObject. /// Track sublcasses of OSObject.
bool TrackOSObjects = false; bool TrackOSObjects = false;
RetainCountChecker() {} /// Track initial parameters (for the entry point) for NS/CF objects.
bool TrackNSCFStartParam = false;
RefCountBug *getLeakWithinFunctionBug(const LangOptions &LOpts) const; RetainCountChecker() {};
RefCountBug *getLeakAtReturnBug(const LangOptions &LOpts) const;
RetainSummaryManager &getSummaryManager(ASTContext &Ctx) const { RetainSummaryManager &getSummaryManager(ASTContext &Ctx) const {
// FIXME: We don't support ARC being turned on and off during one analysis. if (!Summaries)
// (nor, for that matter, do we support changing ASTContexts) Summaries.reset(
bool ARCEnabled = (bool)Ctx.getLangOpts().ObjCAutoRefCount; new RetainSummaryManager(Ctx, TrackObjCAndCFObjects, TrackOSObjects));
if (!Summaries) {
Summaries.reset(new RetainSummaryManager(
Ctx, ARCEnabled, TrackObjCAndCFObjects, TrackOSObjects));
} else {
assert(Summaries->isARCEnabled() == ARCEnabled);
}
return *Summaries; return *Summaries;
} }
RetainSummaryManager &getSummaryManager(CheckerContext &C) const { RetainSummaryManager &getSummaryManager(CheckerContext &C) const {
return getSummaryManager(C.getASTContext()); return getSummaryManager(C.getASTContext());
} }
void printState(raw_ostream &Out, ProgramStateRef State, void printState(raw_ostream &Out, ProgramStateRef State,
const char *NL, const char *Sep) const override; const char *NL, const char *Sep) const override;
skipping to change at line 314 skipping to change at line 313
void checkPostCall(const CallEvent &Call, CheckerContext &C) const; void checkPostCall(const CallEvent &Call, CheckerContext &C) const;
void checkSummary(const RetainSummary &Summ, const CallEvent &Call, void checkSummary(const RetainSummary &Summ, const CallEvent &Call,
CheckerContext &C) const; CheckerContext &C) const;
void processSummaryOfInlined(const RetainSummary &Summ, void processSummaryOfInlined(const RetainSummary &Summ,
const CallEvent &Call, const CallEvent &Call,
CheckerContext &C) const; CheckerContext &C) const;
bool evalCall(const CallExpr *CE, CheckerContext &C) const; bool evalCall(const CallEvent &Call, CheckerContext &C) const;
ProgramStateRef evalAssume(ProgramStateRef state, SVal Cond, ProgramStateRef evalAssume(ProgramStateRef state, SVal Cond,
bool Assumption) const; bool Assumption) const;
ProgramStateRef ProgramStateRef
checkRegionChanges(ProgramStateRef state, checkRegionChanges(ProgramStateRef state,
const InvalidatedSymbols *invalidated, const InvalidatedSymbols *invalidated,
ArrayRef<const MemRegion *> ExplicitRegions, ArrayRef<const MemRegion *> ExplicitRegions,
ArrayRef<const MemRegion *> Regions, ArrayRef<const MemRegion *> Regions,
const LocationContext* LCtx, const LocationContext* LCtx,
skipping to change at line 339 skipping to change at line 338
SymbolRef Sym, ProgramStateRef state) const; SymbolRef Sym, ProgramStateRef state) const;
void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const; void checkDeadSymbols(SymbolReaper &SymReaper, CheckerContext &C) const;
void checkBeginFunction(CheckerContext &C) const; void checkBeginFunction(CheckerContext &C) const;
void checkEndFunction(const ReturnStmt *RS, CheckerContext &C) const; void checkEndFunction(const ReturnStmt *RS, CheckerContext &C) const;
ProgramStateRef updateSymbol(ProgramStateRef state, SymbolRef sym, ProgramStateRef updateSymbol(ProgramStateRef state, SymbolRef sym,
RefVal V, ArgEffect E, RefVal::Kind &hasErr, RefVal V, ArgEffect E, RefVal::Kind &hasErr,
CheckerContext &C) const; CheckerContext &C) const;
const RefCountBug &errorKindToBugKind(RefVal::Kind ErrorKind,
SymbolRef Sym) const;
void processNonLeakError(ProgramStateRef St, SourceRange ErrorRange, void processNonLeakError(ProgramStateRef St, SourceRange ErrorRange,
RefVal::Kind ErrorKind, SymbolRef Sym, RefVal::Kind ErrorKind, SymbolRef Sym,
CheckerContext &C) const; CheckerContext &C) const;
void processObjCLiterals(CheckerContext &C, const Expr *Ex) const; void processObjCLiterals(CheckerContext &C, const Expr *Ex) const;
ProgramStateRef handleSymbolDeath(ProgramStateRef state, ProgramStateRef handleSymbolDeath(ProgramStateRef state,
SymbolRef sid, RefVal V, SymbolRef sid, RefVal V,
SmallVectorImpl<SymbolRef> &Leaked) const; SmallVectorImpl<SymbolRef> &Leaked) const;
skipping to change at line 361 skipping to change at line 363
const ProgramPointTag *Tag, CheckerContext &Ctx, const ProgramPointTag *Tag, CheckerContext &Ctx,
SymbolRef Sym, SymbolRef Sym,
RefVal V, RefVal V,
const ReturnStmt *S=nullptr) const; const ReturnStmt *S=nullptr) const;
ExplodedNode *processLeaks(ProgramStateRef state, ExplodedNode *processLeaks(ProgramStateRef state,
SmallVectorImpl<SymbolRef> &Leaked, SmallVectorImpl<SymbolRef> &Leaked,
CheckerContext &Ctx, CheckerContext &Ctx,
ExplodedNode *Pred = nullptr) const; ExplodedNode *Pred = nullptr) const;
const CheckerProgramPointTag &getDeallocSentTag() const {
return DeallocSentTag;
}
const CheckerProgramPointTag &getCastFailTag() const {
return CastFailTag;
}
private: private:
/// Perform the necessary checks and state adjustments at the end of the /// Perform the necessary checks and state adjustments at the end of the
/// function. /// function.
/// \p S Return statement, may be null. /// \p S Return statement, may be null.
ExplodedNode * processReturn(const ReturnStmt *S, CheckerContext &C) const; ExplodedNode * processReturn(const ReturnStmt *S, CheckerContext &C) const;
}; };
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// RefBindings - State used to track object reference counts. // RefBindings - State used to track object reference counts.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
const RefVal *getRefBinding(ProgramStateRef State, SymbolRef Sym); const RefVal *getRefBinding(ProgramStateRef State, SymbolRef Sym);
ProgramStateRef setRefBinding(ProgramStateRef State, SymbolRef Sym,
RefVal Val);
ProgramStateRef removeRefBinding(ProgramStateRef State, SymbolRef Sym);
/// Returns true if this stack frame is for an Objective-C method that is a /// Returns true if this stack frame is for an Objective-C method that is a
/// property getter or setter whose body has been synthesized by the analyzer. /// property getter or setter whose body has been synthesized by the analyzer.
inline bool isSynthesizedAccessor(const StackFrameContext *SFC) { inline bool isSynthesizedAccessor(const StackFrameContext *SFC) {
auto Method = dyn_cast_or_null<ObjCMethodDecl>(SFC->getDecl()); auto Method = dyn_cast_or_null<ObjCMethodDecl>(SFC->getDecl());
if (!Method || !Method->isPropertyAccessor()) if (!Method || !Method->isPropertyAccessor())
return false; return false;
return SFC->getAnalysisDeclContext()->isBodyAutosynthesized(); return SFC->getAnalysisDeclContext()->isBodyAutosynthesized();
} }
 End of changes. 12 change blocks. 
29 lines changed or deleted 34 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)