[cfe-commits] r135213 - in /cfe/trunk: lib/ARCMigrate/TransRetainReleaseDealloc.cpp lib/ARCMigrate/TransUnbridgedCasts.cpp lib/ARCMigrate/Transforms.cpp lib/ARCMigrate/Transforms.h test/ARCMT/checking.m

Argyrios Kyrtzidis akyrtzi at gmail.com
Thu Jul 14 16:32:04 PDT 2011


Author: akirtzidis
Date: Thu Jul 14 18:32:04 2011
New Revision: 135213

URL: http://llvm.org/viewvc/llvm-project?rev=135213&view=rev
Log:
[arcmt] Don't remove retains/releases on a global variable, flag them with errors. rdar://9402555.

Modified:
    cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
    cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp
    cfe/trunk/lib/ARCMigrate/Transforms.cpp
    cfe/trunk/lib/ARCMigrate/Transforms.h
    cfe/trunk/test/ARCMT/checking.m

Modified: cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp?rev=135213&r1=135212&r2=135213&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp Thu Jul 14 18:32:04 2011
@@ -78,6 +78,15 @@
             Pass.TA.reportError(err, rec->getLocStart());
             return true;
           }
+
+          if (isGlobalVar(rec) &&
+              (E->getMethodFamily() != OMF_retain || isRemovable(E))) {
+            std::string err = "it is not safe to remove '";
+            err += E->getSelector().getAsString() + "' message on "
+                "a global variable";
+            Pass.TA.reportError(err, rec->getLocStart());
+            return true;
+          }
         }
     case OMF_dealloc:
       break;

Modified: cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp?rev=135213&r1=135212&r2=135213&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransUnbridgedCasts.cpp Thu Jul 14 18:32:04 2011
@@ -193,17 +193,6 @@
         return true;
     return false;
   }
-
-  static bool isGlobalVar(Expr *E) {
-    E = E->IgnoreParenCasts();
-    if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
-      return DRE->getDecl()->getDeclContext()->isFileContext();
-    if (ConditionalOperator *condOp = dyn_cast<ConditionalOperator>(E))
-      return isGlobalVar(condOp->getTrueExpr()) &&
-             isGlobalVar(condOp->getFalseExpr());
-
-    return false;  
-  }
 };
 
 } // end anonymous namespace

Modified: cfe/trunk/lib/ARCMigrate/Transforms.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.cpp?rev=135213&r1=135212&r2=135213&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/Transforms.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/Transforms.cpp Thu Jul 14 18:32:04 2011
@@ -152,6 +152,17 @@
   return true;
 }
 
+bool trans::isGlobalVar(Expr *E) {
+  E = E->IgnoreParenCasts();
+  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E))
+    return DRE->getDecl()->getDeclContext()->isFileContext();
+  if (ConditionalOperator *condOp = dyn_cast<ConditionalOperator>(E))
+    return isGlobalVar(condOp->getTrueExpr()) &&
+           isGlobalVar(condOp->getFalseExpr());
+
+  return false;  
+}
+
 namespace {
 
 class ReferenceClear : public RecursiveASTVisitor<ReferenceClear> {

Modified: cfe/trunk/lib/ARCMigrate/Transforms.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/Transforms.h?rev=135213&r1=135212&r2=135213&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/Transforms.h (original)
+++ cfe/trunk/lib/ARCMigrate/Transforms.h Thu Jul 14 18:32:04 2011
@@ -54,6 +54,8 @@
 SourceLocation findLocationAfterSemi(SourceLocation loc, ASTContext &Ctx);
 
 bool hasSideEffects(Expr *E, ASTContext &Ctx);
+bool isGlobalVar(Expr *E);
+
 
 template <typename BODY_TRANS>
 class BodyTransform : public RecursiveASTVisitor<BodyTransform<BODY_TRANS> > {

Modified: cfe/trunk/test/ARCMT/checking.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/checking.m?rev=135213&r1=135212&r2=135213&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/checking.m (original)
+++ cfe/trunk/test/ARCMT/checking.m Thu Jul 14 18:32:04 2011
@@ -36,10 +36,16 @@
 - (oneway void)release { } // expected-error {{ARC forbids implementation}}
 @end
 
+id global_foo;
+
 void test1(A *a, BOOL b, struct UnsafeS *unsafeS) {
   [unsafeS->unsafeObj retain]; // expected-error {{it is not safe to remove 'retain' message on an __unsafe_unretained type}} \
                                // expected-error {{ARC forbids explicit message send}}
   id foo = [unsafeS->unsafeObj retain]; // no warning.
+  [global_foo retain]; // expected-error {{it is not safe to remove 'retain' message on a global variable}} \
+                       // expected-error {{ARC forbids explicit message send}}
+  [global_foo release]; // expected-error {{it is not safe to remove 'release' message on a global variable}} \
+                        // expected-error {{ARC forbids explicit message send}}
   [a dealloc];
   [a retain];
   [a retainCount]; // expected-error {{ARC forbids explicit message send of 'retainCount'}}





More information about the cfe-commits mailing list