Go to the documentation of this file.
30 #include "llvm/ADT/DenseMap.h"
32 using namespace clang;
51 class DirectIvarAssignment :
52 public Checker<check::ASTDecl<ObjCImplementationDecl> > {
60 const IvarToPropertyMapTy &IvarToPropMap;
64 const CheckerBase *Checker;
68 MethodCrawler(
const IvarToPropertyMapTy &InMap,
const ObjCMethodDecl *InMD,
71 : IvarToPropMap(InMap), MD(InMD), InterfD(InID), BR(InBR),
72 Checker(Checker), DCtx(InDCtx) {}
74 void VisitStmt(
const Stmt *S) { VisitChildren(S); }
78 void VisitChildren(
const Stmt *S) {
79 for (
const Stmt *Child : S->children())
88 DirectIvarAssignment() : ShouldSkipMethod(&DefaultMethodFilter) {}
91 BugReporter &BR)
const;
117 AnalysisManager& Mgr,
118 BugReporter &BR)
const {
122 IvarToPropertyMapTy IvarToPropMap;
128 Mgr.getASTContext());
134 IvarToPropMap[
ID] = PD;
137 if (IvarToPropMap.empty())
143 if ((*ShouldSkipMethod)(M))
157 static bool isAnnotatedToAllowDirectAssignment(
const Decl *D) {
159 if (Ann->getAnnotation() ==
160 "objc_allow_direct_instance_variable_assignment")
165 void DirectIvarAssignment::MethodCrawler::VisitBinaryOperator(
177 IvarToPropertyMapTy::const_iterator I = IvarToPropMap.find(D);
179 if (I != IvarToPropMap.end()) {
185 if (isAnnotatedToAllowDirectAssignment(PD) ||
186 isAnnotatedToAllowDirectAssignment(D))
202 "Direct assignment to an instance variable backing a property; "
203 "use the setter instead",
204 PathDiagnosticLocation(IvarRef, BR.getSourceManager(), DCtx));
214 if (Ann->getAnnotation() ==
"objc_no_direct_instance_variable_assignment")
221 void ento::registerDirectIvarAssignment(CheckerManager &mgr) {
222 auto Chk = mgr.registerChecker<DirectIvarAssignment>();
223 if (mgr.getAnalyzerOptions().getCheckerBooleanOption(Chk,
224 "AnnotatedFunctions"))
228 bool ento::shouldRegisterDirectIvarAssignment(
const CheckerManager &mgr) {
Represents an ObjC class declaration.
static bool isAssignmentOp(Opcode Opc)
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
AnalysisDeclContext contains the context data for the function, method or block under analysis.
instmeth_range instance_methods() const
const ObjCInterfaceDecl * getClassInterface() const
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
A builtin binary operation expression such as "x + y" or "x <= y".
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Selector getSetterName() const
Selector getSelector() const
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
llvm::PointerUnion< const LocationContext *, AnalysisDeclContext * > LocationOrAnalysisDeclContext
ObjCMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
const char *const CoreFoundationObjectiveC
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
IdentifierInfo * getDefaultSynthIvarName(ASTContext &Ctx) const
Get the default name of the synthesized ivar.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
static bool AttrFilter(const ObjCMethodDecl *M)
bool isSynthesizedAccessorStub() const
Decl - This represents one declaration (or definition), e.g.
ObjCIvarDecl * getPropertyIvarDecl() const
Represents one property declaration in an Objective-C interface.
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
One of these records is kept for each identifier that is lexed.
Selector getGetterName() const
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
ObjCMethodDecl - Represents an instance or class method declaration.
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
Stmt - This represents one statement.
ObjCIvarDecl - Represents an ObjC instance variable.
instprop_range instance_properties() const
ObjCIvarRefExpr - A reference to an ObjC instance variable.