27 using namespace clang;
31 typedef llvm::DenseMap<const ObjCIvarDecl*,IVarState>
IvarUsageMap;
39 IvarUsageMap::iterator I = M.find(D);
46 if (
const BlockExpr *BE = dyn_cast<BlockExpr>(S)) {
47 Scan(M, BE->getBody());
53 i = POE->semantics_begin(), e = POE->semantics_end(); i != e; ++i) {
56 sub = OVE->getSourceExpr();
73 IvarUsageMap::iterator I = M.find(ID);
81 Scan(M, I->getBody());
86 for (
const auto *I :
ID->property_impls())
90 for (
const auto *Cat :
ID->getClassInterface()->visible_categories()) {
99 for (
const auto *I : C->
decls())
100 if (
const auto *FD = dyn_cast<FunctionDecl>(I)) {
103 Scan(M, FD->getBody());
109 const CheckerBase *Checker) {
115 for (
const auto *Ivar : ID->
ivars()) {
122 Ivar->hasAttr<UnusedAttr>() || Ivar->hasAttr<IBOutletAttr>() ||
123 Ivar->hasAttr<IBOutletCollectionAttr>() ||
124 Ivar->isUnnamedBitfield())
137 bool hasUnused =
false;
138 for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
139 if (I->second ==
Unused) {
156 for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
157 if (I->second ==
Unused) {
159 llvm::raw_string_ostream os(sbuf);
160 os <<
"Instance variable '" << *I->first <<
"' in class '" << *ID
161 <<
"' is never used by the methods in its @implementation " 162 "(although it may be used by category methods).";
164 PathDiagnosticLocation L =
166 BR.EmitBasicReport(D, Checker,
"Unused instance variable",
"Optimization",
176 class ObjCUnusedIvarsChecker :
public Checker<
177 check::ASTDecl<ObjCImplementationDecl> > {
180 BugReporter &BR)
const {
186 void ento::registerObjCUnusedIvarsChecker(CheckerManager &mgr) {
187 mgr.registerChecker<ObjCUnusedIvarsChecker>();
ObjCIvarDecl * getPropertyIvarDecl() const
Stmt - This represents one statement.
Defines the SourceManager interface.
static void Scan(IvarUsageMap &M, const Stmt *S)
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
instmeth_range instance_methods() const
const Expr *const * const_semantics_iterator
ObjCContainerDecl - Represents a container for method declarations.
static PathDiagnosticLocation create(const Decl *D, const SourceManager &SM)
Create a location corresponding to the given declaration.
Represents an ObjC class declaration.
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
static void checkObjCUnusedIvar(const ObjCImplementationDecl *D, BugReporter &BR, const CheckerBase *Checker)
This represents one expression.
Defines the clang::LangOptions interface.
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
DeclContext * getDeclContext()
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class...
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Encodes a location in the source.
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
const ObjCInterfaceDecl * getClassInterface() const
Dataflow Directional Tag Classes.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
llvm::DenseMap< const ObjCIvarDecl *, IVarState > IvarUsageMap
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
ObjCIvarRefExpr - A reference to an ObjC instance variable.
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
This class handles loading and caching of source files into memory.
SourceLocation getLocation() const