[cfe-commits] r142304 - in /cfe/trunk: lib/ARCMigrate/TransProperties.cpp test/ARCMT/assign-prop-with-arc-runtime.m test/ARCMT/assign-prop-with-arc-runtime.m.result test/ARCMT/releases-driver.m.result test/ARCMT/releases.m.result test/ARCMT/remove-dealloc-method.m.result test/ARCMT/remove-dealloc-zerouts.m.result test/ARCMT/retains.m.result

Argyrios Kyrtzidis akyrtzi at gmail.com
Mon Oct 17 16:14:17 PDT 2011


Author: akirtzidis
Date: Mon Oct 17 18:14:16 2011
New Revision: 142304

URL: http://llvm.org/viewvc/llvm-project?rev=142304&view=rev
Log:
[arcmt] In ARC default for properties is 'strong' so just remove a 'retain' if possible,
instead of changing it to 'strong'. rdar://9984862.

Modified:
    cfe/trunk/lib/ARCMigrate/TransProperties.cpp
    cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m
    cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m.result
    cfe/trunk/test/ARCMT/releases-driver.m.result
    cfe/trunk/test/ARCMT/releases.m.result
    cfe/trunk/test/ARCMT/remove-dealloc-method.m.result
    cfe/trunk/test/ARCMT/remove-dealloc-zerouts.m.result
    cfe/trunk/test/ARCMT/retains.m.result

Modified: cfe/trunk/lib/ARCMigrate/TransProperties.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/TransProperties.cpp?rev=142304&r1=142303&r2=142304&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/TransProperties.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/TransProperties.cpp Mon Oct 17 18:14:16 2011
@@ -132,7 +132,10 @@
       return;
 
     if (propAttrs & ObjCPropertyDecl::OBJC_PR_retain) {
-      rewriteAttribute("retain", "strong", atLoc);
+      if (propAttrs & ObjCPropertyDecl::OBJC_PR_readonly)
+        rewriteAttribute("retain", "strong", atLoc);
+      else
+        removeAttribute("retain", atLoc); // strong is the default.
       return;
     }
 
@@ -215,6 +218,10 @@
     }
   }
 
+  bool removeAttribute(StringRef fromAttr, SourceLocation atLoc) const {
+    return rewriteAttribute(fromAttr, StringRef(), atLoc);
+  }
+
   bool rewriteAttribute(StringRef fromAttr, StringRef toAttr,
                         SourceLocation atLoc) const {
     if (atLoc.isMacroID())
@@ -248,6 +255,11 @@
     lexer.LexFromRawLexer(tok);
     if (tok.isNot(tok::l_paren)) return false;
     
+    Token BeforeTok = tok;
+    Token AfterTok;
+    AfterTok.startToken();
+    SourceLocation AttrLoc;
+    
     lexer.LexFromRawLexer(tok);
     if (tok.is(tok::r_paren))
       return false;
@@ -256,18 +268,40 @@
       if (tok.isNot(tok::raw_identifier)) return false;
       StringRef ident(tok.getRawIdentifierData(), tok.getLength());
       if (ident == fromAttr) {
-        Pass.TA.replaceText(tok.getLocation(), fromAttr, toAttr);
-        return true;
+        if (!toAttr.empty()) {
+          Pass.TA.replaceText(tok.getLocation(), fromAttr, toAttr);
+          return true;
+        }
+        // We want to remove the attribute.
+        AttrLoc = tok.getLocation();
       }
 
       do {
         lexer.LexFromRawLexer(tok);
+        if (AttrLoc.isValid() && AfterTok.is(tok::unknown))
+          AfterTok = tok;
       } while (tok.isNot(tok::comma) && tok.isNot(tok::r_paren));
       if (tok.is(tok::r_paren))
         break;
+      if (AttrLoc.isInvalid())
+        BeforeTok = tok;
       lexer.LexFromRawLexer(tok);
     }
 
+    if (toAttr.empty() && AttrLoc.isValid() && AfterTok.isNot(tok::unknown)) {
+      // We want to remove the attribute.
+      if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::r_paren)) {
+        Pass.TA.remove(SourceRange(BeforeTok.getLocation(),
+                                   AfterTok.getLocation()));
+      } else if (BeforeTok.is(tok::l_paren) && AfterTok.is(tok::comma)) {
+        Pass.TA.remove(SourceRange(AttrLoc, AfterTok.getLocation()));
+      } else {
+        Pass.TA.remove(SourceRange(BeforeTok.getLocation(), AttrLoc));
+      }
+
+      return true;
+    }
+    
     return false;
   }
 

