26 using namespace clang;
30 typedef llvm::DenseMap<const ObjCIvarDecl*,IVarState>
IvarUsageMap;
38 IvarUsageMap::iterator I = M.find(D);
45 if (
const BlockExpr *BE = dyn_cast<BlockExpr>(S)) {
46 Scan(M, BE->getBody());
52 i = POE->semantics_begin(), e = POE->semantics_end();
i != e; ++
i) {
55 sub = OVE->getSourceExpr();
72 IvarUsageMap::iterator I = M.find(ID);
80 Scan(M, I->getBody());
85 for (
const auto *I :
ID->property_impls())
89 for (
const auto *Cat :
ID->getClassInterface()->visible_categories()) {
98 for (
const auto *I : C->
decls())
99 if (
const auto *FD = dyn_cast<FunctionDecl>(I)) {
102 Scan(M, FD->getBody());
108 const CheckerBase *Checker) {
114 for (
const auto *Ivar : ID->
ivars()) {
121 Ivar->hasAttr<UnusedAttr>() || Ivar->hasAttr<IBOutletAttr>() ||
122 Ivar->hasAttr<IBOutletCollectionAttr>() ||
123 Ivar->isUnnamedBitfield())
136 bool hasUnused =
false;
137 for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
138 if (I->second ==
Unused) {
155 for (IvarUsageMap::iterator I = M.begin(), E = M.end(); I!=E; ++I)
156 if (I->second ==
Unused) {
158 llvm::raw_string_ostream os(sbuf);
159 os <<
"Instance variable '" << *I->first <<
"' in class '" << *ID
160 <<
"' is never used by the methods in its @implementation " 161 "(although it may be used by category methods).";
163 PathDiagnosticLocation L =
165 BR.EmitBasicReport(D, Checker,
"Unused instance variable",
"Optimization",
175 class ObjCUnusedIvarsChecker :
public Checker<
176 check::ASTDecl<ObjCImplementationDecl> > {
179 BugReporter &BR)
const {
185 void ento::registerObjCUnusedIvarsChecker(CheckerManager &mgr) {
186 mgr.registerChecker<ObjCUnusedIvarsChecker>();
189 bool ento::shouldRegisterObjCUnusedIvarsChecker(
const LangOptions &LO) {
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
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
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