From c72b4b396a9b87cf9cdb9958308d82fd32bdb846 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 9 Sep 2013 23:56:14 +0000 Subject: [PATCH] ObjectiveC migrator. Do not infer NS_RETURNS_INNER_POINTER annotation on methods which return typedef of pointer to an incomplete struct type. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190372 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ARCMigrate/ObjCMT.cpp | 14 ++++++++++++++ test/ARCMT/objcmt-ns-returns-inner-pointer.m | 10 ++++++++++ .../ARCMT/objcmt-ns-returns-inner-pointer.m.result | 10 ++++++++++ 3 files changed, 34 insertions(+) diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 702149e018..f91741abf8 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -694,6 +694,20 @@ static bool TypeIsInnerPointer(QualType T) { if (T->isObjCObjectPointerType() || T->isObjCBuiltinType() || T->isBlockPointerType() || ento::coreFoundation::isCFObjectRef(T)) return false; + // Also, typedef-of-pointer-to-incomplete-struct is something that we assume + // is not an innter pointer type. + QualType OrigT = T; + while (const TypedefType *TD = dyn_cast(T.getTypePtr())) + T = TD->getDecl()->getUnderlyingType(); + if (OrigT == T || !T->isPointerType()) + return true; + const PointerType* PT = T->getAs(); + QualType UPointeeT = PT->getPointeeType().getUnqualifiedType(); + if (UPointeeT->isRecordType()) { + const RecordType *RecordTy = UPointeeT->getAs(); + if (!RecordTy->getDecl()->isCompleteDefinition()) + return false; + } return true; } diff --git a/test/ARCMT/objcmt-ns-returns-inner-pointer.m b/test/ARCMT/objcmt-ns-returns-inner-pointer.m index f1a57bde96..404928398f 100644 --- a/test/ARCMT/objcmt-ns-returns-inner-pointer.m +++ b/test/ARCMT/objcmt-ns-returns-inner-pointer.m @@ -75,6 +75,10 @@ typedef struct __CFDictionary * CFMutableDictionaryRef; typedef struct CGImage *CGImageRef; +typedef struct OpaqueJSValue* JSObjectRef; + +typedef JSObjectRef TTJSObjectRef; + CF_IMPLICIT_BRIDGING_DISABLED @interface I @@ -94,3 +98,9 @@ CF_IMPLICIT_BRIDGING_DISABLED @interface NSMutableData - (void *)mutableBytes __attribute__((deprecated)) __attribute__((unavailable)); @end + +@interface JS +- (JSObjectRef)JSObject; +- (TTJSObjectRef)JSObject1; +- (JSObjectRef*)JSObject2; +@end diff --git a/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result b/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result index 40d4f66356..c3f151ab22 100644 --- a/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result +++ b/test/ARCMT/objcmt-ns-returns-inner-pointer.m.result @@ -75,6 +75,10 @@ typedef struct __CFDictionary * CFMutableDictionaryRef; typedef struct CGImage *CGImageRef; +typedef struct OpaqueJSValue* JSObjectRef; + +typedef JSObjectRef TTJSObjectRef; + CF_IMPLICIT_BRIDGING_DISABLED @interface I @@ -94,3 +98,9 @@ CF_IMPLICIT_BRIDGING_DISABLED @interface NSMutableData - (void *)mutableBytes __attribute__((deprecated)) __attribute__((unavailable)) NS_RETURNS_INNER_POINTER; @end + +@interface JS +- (JSObjectRef)JSObject; +- (TTJSObjectRef)JSObject1; +- (JSObjectRef*)JSObject2 NS_RETURNS_INNER_POINTER; +@end -- 2.40.0