Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,30 @@ class RetainPtrCtorAdoptChecker
void visitBinaryOperator(const BinaryOperator *BO) const {
if (!BO->isAssignmentOp())
return;
if (!isa<ObjCIvarRefExpr>(BO->getLHS()))
return;
auto *LHS = BO->getLHS();
auto *RHS = BO->getRHS()->IgnoreParenCasts();
const Expr *Inner = nullptr;
if (isAllocInit(RHS, &Inner)) {
CreateOrCopyFnCall.insert(RHS);
if (Inner)
CreateOrCopyFnCall.insert(Inner);
if (isa<ObjCIvarRefExpr>(LHS)) {
const Expr *Inner = nullptr;
if (isAllocInit(RHS, &Inner)) {
CreateOrCopyFnCall.insert(RHS);
if (Inner)
CreateOrCopyFnCall.insert(Inner);
}
return;
} else if (auto *UO = dyn_cast<UnaryOperator>(LHS)) {
auto OpCode = UO->getOpcode();
if (OpCode == UO_Deref) {
if (auto *DerefTarget = UO->getSubExpr()) {
DerefTarget = DerefTarget->IgnoreParenCasts();
auto *DRE = dyn_cast<DeclRefExpr>(DerefTarget);
if (auto *Decl = DRE->getDecl()) {
if (!isa<ParmVarDecl>(Decl) || !isCreateOrCopy(RHS))
return;
if (Decl->hasAttr<CFReturnsRetainedAttr>())
CreateOrCopyFnCall.insert(RHS);
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ void adopt_retainptr() {
auto bar = adoptNS([allocSomeObj() init]);
}

CFTypeRef make_cf_obj() CF_RETURNS_RETAINED {
return CFArrayCreateMutable(kCFAllocatorDefault, 1);
}

void get_cf_obj(CFTypeRef* CF_RETURNS_RETAINED result) {
*result = CFArrayCreateMutable(kCFAllocatorDefault, 1);
}

RetainPtr<CFArrayRef> return_arg(CFArrayRef arg) {
return arg;
}
Expand Down