From 0b3bc24e393b558f7f1934eb1be09b7883a8842e Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 10 Jun 2014 17:08:04 +0000 Subject: [PATCH] Objective-C IRGen. Patch to generate a weak symbol reference when 'super' dispatches a class method in category for OBJC_METACLASS. This is when class is a weak_import class. // rdar://16529125 llvm-svn: 210547 --- clang/lib/CodeGen/CGObjCMac.cpp | 11 +++++++---- clang/test/CodeGenObjC/weak-metaclass-visibility.m | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 1d2b7a7e462e..88ad7f151368 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -1389,7 +1389,7 @@ private: /// EmitMetaClassRef - Return a Value * of the address of _class_t /// meta-data llvm::Value *EmitMetaClassRef(CodeGenFunction &CGF, - const ObjCInterfaceDecl *ID); + const ObjCInterfaceDecl *ID, bool Weak); /// ObjCIvarOffsetVariable - Returns the ivar offset variable for /// the given ivar. @@ -6702,13 +6702,15 @@ CGObjCNonFragileABIMac::EmitSuperClassRef(CodeGenFunction &CGF, /// meta-data /// llvm::Value *CGObjCNonFragileABIMac::EmitMetaClassRef(CodeGenFunction &CGF, - const ObjCInterfaceDecl *ID) { + const ObjCInterfaceDecl *ID, + bool Weak) { llvm::GlobalVariable * &Entry = MetaClassReferences[ID->getIdentifier()]; if (!Entry) { std::string MetaClassName(getMetaclassSymbolPrefix() + ID->getNameAsString()); - llvm::GlobalVariable *MetaClassGV = GetClassGlobal(MetaClassName); + llvm::GlobalVariable *MetaClassGV = + GetClassGlobal(MetaClassName, Weak); Entry = new llvm::GlobalVariable(CGM.getModule(), ObjCTypes.ClassnfABIPtrTy, false, llvm::GlobalValue::PrivateLinkage, MetaClassGV, @@ -6766,7 +6768,8 @@ CGObjCNonFragileABIMac::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, // If this is a class message the metaclass is passed as the target. llvm::Value *Target; if (IsClassMessage) - Target = EmitMetaClassRef(CGF, Class); + Target = EmitMetaClassRef(CGF, Class, + (isCategoryImpl && Class->isWeakImported())); else Target = EmitSuperClassRef(CGF, Class); diff --git a/clang/test/CodeGenObjC/weak-metaclass-visibility.m b/clang/test/CodeGenObjC/weak-metaclass-visibility.m index 1f76197d8441..128f881a5c00 100644 --- a/clang/test/CodeGenObjC/weak-metaclass-visibility.m +++ b/clang/test/CodeGenObjC/weak-metaclass-visibility.m @@ -3,6 +3,7 @@ @interface NSObject - (void) finalize; ++ (void) class; @end __attribute__((availability(macosx,introduced=9876.5))) @@ -31,3 +32,14 @@ void kit() // CHECK: @"OBJC_METACLASS_$_MyClass" = global %struct._class_t // CHECK: @"OBJC_CLASS_$_NSObject" = external global %struct._class_t +// rdar://16529125 +__attribute__((weak_import)) +@interface NSURLQueryItem : NSObject +@end + +@implementation NSURLQueryItem (hax) ++(void)classmethod { [super class]; } +@end + +// CHECK: @"OBJC_METACLASS_$_NSURLQueryItem" = extern_weak global +// CHECK: @"OBJC_CLASS_$_NSURLQueryItem" = extern_weak global