30#include "llvm/ADT/DenseMap.h"
51class DirectIvarAssignment :
52 public Checker<check::ASTDecl<ObjCImplementationDecl> > {
60 const IvarToPropertyMapTy &IvarToPropMap;
68 MethodCrawler(
const IvarToPropertyMapTy &InMap,
const ObjCMethodDecl *InMD,
71 : IvarToPropMap(InMap), MD(InMD), InterfD(InID), BR(InBR),
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) {}
122 IvarToPropertyMapTy IvarToPropMap;
134 IvarToPropMap[
ID] = PD;
137 if (IvarToPropMap.empty())
140 for (
const auto *M :
D->instance_methods()) {
143 if ((*ShouldSkipMethod)(M))
157static bool isAnnotatedToAllowDirectAssignment(
const Decl *
D) {
159 if (Ann->getAnnotation() ==
160 "objc_allow_direct_instance_variable_assignment")
165void 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",
214 if (Ann->getAnnotation() ==
"objc_no_direct_instance_variable_assignment")
224 "AnnotatedFunctions"))
228bool ento::shouldRegisterDirectIvarAssignment(
const CheckerManager &mgr) {
static bool AttrFilter(const ObjCMethodDecl *M)
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
AnalysisDeclContext contains the context data for the function, method or block under analysis.
bool getCheckerBooleanOption(StringRef CheckerName, StringRef OptionName, bool SearchInParents=false) const
Interprets an option's string value as a boolean.
A builtin binary operation expression such as "x + y" or "x <= y".
static bool isAssignmentOp(Opcode Opc)
ConstStmtVisitor - This class implements a simple visitor for Stmt subclasses.
Decl - This represents one declaration (or definition), e.g.
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
One of these records is kept for each identifier that is lexed.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
instprop_range instance_properties() const
ObjCMethodDecl * getInstanceMethod(Selector Sel, bool AllowHidden=false) const
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
ObjCIvarDecl * lookupInstanceVariable(IdentifierInfo *IVarName, ObjCInterfaceDecl *&ClassDeclared)
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
ObjCMethodDecl - Represents an instance or class method declaration.
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
ObjCMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isSynthesizedAccessorStub() const
Selector getSelector() const
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Represents one property declaration in an Objective-C interface.
ObjCIvarDecl * getPropertyIvarDecl() const
Selector getSetterName() const
Selector getGetterName() const
IdentifierInfo * getDefaultSynthIvarName(ASTContext &Ctx) const
Get the default name of the synthesized ivar.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
Stmt - This represents one statement.
ASTContext & getASTContext() override
AnalysisDeclContext * getAnalysisDeclContext(const Decl *D)
BugReporter is a utility class for generating PathDiagnostics for analysis.
const SourceManager & getSourceManager()
void EmitBasicReport(const Decl *DeclWithIssue, const CheckerBase *Checker, StringRef BugName, StringRef BugCategory, StringRef BugStr, PathDiagnosticLocation Loc, ArrayRef< SourceRange > Ranges=std::nullopt, ArrayRef< FixItHint > Fixits=std::nullopt)
const AnalyzerOptions & getAnalyzerOptions() const
CHECKER * registerChecker(AT &&... Args)
Used to register checkers.
const char *const CoreFoundationObjectiveC
llvm::PointerUnion< const LocationContext *, AnalysisDeclContext * > LocationOrAnalysisDeclContext
The JSON file list parser is used to communicate input to InstallAPI.