r194233 - ObjectiveC migrator. Fixes an obscure bug where

Fariborz Jahanian fjahanian at apple.com
Thu Nov 7 17:15:18 PST 2013


Author: fjahanian
Date: Thu Nov  7 19:15:17 2013
New Revision: 194233

URL: http://llvm.org/viewvc/llvm-project?rev=194233&view=rev
Log:
ObjectiveC migrator. Fixes an obscure bug where
NS_RETURNS_INNER_POINTER ends up unintentionally 
on the @property under -objcmt-migrate-all 
// rdar://15396636

Added:
    cfe/trunk/test/ARCMT/objcmt-migrate-all.m
    cfe/trunk/test/ARCMT/objcmt-migrate-all.m.result
Modified:
    cfe/trunk/include/clang/Frontend/FrontendOptions.h
    cfe/trunk/lib/ARCMigrate/ObjCMT.cpp

Modified: cfe/trunk/include/clang/Frontend/FrontendOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/FrontendOptions.h?rev=194233&r1=194232&r2=194233&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h Thu Nov  7 19:15:17 2013
@@ -183,8 +183,7 @@ public:
     ObjCMT_MigrateAll = (ObjCMT_Literals | ObjCMT_Subscripting |
                          ObjCMT_ReadonlyProperty | ObjCMT_ReadwriteProperty |
                          ObjCMT_Annotation | ObjCMT_Instancetype |
-                         ObjCMT_NsMacros | ObjCMT_ProtocolConformance |
-                         ObjCMT_ReturnsInnerPointerProperty)
+                         ObjCMT_NsMacros | ObjCMT_ProtocolConformance)
   };
   unsigned ObjCMTAction;
 

Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=194233&r1=194232&r2=194233&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Thu Nov  7 19:15:17 2013
@@ -412,8 +412,12 @@ void ObjCMigrateASTConsumer::migrateObjC
     ObjCMethodDecl *Method = (*M);
     if (Method->isDeprecated())
       continue;
-    migrateProperty(Ctx, D, Method);
-    if (ASTMigrateActions & FrontendOptions::ObjCMT_Annotation)
+    bool PropertyInferred = migrateProperty(Ctx, D, Method);
+    // If a property is inferred, do not attempt to attach NS_RETURNS_INNER_POINTER to
+    // the getter method as it ends up on the property itself which we don't want
+    // to do unless -objcmt-returns-innerpointer-property  option is on.
+    if (!PropertyInferred ||
+        (ASTMigrateActions & FrontendOptions::ObjCMT_ReturnsInnerPointerProperty))
       migrateNsReturnsInnerPointer(Ctx, Method);
   }
   if (!(ASTMigrateActions & FrontendOptions::ObjCMT_ReturnsInnerPointerProperty))

