r181491 - Objective-C: Correctly encode 'retain' and 'copy' for readonly properties.

Nico Weber nicolasweber at gmx.de
Wed May 8 16:47:40 PDT 2013


Author: nico
Date: Wed May  8 18:47:40 2013
New Revision: 181491

URL: http://llvm.org/viewvc/llvm-project?rev=181491&view=rev
Log:
Objective-C: Correctly encode 'retain' and 'copy' for readonly properties.

clang would omit 'C' for 'copy' properties and '&' for 'retain' properties if
the property was also 'readonly'. Fix this, which makes clang match gcc4.2's
behavior.

Fixes PR15928.


Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/test/Rewriter/objc-modern-property-attributes.mm

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=181491&r1=181490&r2=181491&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Wed May  8 18:47:40 2013
@@ -4910,6 +4910,10 @@ void ASTContext::getObjCEncodingForPrope
 
   if (PD->isReadOnly()) {
     S += ",R";
+    if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy)
+      S += ",C";
+    if (PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain)
+      S += ",&";
   } else {
     switch (PD->getSetterKind()) {
     case ObjCPropertyDecl::Assign: break;

Modified: cfe/trunk/test/Rewriter/objc-modern-property-attributes.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-property-attributes.mm?rev=181491&r1=181490&r2=181491&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/objc-modern-property-attributes.mm (original)
+++ cfe/trunk/test/Rewriter/objc-modern-property-attributes.mm Wed May  8 18:47:40 2013
@@ -16,6 +16,10 @@ typedef void (^void_block_t)(void);
 
 @property (copy) void_block_t completionBlock;
 @property (retain) PropertyClass* Yblock;
+ at property (readonly) PropertyClass* readonlyAttr;
+ at property (readonly,copy) PropertyClass* readonlyCopyAttr;
+ at property (readonly,retain) PropertyClass* readonlyRetainAttr;
+ at property (readonly,retain,nonatomic) PropertyClass* readonlyNonatomicAttr;
 @property (copy) id ID;
 
 @end
@@ -25,6 +29,10 @@ typedef void (^void_block_t)(void);
 @dynamic r;     // attributes should be "Ti,D"
 @synthesize completionBlock=__completion; // "T@?,C,V__completion"
 @synthesize Yblock = YVAR; // "T@\"PropertyClass\",&,VYVAR"
+ at synthesize readonlyAttr;
+ at synthesize readonlyCopyAttr;
+ at synthesize readonlyRetainAttr;
+ at synthesize readonlyNonatomicAttr;
 @synthesize  ID; // "T@,C,VID"
 @end
 
@@ -32,6 +40,10 @@ typedef void (^void_block_t)(void);
 // CHECK: Ti,D
 // CHECK: T@?,C,V__completion
 // CHECK: T@\"PropertyClass\",&,VYVAR
+// CHECK: T@\"PropertyClass\",R,VreadonlyAttr
+// CHECK: T@\"PropertyClass\",R,C,VreadonlyCopyAttr
+// CHECK: T@\"PropertyClass\",R,&,VreadonlyRetainAttr
+// CHECK: T@\"PropertyClass\",R,&,N,VreadonlyNonatomicAttr
 
 @interface Test @end
 @interface Test (Category)





More information about the cfe-commits mailing list