Skip to content

Commit dd8c3b5

Browse files
committed
[Clang][ObjC] Add optionality to property attribute strings.
Add a new attribute, "?", to the property attribute string for properties of protocols that are declared @optional. (Previously https://reviews.llvm.org/D135273) rdar://100463524
1 parent 1511e98 commit dd8c3b5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7847,6 +7847,7 @@ ASTContext::getObjCPropertyImplDeclForPropertyDecl(
78477847
/// kPropertyWeak = 'W' // 'weak' property
78487848
/// kPropertyStrong = 'P' // property GC'able
78497849
/// kPropertyNonAtomic = 'N' // property non-atomic
7850+
/// kPropertyOptional = '?' // property optional
78507851
/// };
78517852
/// @endcode
78527853
std::string
@@ -7872,6 +7873,9 @@ ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
78727873
// closely resembles encoding of ivars.
78737874
getObjCEncodingForPropertyType(PD->getType(), S);
78747875

7876+
if (PD->isOptional())
7877+
S += ",?";
7878+
78757879
if (PD->isReadOnly()) {
78767880
S += ",R";
78777881
if (PD->getPropertyAttributes() & ObjCPropertyAttribute::kind_copy)

clang/test/CodeGenObjC/objc-asm-attribute-test.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -no-opaque-pointers -emit-llvm -triple x86_64-apple-darwin %s -o - | FileCheck %s
1+
// RUN: %clang_cc1 -Wno-objc-root-class -no-opaque-pointers -emit-llvm -triple x86_64-apple-darwin %s -o - | FileCheck %s
22
// rdar://16462586
33

44
__attribute__((objc_runtime_name("MySecretNamespace.Protocol")))
@@ -11,6 +11,10 @@ + (void) ClsMethodP;
1111
@protocol Protocol2
1212
- (void) MethodP2;
1313
+ (void) ClsMethodP2;
14+
15+
@optional
16+
@property(retain) id optionalProp;
17+
1418
@end
1519

1620
__attribute__((objc_runtime_name("MySecretNamespace.Protocol3")))
@@ -59,6 +63,10 @@ id Test16877359(void) {
5963
// CHECK: @"OBJC_CLASS_$_MySecretNamespace.Message" ={{.*}} global %struct._class_t
6064
// CHECK: @"OBJC_METACLASS_$_MySecretNamespace.Message" ={{.*}} global %struct._class_t
6165

66+
// CHECK: @OBJC_PROP_NAME_ATTR_ = private unnamed_addr constant [13 x i8] c"optionalProp\00"
67+
// CHECK-NEXT: @OBJC_PROP_NAME_ATTR_.11 = private unnamed_addr constant [7 x i8] c"T@,?,&\00"
68+
// CHECK: @"_OBJC_$_PROP_LIST_MySecretNamespace.Protocol2" ={{.*}} [%struct._prop_t { ptr @OBJC_PROP_NAME_ATTR_, ptr @OBJC_PROP_NAME_ATTR_.11 }]
69+
6270
// CHECK: private unnamed_addr constant [42 x i8] c"T@\22MySecretNamespace.Message\22,&,V_msgProp\00"
6371
// CHECK: private unnamed_addr constant [76 x i8] c"T@\22MySecretNamespace.Message<MySecretNamespace.Protocol3>\22,&,V_msgProtoProp\00"
6472
// CHECK: private unnamed_addr constant [50 x i8] c"T@\22<MySecretNamespace.Protocol3>\22,&,V_idProtoProp\00"

0 commit comments

Comments
 (0)