[clang] 06f10b8 - [Clang][ObjC] Add optionality to property attribute strings. (#66507)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 26 08:30:35 PDT 2023
Author: Alastair Houghton
Date: 2023-09-26T08:30:31-07:00
New Revision: 06f10b80847a75b9329174fa7eb0388e214eb19b
URL: https://github.com/llvm/llvm-project/commit/06f10b80847a75b9329174fa7eb0388e214eb19b
DIFF: https://github.com/llvm/llvm-project/commit/06f10b80847a75b9329174fa7eb0388e214eb19b.diff
LOG: [Clang][ObjC] Add optionality to property attribute strings. (#66507)
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
Added:
Modified:
clang/lib/AST/ASTContext.cpp
clang/test/CodeGenObjC/objc-asm-attribute-test.m
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4b1d9e86797b778..57aaa05b1d81ddb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -7890,6 +7890,7 @@ ASTContext::getObjCPropertyImplDeclForPropertyDecl(
/// kPropertyWeak = 'W' // 'weak' property
/// kPropertyStrong = 'P' // property GC'able
/// kPropertyNonAtomic = 'N' // property non-atomic
+/// kPropertyOptional = '?' // property optional
/// };
/// @endcode
std::string
@@ -7915,6 +7916,9 @@ ASTContext::getObjCEncodingForPropertyDecl(const ObjCPropertyDecl *PD,
// 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
index 876370115bfc424..e57e42535f67274 100644
--- 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 -emit-llvm -triple x86_64-apple-darwin %s -o - | FileCheck %s
+// RUN: %clang_cc1 -Wno-objc-root-class -emit-llvm -triple x86_64-apple-darwin %s -o - | FileCheck %s
__attribute__((objc_runtime_name("MySecretNamespace.Protocol")))
@protocol Protocol
@@ -10,6 +10,10 @@ + (void) ClsMethodP;
@protocol Protocol2
- (void) MethodP2;
+ (void) ClsMethodP2;
+
+ at optional
+ at property(retain) id optionalProp;
+
@end
__attribute__((objc_runtime_name("MySecretNamespace.Protocol3")))
@@ -57,6 +61,10 @@ id Test16877359(void) {
// 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"
+// CHECK-NEXT: @OBJC_PROP_NAME_ATTR_.11 = private unnamed_addr constant [7 x i8] c"T@,?,&\00"
+// CHECK: @"_OBJC_$_PROP_LIST_MySecretNamespace.Protocol2" ={{.*}} [%struct._prop_t { ptr @OBJC_PROP_NAME_ATTR_, ptr @OBJC_PROP_NAME_ATTR_.11 }]
+
// 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<MySecretNamespace.Protocol3>\22,&,V_msgProtoProp\00"
// CHECK: private unnamed_addr constant [50 x i8] c"T@\22<MySecretNamespace.Protocol3>\22,&,V_idProtoProp\00"
More information about the cfe-commits
mailing list