25class ZeroOutInDeallocRemover :
31 llvm::DenseMap<ObjCPropertyDecl*, ObjCPropertyImplDecl*> SynthesizedProperties;
37 ZeroOutInDeallocRemover(
MigrationPass &pass) : Pass(pass), SelfD(nullptr) {
53 if (!refE || refE->
getDecl() != SelfD)
56 bool BackedBySynthesizeSetter =
false;
57 for (llvm::DenseMap<ObjCPropertyDecl*, ObjCPropertyImplDecl*>::iterator
58 P = SynthesizedProperties.begin(),
59 E = SynthesizedProperties.end();
P != E; ++
P) {
62 BackedBySynthesizeSetter =
true;
66 if (!BackedBySynthesizeSetter)
75 if (RHSIsNull && isRemovable(ME))
82 if (isZeroingPropIvar(POE) && isRemovable(POE)) {
91 if (isZeroingPropIvar(BOE) && isRemovable(BOE)) {
116 if (PID->getPropertyImplementation() ==
120 if (!(setterM && setterM->
isDefined())) {
125 SynthesizedProperties[PD] = PID;
131 base::TraverseObjCMethodDecl(D);
134 SynthesizedProperties.clear();
140 bool TraverseFunctionDecl(
FunctionDecl *D) {
return true; }
141 bool TraverseBlockDecl(
BlockDecl *block) {
return true; }
142 bool TraverseBlockExpr(
BlockExpr *block) {
return true; }
145 bool isRemovable(
Expr *E)
const {
146 return Removables.count(E);
149 bool isZeroingPropIvar(
Expr *E) {
152 return isZeroingPropIvar(BO);
154 return isZeroingPropIvar(PO);
160 return isZeroingPropIvar(BOE->
getLHS()) &&
161 isZeroingPropIvar(BOE->
getRHS());
171 bool IvarBacksPropertySynthesis =
false;
172 for (llvm::DenseMap<ObjCPropertyDecl*, ObjCPropertyImplDecl*>::iterator
173 P = SynthesizedProperties.begin(),
174 E = SynthesizedProperties.end();
P != E; ++
P) {
177 IvarBacksPropertySynthesis =
true;
181 if (!IvarBacksPropertySynthesis)
187 return isZero(BOE->
getRHS());
192 if (!BO)
return false;
193 if (BO->
getOpcode() != BO_Assign)
return false;
197 if (!PropRefExp)
return false;
204 if (!SynthesizedProperties.count(PDecl))
208 return isZero(cast<OpaqueValueExpr>(BO->
getRHS())->getSourceExpr());
211 bool isZero(
Expr *E) {
215 return isZeroingPropIvar(E);
222 ZeroOutInDeallocRemover trans(pass);
Defines the clang::ASTContext interface.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TranslationUnitDecl * getTranslationUnitDecl() const
SelectorTable & Selectors
A builtin binary operation expression such as "x + y" or "x <= y".
Represents a block literal declaration, which is like an unnamed FunctionDecl.
BlockExpr - Adaptor class for mixing a BlockDecl with expressions.
A reference to a declared variable, function, enum, etc.
DeclContext * getDeclContext()
This represents one expression.
Expr * IgnoreParenCasts() LLVM_READONLY
Skip past any parentheses and casts which might surround this expression until reaching a fixed point...
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
@ NPC_ValueDependentIsNull
Specifies that a value-dependent expression of integral or dependent type should be considered a null...
NullPointerConstantKind isNullPointerConstant(ASTContext &Ctx, NullPointerConstantValueDependence NPC) const
isNullPointerConstant - C99 6.3.2.3p3 - Test if this reduces down to a Null pointer constant.
Represents a function declaration or definition.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
propimpl_range property_impls() const
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCIvarRefExpr - A reference to an ObjC instance variable.
An expression that sends a message to the given Objective-C object or class.
Expr * getArg(unsigned Arg)
getArg - Return the specified argument.
Expr * getInstanceReceiver()
Returns the object expression (receiver) for an instance message, or null for a message that is not a...
Selector getSelector() const
@ Instance
The receiver is an object instance.
ReceiverKind getReceiverKind() const
Determine the kind of receiver that this message is being sent to.
ObjCMethodDecl - Represents an instance or class method declaration.
ImplicitParamDecl * getSelfDecl() const
bool hasBody() const override
Determine whether this method has a body.
Stmt * getBody() const override
Retrieve the body of this method, if it has one.
Selector getSelector() const
bool isInstanceMethod() const
ObjCMethodFamily getMethodFamily() const
Determines the family of this method.
Represents one property declaration in an Objective-C interface.
ObjCMethodDecl * getSetterMethodDecl() const
Selector getSetterName() const
ObjCPropertyAttribute::Kind getPropertyAttributes() const
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
ObjCIvarDecl * getPropertyIvarDecl() const
ObjCPropertyRefExpr - A dot-syntax expression to access an ObjC property.
ObjCPropertyDecl * getExplicitProperty() const
bool isImplicitProperty() const
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Expr * getSyntacticForm()
Return the syntactic form of this expression, i.e.
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
Selector getNullarySelector(IdentifierInfo *ID)
Smart pointer class that efficiently represents Objective-C method names.
bool isObjCObjectPointerType() const
void removeZeroOutPropsInDeallocFinalize(MigrationPass &pass)
void collectRemovables(Stmt *S, ExprSet &exprs)