Added: cfe/trunk/test/ARCMT/objcmt-migrate-all.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-migrate-all.m?rev=194233&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-migrate-all.m (added)
+++ cfe/trunk/test/ARCMT/objcmt-migrate-all.m Thu Nov  7 19:15:17 2013
@@ -0,0 +1,135 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -objcmt-migrate-all -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11
+// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result
+// rdar://15396636
+
+#ifndef NS_RETURNS_INNER_POINTER // defined in iOS 6 for sure
+#define NS_RETURNS_INNER_POINTER __attribute__((objc_returns_inner_pointer))
+#endif
+
+#define CF_IMPLICIT_BRIDGING_ENABLED _Pragma("clang arc_cf_code_audited begin")
+
+#define CF_IMPLICIT_BRIDGING_DISABLED _Pragma("clang arc_cf_code_audited end")
+
+#if __has_feature(attribute_ns_returns_retained)
+#define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
+#endif
+#if __has_feature(attribute_cf_returns_retained)
+#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
+#endif
+#if __has_feature(attribute_ns_returns_not_retained)
+#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
+#endif
+#if __has_feature(attribute_cf_returns_not_retained)
+#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
+#endif
+#if __has_feature(attribute_ns_consumes_self)
+#define NS_CONSUMES_SELF __attribute__((ns_consumes_self))
+#endif
+#if __has_feature(attribute_ns_consumed)
+#define NS_CONSUMED __attribute__((ns_consumed))
+#endif
+#if __has_feature(attribute_cf_consumed)
+#define CF_CONSUMED __attribute__((cf_consumed))
+#endif
+#if __has_attribute(ns_returns_autoreleased)
+#define NS_RETURNS_AUTORELEASED __attribute__((ns_returns_autoreleased))
+#endif
+
+#define NS_AVAILABLE __attribute__((availability(macosx,introduced=10.0)))
+
+CF_IMPLICIT_BRIDGING_ENABLED
+
+typedef unsigned long CFTypeID;
+typedef unsigned long CFOptionFlags;
+typedef unsigned long CFHashCode;
+
+typedef signed long CFIndex; /*AnyObj*/
+typedef const struct __CFArray * CFArrayRef;
+typedef struct {
+    CFIndex location;
+    CFIndex length;
+} CFRange;
+
+typedef void (*CFArrayApplierFunction)(const void *value, void *context);
+
+typedef enum CFComparisonResult : CFIndex CFComparisonResult; enum CFComparisonResult : CFIndex {
+    kCFCompareLessThan = -1L,
+    kCFCompareEqualTo = 0,
+    kCFCompareGreaterThan = 1
+};
+
+
+typedef CFComparisonResult (*CFComparatorFunction)(const void *val1, const void *val2, void *context);
+
+typedef struct __CFArray * CFMutableArrayRef;
+
+typedef const struct __CFAttributedString *CFAttributedStringRef;
+typedef struct __CFAttributedString *CFMutableAttributedStringRef;
+
+typedef const struct __CFAllocator * CFAllocatorRef;
+
+typedef const struct __CFString * CFStringRef;
+typedef struct __CFString * CFMutableStringRef;
+
+typedef const struct __CFDictionary * CFDictionaryRef;
+typedef struct __CFDictionary * CFMutableDictionaryRef;
+
+typedef struct CGImage *CGImageRef;
+
+typedef struct OpaqueJSValue* JSObjectRef;
+
+typedef JSObjectRef TTJSObjectRef;
+typedef unsigned int NSUInteger;
+
+CF_IMPLICIT_BRIDGING_DISABLED
+
+ at interface I
+- (void*) ReturnsInnerPointer;
+- (int*)  AlreadyReturnsInnerPointer NS_RETURNS_INNER_POINTER;
+ at end
+
+ at interface UIImage
+- (CGImageRef)CGImage;
+ at end
+
+ at interface NSData
+- (void *)bytes;
+- (void **) ptr_bytes __attribute__((availability(macosx,unavailable)));
+ at end
+
+ at interface NSMutableData
+- (void *)mutableBytes  __attribute__((deprecated)) __attribute__((unavailable));
+ at end
+
+ at interface JS
+- (JSObjectRef)JSObject; 
+- (TTJSObjectRef)JSObject1;
+- (JSObjectRef*)JSObject2;
+ at end
+
+// rdar://15044991
+typedef void *SecTrustRef;
+
+ at interface NSURLProtectionSpace
+ at property (readonly) SecTrustRef serverTrust NS_AVAILABLE;
+- (void *) FOO NS_AVAILABLE;
+ at property (readonly) void * mitTrust NS_AVAILABLE;
+
+ at property (readonly) void * mittiTrust;
+
+ at property (readonly) SecTrustRef XserverTrust;
+
+- (SecTrustRef) FOO1 NS_AVAILABLE;
+
++ (const NSURLProtectionSpace *)ProtectionSpace;
+
+// pointer personality functions
+ at property NSUInteger (*hashFunction)(const void *item, NSUInteger (*size)(const void *item));
+ at end
+
+ at interface MustNotMigrateToInnerPointer
+- (void*) nono;
+- (void) setNono : (void*) val;
+ at end

