diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-04 15:58:17 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-11-04 15:58:17 +0000 |
commit | 81eecde879712729712966b60c0cb1540b41293b (patch) | |
tree | 1bac8f173496e60154e2740ecb48c5e8005e492e /lib | |
parent | 0d579b6a3f555c0e37e84e517c81eb9244fef099 (diff) |
[arcmt] In GC, error for use of CFMakeCollectable because it will leak the
object that it receives in ARC.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@143700 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ARCMigrate/TransGCCalls.cpp | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/ARCMigrate/TransGCCalls.cpp b/lib/ARCMigrate/TransGCCalls.cpp index 9c3faae395..8042c6caba 100644 --- a/lib/ARCMigrate/TransGCCalls.cpp +++ b/lib/ARCMigrate/TransGCCalls.cpp @@ -22,27 +22,37 @@ class GCCollectableCallsChecker : MigrationContext &MigrateCtx; ParentMap &PMap; IdentifierInfo *NSMakeCollectableII; + IdentifierInfo *CFMakeCollectableII; public: GCCollectableCallsChecker(MigrationContext &ctx, ParentMap &map) : MigrateCtx(ctx), PMap(map) { - NSMakeCollectableII = - &MigrateCtx.getPass().Ctx.Idents.get("NSMakeCollectable"); + IdentifierTable &Ids = MigrateCtx.getPass().Ctx.Idents; + NSMakeCollectableII = &Ids.get("NSMakeCollectable"); + CFMakeCollectableII = &Ids.get("CFMakeCollectable"); } bool VisitCallExpr(CallExpr *E) { + TransformActions &TA = MigrateCtx.getPass().TA; + Expr *CEE = E->getCallee()->IgnoreParenImpCasts(); if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE)) { if (FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(DRE->getDecl())) { - if (FD->getDeclContext()->getRedeclContext()->isFileContext() && - FD->getIdentifier() == NSMakeCollectableII) { - TransformActions &TA = MigrateCtx.getPass().TA; + if (!FD->getDeclContext()->getRedeclContext()->isFileContext()) + return true; + + if (FD->getIdentifier() == NSMakeCollectableII) { Transaction Trans(TA); TA.clearDiagnostic(diag::err_unavailable, diag::err_unavailable_message, diag::err_ovl_deleted_call, // ObjC++ DRE->getSourceRange()); TA.replace(DRE->getSourceRange(), "CFBridgingRelease"); + + } else if (FD->getIdentifier() == CFMakeCollectableII) { + TA.reportError("CFMakeCollectable will leak the object that it " + "receives in ARC", DRE->getLocation(), + DRE->getSourceRange()); } } } |