From: Fariborz Jahanian Date: Thu, 5 Feb 2009 01:13:09 +0000 (+0000) Subject: This patch generates messaging code for objc2's non-fragile abi. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ef163782d227f064df5988d46487609324a0169e;p=clang This patch generates messaging code for objc2's non-fragile abi. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@63810 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index a8ea12d994..cce12a4283 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -276,6 +276,9 @@ public: // MessageRefCPtrTy - clang type for struct _message_ref_t* QualType MessageRefCPtrTy; + // MessengerTy - Type of the messenger (shown as IMP above) + const llvm::FunctionType *MessengerTy; + // SuperMessageRefTy - LLVM for: // struct _super_message_ref_t { // SUPER_IMP messenger; @@ -3235,10 +3238,11 @@ ObjCNonFragileABITypesHelper::ObjCNonFragileABITypesHelper(CodeGen::CodeGenModul Params.clear(); Params.push_back(ObjectPtrTy); Params.push_back(MessageRefPtrTy); + MessengerTy = llvm::FunctionType::get(ObjectPtrTy, + Params, + true); MessageSendFixupFn = - CGM.CreateRuntimeFunction(llvm::FunctionType::get(ObjectPtrTy, - Params, - true), + CGM.CreateRuntimeFunction(MessengerTy, "objc_msgSend_fixup"); // id objc_msgSend_fpret_fixup (id, struct message_ref_t*, ...) @@ -4290,6 +4294,8 @@ CodeGen::RValue CGObjCNonFragileABIMac::EmitMessageSend( CGF.Builder.CreateBitCast(Receiver, ObjCTypes.ObjectPtrTy, "tmp"); // Find the message function name. + // FIXME. This is too much work to get the ABI-specific result type + // needed to find the message name. const CGFunctionInfo &FnInfo = Types.getFunctionInfo(ResultType, llvm::SmallVector()); llvm::Constant *Fn; @@ -4346,12 +4352,23 @@ CodeGen::RValue CGObjCNonFragileABIMac::EmitMessageSend( UsedGlobals.push_back(GV); } llvm::Value *Arg1 = CGF.Builder.CreateBitCast(GV, ObjCTypes.MessageRefPtrTy); + CallArgList ActualArgs; ActualArgs.push_back(std::make_pair(RValue::get(Arg0), Arg0Ty)); ActualArgs.push_back(std::make_pair(RValue::get(Arg1), ObjCTypes.MessageRefCPtrTy)); ActualArgs.insert(ActualArgs.end(), CallArgs.begin(), CallArgs.end()); - return RValue::get(0); + const CGFunctionInfo &FnInfo1 = Types.getFunctionInfo(ResultType, ActualArgs); + llvm::Value *Callee = CGF.Builder.CreateStructGEP(Arg1, 0); + Callee = CGF.Builder.CreateLoad(Callee); + const llvm::Type *T = llvm::PointerType::getUnqual(ObjCTypes.MessengerTy); + T = llvm::PointerType::getUnqual(T); + Callee = CGF.Builder.CreateBitCast(Callee, T); + Callee = CGF.Builder.CreateLoad(Callee); + const llvm::FunctionType *FTy = Types.GetFunctionType(FnInfo1, false); + Callee = CGF.Builder.CreateBitCast(Callee, + llvm::PointerType::getUnqual(FTy)); + return CGF.EmitCall(FnInfo1, Callee, ActualArgs); } /// Generate code for a message send expression in the nonfragile abi.