Modified: cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m?rev=142304&r1=142303&r2=142304&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m (original)
+++ cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m Mon Oct 17 18:14:16 2011
@@ -36,12 +36,18 @@
 
 @property (assign) Foo *no_user_ivar1;
 @property (readonly) Foo *no_user_ivar2;
+
+ at property (retain) id def1;
+ at property (atomic,retain) id def2;
+ at property (retain,atomic) id def3;
+
 @end
 
 @implementation Foo
 @synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3;
 @synthesize no_user_ivar1, no_user_ivar2;
 @synthesize assign_plus1, assign_plus2, assign_plus3;
+ at synthesize def1, def2, def3;
 
 -(void)test:(Foo *)parm {
   assign_plus1 = [[Foo alloc] init];

Modified: cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m.result?rev=142304&r1=142303&r2=142304&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m.result (original)
+++ cfe/trunk/test/ARCMT/assign-prop-with-arc-runtime.m.result Mon Oct 17 18:14:16 2011
@@ -36,12 +36,18 @@
 
 @property (weak) Foo *no_user_ivar1;
 @property (weak, readonly) Foo *no_user_ivar2;
+
+ at property  id def1;
+ at property (atomic) id def2;
+ at property (atomic) id def3;
+
 @end
 
 @implementation Foo
 @synthesize x,w,q1,q2,oo,bcw,not_safe1,not_safe2,not_safe3;
 @synthesize no_user_ivar1, no_user_ivar2;
 @synthesize assign_plus1, assign_plus2, assign_plus3;
+ at synthesize def1, def2, def3;
 
 -(void)test:(Foo *)parm {
   assign_plus1 = [[Foo alloc] init];

Modified: cfe/trunk/test/ARCMT/releases-driver.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/releases-driver.m.result?rev=142304&r1=142303&r2=142304&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/releases-driver.m.result (original)
+++ cfe/trunk/test/ARCMT/releases-driver.m.result Mon Oct 17 18:14:16 2011
@@ -20,7 +20,7 @@
 @interface Foo : NSObject {
   id bar;
 }
- at property (strong) id bar;
+ at property  id bar;
 -(void)test:(id)obj;
 @end
 

Modified: cfe/trunk/test/ARCMT/releases.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/releases.m.result?rev=142304&r1=142303&r2=142304&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/releases.m.result (original)
+++ cfe/trunk/test/ARCMT/releases.m.result Mon Oct 17 18:14:16 2011
@@ -20,7 +20,7 @@
 @interface Foo : NSObject {
   id bar;
 }
- at property (strong) id bar;
+ at property  id bar;
 -(void)test:(id)obj;
 @end
 

Modified: cfe/trunk/test/ARCMT/remove-dealloc-method.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/remove-dealloc-method.m.result?rev=142304&r1=142303&r2=142304&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/remove-dealloc-method.m.result (original)
+++ cfe/trunk/test/ARCMT/remove-dealloc-method.m.result Mon Oct 17 18:14:16 2011
@@ -5,10 +5,10 @@
 #define nil ((void*) 0)
 
 @interface Foo 
- at property (strong) id x;
- at property (strong) id y;
- at property (strong) id w;
- at property (strong) id z;
+ at property  id x;
+ at property  id y;
+ at property  id w;
+ at property  id z;
 @end
 
 @implementation Foo 

Modified: cfe/trunk/test/ARCMT/remove-dealloc-zerouts.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/remove-dealloc-zerouts.m.result?rev=142304&r1=142303&r2=142304&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/remove-dealloc-zerouts.m.result (original)
+++ cfe/trunk/test/ARCMT/remove-dealloc-zerouts.m.result Mon Oct 17 18:14:16 2011
@@ -3,10 +3,10 @@
 // RUN: diff %t %s.result
 
 @interface Foo 
- at property (strong) id x;
- at property (strong) id y;
- at property (strong) id w;
- at property (strong) id z;
+ at property  id x;
+ at property  id y;
+ at property  id w;
+ at property  id z;
 @property (strong) id q;
 @end
 
@@ -23,7 +23,7 @@
 @end
 
 @interface Bar
- at property (strong) Foo *a;
+ at property  Foo *a;
 - (void) setA:(Foo*) val;
 - (id) a;
 @end

Modified: cfe/trunk/test/ARCMT/retains.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/retains.m.result?rev=142304&r1=142303&r2=142304&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/retains.m.result (original)
+++ cfe/trunk/test/ARCMT/retains.m.result Mon Oct 17 18:14:16 2011
@@ -9,7 +9,7 @@
 @interface Foo : NSObject {
   id bar;
 }
- at property (strong) id bar;
+ at property  id bar;
 -(id)test:(id)obj;
 -(id)something;
 @end





More information about the cfe-commits mailing list