Skip to content

Commit fce6f33

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 9714127 commit fce6f33

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
@@ -7824,6 +7824,7 @@ ASTContext::getObjCPropertyImplDeclForPropertyDecl(
78247824
/// kPropertyWeak = 'W' // 'weak' property
78257825
/// kPropertyStrong = 'P' // property GC'able
78267826
/// kPropertyNonAtomic = 'N' // property non-atomic
7827+
/// kPropertyOptional = '?' // property optional
78277828
/// };
78287829
/// @endcode
78297830
std::string
@@ -7849,6 +7850,9 @@ ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
78497850
// closely resembles encoding of ivars.
78507851
getObjCEncodingForPropertyType(PD->getType(), S);
78517852

7853+
if (PD->isOptional())
7854+
S += ",?";
7855+
78527856
if (PD->isReadOnly()) {
78537857
S += ",R";
78547858
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 -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)