[cfe-commits] r131496 - in /cfe/trunk: lib/CodeGen/CGObjCGNU.cpp lib/CodeGen/CGObjCMac.cpp lib/CodeGen/CGObjCRuntime.h lib/CodeGen/CodeGenModule.cpp test/CodeGenObjC/constant-string-class-1.m test/CodeGenObjC/constant-string-class.m
Fariborz Jahanian
fjahanian at apple.com
Tue May 17 15:21:16 PDT 2011
Author: fjahanian
Date: Tue May 17 17:21:16 2011
New Revision: 131496
URL: http://llvm.org/viewvc/llvm-project?rev=131496&view=rev
Log:
Patch to fix IR-gen crash generating structure ABI which implements
user specified string class via -fconstant-string-class option.
pr9914.
Added:
cfe/trunk/test/CodeGenObjC/constant-string-class-1.m
Modified:
cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
cfe/trunk/lib/CodeGen/CGObjCRuntime.h
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/test/CodeGenObjC/constant-string-class.m
Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=131496&r1=131495&r2=131496&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Tue May 17 17:21:16 2011
@@ -484,6 +484,10 @@
const CGBlockInfo &blockInfo) {
return NULLPtr;
}
+
+ virtual llvm::GlobalVariable *GetClassGlobal(const std::string &Name) {
+ return 0;
+ }
};
/// Class representing the legacy GCC Objective-C ABI. This is the default when
/// -fobjc-nonfragile-abi is not specified.
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=131496&r1=131495&r2=131496&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue May 17 17:21:16 2011
@@ -1048,6 +1048,13 @@
virtual llvm::Value *EmitIvarOffset(CodeGen::CodeGenFunction &CGF,
const ObjCInterfaceDecl *Interface,
const ObjCIvarDecl *Ivar);
+
+ /// GetClassGlobal - Return the global variable for the Objective-C
+ /// class of the given name.
+ virtual llvm::GlobalVariable *GetClassGlobal(const std::string &Name) {
+ assert(false && "CGObjCMac::GetClassGlobal");
+ return 0;
+ }
};
class CGObjCNonFragileABIMac : public CGObjCCommonMac {
@@ -1142,11 +1149,11 @@
bool IsSuper,
const CallArgList &CallArgs,
const ObjCMethodDecl *Method);
-
+
/// GetClassGlobal - Return the global variable for the Objective-C
/// class of the given name.
llvm::GlobalVariable *GetClassGlobal(const std::string &Name);
-
+
/// EmitClassRef - Return a Value*, of type ObjCTypes.ClassPtrTy,
/// for the given class reference.
llvm::Value *EmitClassRef(CGBuilderTy &Builder,
Modified: cfe/trunk/lib/CodeGen/CGObjCRuntime.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCRuntime.h?rev=131496&r1=131495&r2=131496&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCRuntime.h (original)
+++ cfe/trunk/lib/CodeGen/CGObjCRuntime.h Tue May 17 17:21:16 2011
@@ -243,6 +243,7 @@
llvm::Value *Size) = 0;
virtual llvm::Constant *BuildGCBlockLayout(CodeGen::CodeGenModule &CGM,
const CodeGen::CGBlockInfo &blockInfo) = 0;
+ virtual llvm::GlobalVariable *GetClassGlobal(const std::string &Name) = 0;
};
/// Creates an instance of an Objective-C runtime class.
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=131496&r1=131495&r2=131496&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Tue May 17 17:21:16 2011
@@ -1768,24 +1768,31 @@
if (!ConstantStringClassRef) {
std::string StringClass(getLangOptions().ObjCConstantStringClass);
const llvm::Type *Ty = getTypes().ConvertType(getContext().IntTy);
- Ty = llvm::ArrayType::get(Ty, 0);
llvm::Constant *GV;
- if (StringClass.empty())
- GV = CreateRuntimeVariable(Ty,
- Features.ObjCNonFragileABI ?
- "OBJC_CLASS_$_NSConstantString" :
- "_NSConstantStringClassReference");
- else {
+ if (Features.ObjCNonFragileABI) {
std::string str;
- if (Features.ObjCNonFragileABI)
+ if (StringClass.empty())
+ str = "OBJC_CLASS_$_NSConstantString";
+ else {
str = "OBJC_CLASS_$_" + StringClass;
- else
- str = "_" + StringClass + "ClassReference";
- GV = CreateRuntimeVariable(Ty, str);
+ }
+ GV = getObjCRuntime().GetClassGlobal(str);
+ // Make sure the result is of the correct type.
+ const llvm::Type *PTy = llvm::PointerType::getUnqual(Ty);
+ ConstantStringClassRef =
+ llvm::ConstantExpr::getBitCast(GV, PTy);
+ } else {
+ Ty = llvm::ArrayType::get(Ty, 0);
+ if (StringClass.empty())
+ GV = CreateRuntimeVariable(Ty, "_NSConstantStringClassReference");
+ else {
+ std::string str = "_" + StringClass + "ClassReference";
+ GV = CreateRuntimeVariable(Ty, str);
+ }
+ // Decay array -> ptr
+ ConstantStringClassRef =
+ llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2);
}
- // Decay array -> ptr
- ConstantStringClassRef =
- llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2);
}
QualType NSTy = getContext().getNSConstantStringType();
Added: cfe/trunk/test/CodeGenObjC/constant-string-class-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/constant-string-class-1.m?rev=131496&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/constant-string-class-1.m (added)
+++ cfe/trunk/test/CodeGenObjC/constant-string-class-1.m Tue May 17 17:21:16 2011
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fobjc-nonfragile-abi -fno-constant-cfstrings -fconstant-string-class OFConstantString -emit-llvm -o %t %s
+// pr9914
+
+ at interface OFConstantString
++ class;
+ at end
+
+ at interface OFString
+- (void)XMLElementBySerializing;
+ at end
+
+ at implementation OFString
+
+- (void)XMLElementBySerializing
+{
+ id str = @"object";
+
+ [OFConstantString class];
+}
+
+ at end
+
+// CHECK: @"OBJC_CLASS_$_OFConstantString" = external global
Modified: cfe/trunk/test/CodeGenObjC/constant-string-class.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/constant-string-class.m?rev=131496&r1=131495&r2=131496&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/constant-string-class.m (original)
+++ cfe/trunk/test/CodeGenObjC/constant-string-class.m Tue May 17 17:21:16 2011
@@ -32,4 +32,4 @@
// CHECK-FRAGILE: @_FooClassReference = common global
// CHECK-NONFRAGILE: @"OBJC_CLASS_$_Object" = external global
-// CHECK-NONFRAGILE: "OBJC_CLASS_$_Foo" = unnamed_addr global
+// CHECK-NONFRAGILE: "OBJC_CLASS_$_Foo" = global
More information about the cfe-commits
mailing list