Added: cfe/trunk/test/ARCMT/objcmt-migrate-all.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-migrate-all.m.result?rev=194233&view=auto
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-migrate-all.m.result (added)
+++ cfe/trunk/test/ARCMT/objcmt-migrate-all.m.result Thu Nov  7 19:15:17 2013
@@ -0,0 +1,134 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -objcmt-migrate-all -mt-migrate-directory %t %s -x objective-c -fobjc-runtime-has-weak -fobjc-arc -triple x86_64-apple-darwin11
+// RUN: c-arcmt-test -mt-migrate-directory %t | arcmt-test -verify-transformed-files %s.result
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -x objective-c -fobjc-runtime-has-weak -fobjc-arc %s.result
+// rdar://15396636
+
+#ifndef NS_RETURNS_INNER_POINTER // defined in iOS 6 for sure
+#define NS_RETURNS_INNER_POINTER __attribute__((objc_returns_inner_pointer))
+#endif
+
+#define CF_IMPLICIT_BRIDGING_ENABLED _Pragma("clang arc_cf_code_audited begin")
+
+#define CF_IMPLICIT_BRIDGING_DISABLED _Pragma("clang arc_cf_code_audited end")
+
+#if __has_feature(attribute_ns_returns_retained)
+#define NS_RETURNS_RETAINED __attribute__((ns_returns_retained))
+#endif
+#if __has_feature(attribute_cf_returns_retained)
+#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
+#endif
+#if __has_feature(attribute_ns_returns_not_retained)
+#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
+#endif
+#if __has_feature(attribute_cf_returns_not_retained)
+#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
+#endif
+#if __has_feature(attribute_ns_consumes_self)
+#define NS_CONSUMES_SELF __attribute__((ns_consumes_self))
+#endif
+#if __has_feature(attribute_ns_consumed)
+#define NS_CONSUMED __attribute__((ns_consumed))
+#endif
+#if __has_feature(attribute_cf_consumed)
+#define CF_CONSUMED __attribute__((cf_consumed))
+#endif
+#if __has_attribute(ns_returns_autoreleased)
+#define NS_RETURNS_AUTORELEASED __attribute__((ns_returns_autoreleased))
+#endif
+
+#define NS_AVAILABLE __attribute__((availability(macosx,introduced=10.0)))
+
+CF_IMPLICIT_BRIDGING_ENABLED
+
+typedef unsigned long CFTypeID;
+typedef unsigned long CFOptionFlags;
+typedef unsigned long CFHashCode;
+
+typedef signed long CFIndex; /*AnyObj*/
+typedef const struct __CFArray * CFArrayRef;
+typedef struct {
+    CFIndex location;
+    CFIndex length;
+} CFRange;
+
+typedef void (*CFArrayApplierFunction)(const void *value, void *context);
+
+typedef enum CFComparisonResult : CFIndex CFComparisonResult; enum CFComparisonResult : CFIndex {
+    kCFCompareLessThan = -1L,
+    kCFCompareEqualTo = 0,
+    kCFCompareGreaterThan = 1
+};
+
+
+typedef CFComparisonResult (*CFComparatorFunction)(const void *val1, const void *val2, void *context);
+
+typedef struct __CFArray * CFMutableArrayRef;
+
+typedef const struct __CFAttributedString *CFAttributedStringRef;
+typedef struct __CFAttributedString *CFMutableAttributedStringRef;
+
+typedef const struct __CFAllocator * CFAllocatorRef;
+
+typedef const struct __CFString * CFStringRef;
+typedef struct __CFString * CFMutableStringRef;
+
+typedef const struct __CFDictionary * CFDictionaryRef;
+typedef struct __CFDictionary * CFMutableDictionaryRef;
+
+typedef struct CGImage *CGImageRef;
+
+typedef struct OpaqueJSValue* JSObjectRef;
+
+typedef JSObjectRef TTJSObjectRef;
+typedef unsigned int NSUInteger;
+
+CF_IMPLICIT_BRIDGING_DISABLED
+
+ at interface I
+ at property (nonatomic, readonly) void *ReturnsInnerPointer;
+ at property (nonatomic, readonly) int *AlreadyReturnsInnerPointer NS_RETURNS_INNER_POINTER;
+ at end
+
+ at interface UIImage
+ at property (nonatomic, readonly) CGImageRef CGImage CF_RETURNS_NOT_RETAINED;
+ at end
+
+ at interface NSData
+ at property (nonatomic, readonly) void *bytes;
+ at property (nonatomic, readonly) void **ptr_bytes __attribute__((availability(macosx,unavailable)));
+ at end
+
+ at interface NSMutableData
+ at property (nonatomic, readonly) void *mutableBytes  __attribute__((deprecated)) __attribute__((unavailable));
+ at end
+
+ at interface JS
+ at property (nonatomic, readonly) JSObjectRef JSObject; 
+ at property (nonatomic, readonly) TTJSObjectRef JSObject1;
+ at property (nonatomic, readonly) JSObjectRef *JSObject2;
+ at end
+
+// rdar://15044991
+typedef void *SecTrustRef;
+
+ at interface NSURLProtectionSpace
+ at property (readonly) SecTrustRef serverTrust NS_AVAILABLE;
+ at property (nonatomic, readonly) void *FOO NS_AVAILABLE;
+ at property (readonly) void * mitTrust NS_AVAILABLE;
+
+ at property (readonly) void * mittiTrust;
+
+ at property (readonly) SecTrustRef XserverTrust;
+
+ at property (nonatomic, readonly) SecTrustRef FOO1 NS_AVAILABLE;
+
++ (const NSURLProtectionSpace *)ProtectionSpace;
+
+// pointer personality functions
+ at property NSUInteger (*hashFunction)(const void *item, NSUInteger (*size)(const void *item));
+ at end
+
+ at interface MustNotMigrateToInnerPointer
+ at property (nonatomic) void *nono;
+ at end





More information about the cfe-commits mailing list