diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -7828,6 +7828,7 @@ /// kPropertyWeak = 'W' // 'weak' property /// kPropertyStrong = 'P' // property GC'able /// kPropertyNonAtomic = 'N' // property non-atomic +/// kPropertyOptional = '?' // property optional /// }; /// @endcode std::string @@ -7853,6 +7854,10 @@ // closely resembles encoding of ivars. getObjCEncodingForPropertyType(PD->getType(), S); + if (PD->isOptional()) { + S += ",?"; + } + if (PD->isReadOnly()) { S += ",R"; if (PD->getPropertyAttributes() & ObjCPropertyAttribute::kind_copy) diff --git a/clang/test/CodeGenObjC/objc-asm-attribute-test.m b/clang/test/CodeGenObjC/objc-asm-attribute-test.m --- a/clang/test/CodeGenObjC/objc-asm-attribute-test.m +++ b/clang/test/CodeGenObjC/objc-asm-attribute-test.m @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple x86_64-apple-darwin %s -o - | FileCheck %s +// RUN: %clang_cc1 -no-opaque-pointers -Wno-objc-root-class -emit-llvm -triple x86_64-apple-darwin %s -o - | FileCheck %s // rdar://16462586 __attribute__((objc_runtime_name("MySecretNamespace.Protocol"))) @@ -11,10 +11,17 @@ @protocol Protocol2 - (void) MethodP2; + (void) ClsMethodP2; + +@optional +@property(retain) id optionalProp; + @end +@class Message; + __attribute__((objc_runtime_name("MySecretNamespace.Protocol3"))) @protocol Protocol3 + @end __attribute__((objc_runtime_name("MySecretNamespace.Message"))) @@ -56,9 +63,13 @@ } // CHECK: @"OBJC_IVAR_$_MySecretNamespace.Message.MyIVAR" ={{.*}} global i64 0 + // CHECK: @"OBJC_CLASS_$_MySecretNamespace.Message" ={{.*}} global %struct._class_t // CHECK: @"OBJC_METACLASS_$_MySecretNamespace.Message" ={{.*}} global %struct._class_t +// CHECK: @OBJC_PROP_NAME_ATTR_ = private unnamed_addr constant [13 x i8] c"optionalProp\00", section "__TEXT,__objc_methname,cstring_literals", align 1 +// CHECK-NEXT: @OBJC_PROP_NAME_ATTR_.11 = private unnamed_addr constant [7 x i8] c"T@,?,&\00", section "__TEXT,__objc_methname,cstring_literals", align 1 + // CHECK: private unnamed_addr constant [42 x i8] c"T@\22MySecretNamespace.Message\22,&,V_msgProp\00" // CHECK: private unnamed_addr constant [76 x i8] c"T@\22MySecretNamespace.Message\22,&,V_msgProtoProp\00" // CHECK: private unnamed_addr constant [50 x i8] c"T@\22\22,&,V_idProtoProp\00"