[cfe-commits] r143700 - in /cfe/trunk: lib/ARCMigrate/TransGCCalls.cpp test/ARCMT/GC-check.m

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Nov 4 08:58:18 PDT 2011


Author: akirtzidis
Date: Fri Nov  4 10:58:17 2011
New Revision: 143700

URL: http://llvm.org/viewvc/llvm-project?rev=143700&view=rev
Log:
[arcmt] In GC, error for use of CFMakeCollectable because it will leak the
object that it receives in ARC.

Added:
    cfe/trunk/test/ARCMT/GC-check.m
Modified:
    cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp

Modified: cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp?rev=143700&r1=143699&r2=143700&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransGCCalls.cpp Fri Nov  4 10:58:17 2011
@@ -22,27 +22,37 @@
   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());
         }
       }
     }

Added: cfe/trunk/test/ARCMT/GC-check.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/GC-check.m?rev=143700&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/GC-check.m (added)
+++ cfe/trunk/test/ARCMT/GC-check.m Fri Nov  4 10:58:17 2011
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-gc-only %s
+// RUN: %clang_cc1 -arcmt-check -verify -triple x86_64-apple-darwin10 -fobjc-gc-only -x objective-c++ %s
+
+#define CF_AUTOMATED_REFCOUNT_UNAVAILABLE __attribute__((unavailable("not available in automatic reference counting mode")))
+typedef const void * CFTypeRef;
+CFTypeRef CFMakeCollectable(CFTypeRef cf) CF_AUTOMATED_REFCOUNT_UNAVAILABLE; // expected-note {{unavailable}}
+
+void test1(CFTypeRef *cft) {
+  CFTypeRef c = CFMakeCollectable(cft); // expected-error {{CFMakeCollectable will leak the object that it receives in ARC}} \
+                // expected-error {{unavailable}}
+}





More information about the cfe-commits mailing list