diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-02-15 07:36:20 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-02-15 07:36:20 +0000 |
commit | 948e2589505aa1b334b2cff81b28a741db49f701 (patch) | |
tree | 48043c7ab784fc200ebe0e96f662ed6f8e080970 /lib/CodeGen/CGObjCMac.cpp | |
parent | 41577f1130fa017e91fb1ea57deab9c1a4716d0a (diff) |
Obj-C non-fragile ABI: Fix types of a few globals; these were not
creating valid LLVM structures (although they work fined).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64580 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGObjCMac.cpp')
-rw-r--r-- | lib/CodeGen/CGObjCMac.cpp | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 1a5facd1b9..2a0a4aac91 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -230,6 +230,9 @@ public: // ProtocolnfABITy = LLVM for struct _protocol_t const llvm::StructType *ProtocolnfABITy; + // ProtocolnfABIPtrTy = LLVM for struct _protocol_t* + const llvm::Type *ProtocolnfABIPtrTy; + // ProtocolListnfABITy - LLVM for struct _objc_protocol_list const llvm::StructType *ProtocolListnfABITy; @@ -3122,25 +3125,26 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul NULL); CGM.getModule().addTypeName("struct._protocol_t", ProtocolnfABITy); + + // struct _protocol_t* + ProtocolnfABIPtrTy = llvm::PointerType::getUnqual(ProtocolnfABITy); // struct _protocol_list_t { // long protocol_count; // Note, this is 32/64 bit - // struct _protocol_t[protocol_count]; + // struct _protocol_t *[protocol_count]; // } ProtocolListnfABITy = llvm::StructType::get(LongTy, llvm::ArrayType::get( - ProtocolnfABITy, 0), + ProtocolnfABIPtrTy, 0), NULL); CGM.getModule().addTypeName("struct._objc_protocol_list", ProtocolListnfABITy); + cast<llvm::OpaqueType>(ProtocolListTyHolder.get())->refineAbstractTypeTo( + ProtocolListnfABITy); // struct _objc_protocol_list* ProtocolListnfABIPtrTy = llvm::PointerType::getUnqual(ProtocolListnfABITy); - // FIXME! Is this doing the right thing? - cast<llvm::OpaqueType>(ProtocolListTyHolder.get())->refineAbstractTypeTo( - ProtocolListnfABIPtrTy); - // struct _ivar_t { // unsigned long int *offset; // pointer to ivar offset location // char *name; @@ -3605,7 +3609,7 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { std::string ClassName = ID->getNameAsString(); if (!ObjCEmptyCacheVar) { ObjCEmptyCacheVar = new llvm::GlobalVariable( - ObjCTypes.CachePtrTy, + ObjCTypes.CacheTy, false, llvm::GlobalValue::ExternalLinkage, 0, @@ -3614,8 +3618,7 @@ void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) { UsedGlobals.push_back(ObjCEmptyCacheVar); ObjCEmptyVtableVar = new llvm::GlobalVariable( - llvm::PointerType::getUnqual( - ObjCTypes.ImpnfABITy), + ObjCTypes.ImpnfABITy, false, llvm::GlobalValue::ExternalLinkage, 0, @@ -4228,16 +4231,15 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( // Use this protocol meta-data to build protocol list table in section // __DATA, __objc_protolist - llvm::Type *ptype = llvm::PointerType::getUnqual(ObjCTypes.ProtocolnfABITy); llvm::GlobalVariable *PTGV = new llvm::GlobalVariable( - ptype, false, + ObjCTypes.ProtocolnfABIPtrTy, false, llvm::GlobalValue::WeakLinkage, Entry, std::string("\01l_OBJC_LABEL_PROTOCOL_$_") +ProtocolName, &CGM.getModule()); PTGV->setAlignment( - CGM.getTargetData().getPrefTypeAlignment(ptype)); + CGM.getTargetData().getPrefTypeAlignment(ObjCTypes.ProtocolnfABIPtrTy)); PTGV->setSection("__DATA, __objc_protolist"); PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility); UsedGlobals.push_back(PTGV); @@ -4258,24 +4260,27 @@ CGObjCNonFragileABIMac::EmitProtocolList(const std::string &Name, ObjCProtocolDecl::protocol_iterator end) { std::vector<llvm::Constant*> ProtocolRefs; - for (; begin != end; ++begin) - ProtocolRefs.push_back(GetProtocolRef(*begin)); // Implemented??? - // Just return null for empty protocol lists - if (ProtocolRefs.empty()) + if (begin == end) return llvm::Constant::getNullValue(ObjCTypes.ProtocolListnfABIPtrTy); + // FIXME: We shouldn't need to do this lookup here, should we? llvm::GlobalVariable *GV = CGM.getModule().getGlobalVariable(Name, true); if (GV) - return GV; + return llvm::ConstantExpr::getBitCast(GV, + ObjCTypes.ProtocolListnfABIPtrTy); + + for (; begin != end; ++begin) + ProtocolRefs.push_back(GetProtocolRef(*begin)); // Implemented??? + // This list is null terminated. ProtocolRefs.push_back(llvm::Constant::getNullValue( - ObjCTypes.ProtocolListnfABIPtrTy)); + ObjCTypes.ProtocolnfABIPtrTy)); std::vector<llvm::Constant*> Values(2); Values[0] = llvm::ConstantInt::get(ObjCTypes.LongTy, ProtocolRefs.size() - 1); Values[1] = - llvm::ConstantArray::get(llvm::ArrayType::get(ObjCTypes.ProtocolListnfABIPtrTy, + llvm::ConstantArray::get(llvm::ArrayType::get(ObjCTypes.ProtocolnfABIPtrTy, ProtocolRefs.size()), ProtocolRefs); @@ -4289,7 +4294,8 @@ CGObjCNonFragileABIMac::EmitProtocolList(const std::string &Name, GV->setAlignment( CGM.getTargetData().getPrefTypeAlignment(Init->getType())); UsedGlobals.push_back(GV); - return llvm::ConstantExpr::getBitCast(GV, ObjCTypes.ProtocolListnfABIPtrTy); + return llvm::ConstantExpr::getBitCast(GV, + ObjCTypes.ProtocolListnfABIPtrTy); } /// GetMethodDescriptionConstant - This routine build following meta-data: |