From 68c71b1ebc4565100d4b7ff9ed04addf34fc3d03 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 16 Jun 2015 21:04:55 +0000 Subject: [PATCH] Honor the objc_runtime_name attribute when encoding class/protocol names. While the rest of the Objective-C metadata seems to honor objc_runtime_name, the encoding strings produced by, e.g., @encode and property meta, were not. Fixes rdar://problem/21408305. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239852 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/AST/ASTContext.cpp | 11 +++++------ test/CodeGenObjC/objc-asm-attribute-test.m | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 4a831d90e6..049eebd82b 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -5610,8 +5610,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, // @encode(class_name) ObjCInterfaceDecl *OI = OIT->getDecl(); S += '{'; - const IdentifierInfo *II = OI->getIdentifier(); - S += II->getName(); + S += OI->getObjCRuntimeNameAsString(); S += '='; SmallVector Ivars; DeepCollectObjCIvars(OI, true, Ivars); @@ -5654,7 +5653,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, S += '"'; for (const auto *I : OPT->quals()) { S += '<'; - S += I->getNameAsString(); + S += I->getObjCRuntimeNameAsString(); S += '>'; } S += '"'; @@ -5678,7 +5677,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, for (unsigned i = 0, e = Ivars.size(); i != e; ++i) { if (cast(Ivars[i]) == FD) { S += '{'; - S += OI->getIdentifier()->getName(); + S += OI->getObjCRuntimeNameAsString(); S += '}'; return; } @@ -5696,10 +5695,10 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, if (OPT->getInterfaceDecl() && (FD || EncodingProperty || EncodeClassNames)) { S += '"'; - S += OPT->getInterfaceDecl()->getIdentifier()->getName(); + S += OPT->getInterfaceDecl()->getObjCRuntimeNameAsString(); for (const auto *I : OPT->quals()) { S += '<'; - S += I->getNameAsString(); + S += I->getObjCRuntimeNameAsString(); S += '>'; } S += '"'; diff --git a/test/CodeGenObjC/objc-asm-attribute-test.m b/test/CodeGenObjC/objc-asm-attribute-test.m index 589b08ae0e..7b3a64deb7 100644 --- a/test/CodeGenObjC/objc-asm-attribute-test.m +++ b/test/CodeGenObjC/objc-asm-attribute-test.m @@ -13,10 +13,19 @@ __attribute__((objc_runtime_name("MySecretNamespace.Protocol2"))) + (void) ClsMethodP2; @end +__attribute__((objc_runtime_name("MySecretNamespace.Protocol3"))) +@protocol Protocol3 +@end + __attribute__((objc_runtime_name("MySecretNamespace.Message"))) @interface Message { id MyIVAR; } + +@property(retain) Message *msgProp; +@property(retain) Message *msgProtoProp; +@property(retain) id idProtoProp; + @end @implementation Message @@ -46,9 +55,14 @@ id Test16877359() { return [SLREarth alloc]; } -// CHECK: @"OBJC_IVAR_$_MySecretNamespace.Message.MyIVAR" = global i64 +// 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: private global [42 x i8] c"T@\22MySecretNamespace.Message\22,&,V_msgProp\00" +// CHECK: private global [76 x i8] c"T@\22MySecretNamespace.Message\22,&,V_msgProtoProp\00" +// CHECK: private global [50 x i8] c"T@\22\22,&,V_idProtoProp\00" + // CHECK: @"OBJC_CLASS_$_foo" = external global %struct._class_t // CHECK: define internal i8* @"\01-[Message MyMethod]" // CHECK: [[IVAR:%.*]] = load i64, i64* @"OBJC_IVAR_$_MySecretNamespace.Message.MyIVAR" -- 2.40.0