Home | History | Annotate | Line # | Download | only in CodeGen
      1      1.1  joerg //==- CGObjCRuntime.cpp - Interface to Shared Objective-C Runtime Features ==//
      2      1.1  joerg //
      3      1.1  joerg // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
      4      1.1  joerg // See https://llvm.org/LICENSE.txt for license information.
      5      1.1  joerg // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
      6      1.1  joerg //
      7      1.1  joerg //===----------------------------------------------------------------------===//
      8      1.1  joerg //
      9      1.1  joerg // This abstract class defines the interface for Objective-C runtime-specific
     10      1.1  joerg // code generation.  It provides some concrete helper methods for functionality
     11      1.1  joerg // shared between all (or most) of the Objective-C runtimes supported by clang.
     12      1.1  joerg //
     13      1.1  joerg //===----------------------------------------------------------------------===//
     14      1.1  joerg 
     15      1.1  joerg #include "CGObjCRuntime.h"
     16      1.1  joerg #include "CGCXXABI.h"
     17  1.1.1.2  joerg #include "CGCleanup.h"
     18      1.1  joerg #include "CGRecordLayout.h"
     19      1.1  joerg #include "CodeGenFunction.h"
     20      1.1  joerg #include "CodeGenModule.h"
     21      1.1  joerg #include "clang/AST/RecordLayout.h"
     22      1.1  joerg #include "clang/AST/StmtObjC.h"
     23      1.1  joerg #include "clang/CodeGen/CGFunctionInfo.h"
     24  1.1.1.2  joerg #include "clang/CodeGen/CodeGenABITypes.h"
     25      1.1  joerg #include "llvm/Support/SaveAndRestore.h"
     26      1.1  joerg 
     27      1.1  joerg using namespace clang;
     28      1.1  joerg using namespace CodeGen;
     29      1.1  joerg 
     30      1.1  joerg uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
     31      1.1  joerg                                               const ObjCInterfaceDecl *OID,
     32      1.1  joerg                                               const ObjCIvarDecl *Ivar) {
     33      1.1  joerg   return CGM.getContext().lookupFieldBitOffset(OID, nullptr, Ivar) /
     34      1.1  joerg          CGM.getContext().getCharWidth();
     35      1.1  joerg }
     36      1.1  joerg 
     37      1.1  joerg uint64_t CGObjCRuntime::ComputeIvarBaseOffset(CodeGen::CodeGenModule &CGM,
     38      1.1  joerg                                               const ObjCImplementationDecl *OID,
     39      1.1  joerg                                               const ObjCIvarDecl *Ivar) {
     40      1.1  joerg   return CGM.getContext().lookupFieldBitOffset(OID->getClassInterface(), OID,
     41      1.1  joerg                                                Ivar) /
     42      1.1  joerg          CGM.getContext().getCharWidth();
     43      1.1  joerg }
     44      1.1  joerg 
     45      1.1  joerg unsigned CGObjCRuntime::ComputeBitfieldBitOffset(
     46      1.1  joerg     CodeGen::CodeGenModule &CGM,
     47      1.1  joerg     const ObjCInterfaceDecl *ID,
     48      1.1  joerg     const ObjCIvarDecl *Ivar) {
     49      1.1  joerg   return CGM.getContext().lookupFieldBitOffset(ID, ID->getImplementation(),
     50      1.1  joerg                                                Ivar);
     51      1.1  joerg }
     52      1.1  joerg 
     53      1.1  joerg LValue CGObjCRuntime::EmitValueForIvarAtOffset(CodeGen::CodeGenFunction &CGF,
     54      1.1  joerg                                                const ObjCInterfaceDecl *OID,
     55      1.1  joerg                                                llvm::Value *BaseValue,
     56      1.1  joerg                                                const ObjCIvarDecl *Ivar,
     57      1.1  joerg                                                unsigned CVRQualifiers,
     58      1.1  joerg                                                llvm::Value *Offset) {
     59      1.1  joerg   // Compute (type*) ( (char *) BaseValue + Offset)
     60      1.1  joerg   QualType InterfaceTy{OID->getTypeForDecl(), 0};
     61      1.1  joerg   QualType ObjectPtrTy =
     62      1.1  joerg       CGF.CGM.getContext().getObjCObjectPointerType(InterfaceTy);
     63      1.1  joerg   QualType IvarTy =
     64      1.1  joerg       Ivar->getUsageType(ObjectPtrTy).withCVRQualifiers(CVRQualifiers);
     65      1.1  joerg   llvm::Type *LTy = CGF.CGM.getTypes().ConvertTypeForMem(IvarTy);
     66      1.1  joerg   llvm::Value *V = CGF.Builder.CreateBitCast(BaseValue, CGF.Int8PtrTy);
     67  1.1.1.2  joerg   V = CGF.Builder.CreateInBoundsGEP(CGF.Int8Ty, V, Offset, "add.ptr");
     68      1.1  joerg 
     69      1.1  joerg   if (!Ivar->isBitField()) {
     70      1.1  joerg     V = CGF.Builder.CreateBitCast(V, llvm::PointerType::getUnqual(LTy));
     71      1.1  joerg     LValue LV = CGF.MakeNaturalAlignAddrLValue(V, IvarTy);
     72      1.1  joerg     return LV;
     73      1.1  joerg   }
     74      1.1  joerg 
     75      1.1  joerg   // We need to compute an access strategy for this bit-field. We are given the
     76      1.1  joerg   // offset to the first byte in the bit-field, the sub-byte offset is taken
     77      1.1  joerg   // from the original layout. We reuse the normal bit-field access strategy by
     78      1.1  joerg   // treating this as an access to a struct where the bit-field is in byte 0,
     79      1.1  joerg   // and adjust the containing type size as appropriate.
     80      1.1  joerg   //
     81      1.1  joerg   // FIXME: Note that currently we make a very conservative estimate of the
     82      1.1  joerg   // alignment of the bit-field, because (a) it is not clear what guarantees the
     83      1.1  joerg   // runtime makes us, and (b) we don't have a way to specify that the struct is
     84      1.1  joerg   // at an alignment plus offset.
     85      1.1  joerg   //
     86      1.1  joerg   // Note, there is a subtle invariant here: we can only call this routine on
     87      1.1  joerg   // non-synthesized ivars but we may be called for synthesized ivars.  However,
     88      1.1  joerg   // a synthesized ivar can never be a bit-field, so this is safe.
     89      1.1  joerg   uint64_t FieldBitOffset =
     90      1.1  joerg       CGF.CGM.getContext().lookupFieldBitOffset(OID, nullptr, Ivar);
     91      1.1  joerg   uint64_t BitOffset = FieldBitOffset % CGF.CGM.getContext().getCharWidth();
     92      1.1  joerg   uint64_t AlignmentBits = CGF.CGM.getTarget().getCharAlign();
     93      1.1  joerg   uint64_t BitFieldSize = Ivar->getBitWidthValue(CGF.getContext());
     94      1.1  joerg   CharUnits StorageSize = CGF.CGM.getContext().toCharUnitsFromBits(
     95      1.1  joerg       llvm::alignTo(BitOffset + BitFieldSize, AlignmentBits));
     96      1.1  joerg   CharUnits Alignment = CGF.CGM.getContext().toCharUnitsFromBits(AlignmentBits);
     97      1.1  joerg 
     98      1.1  joerg   // Allocate a new CGBitFieldInfo object to describe this access.
     99      1.1  joerg   //
    100      1.1  joerg   // FIXME: This is incredibly wasteful, these should be uniqued or part of some
    101      1.1  joerg   // layout object. However, this is blocked on other cleanups to the
    102      1.1  joerg   // Objective-C code, so for now we just live with allocating a bunch of these
    103      1.1  joerg   // objects.
    104      1.1  joerg   CGBitFieldInfo *Info = new (CGF.CGM.getContext()) CGBitFieldInfo(
    105      1.1  joerg     CGBitFieldInfo::MakeInfo(CGF.CGM.getTypes(), Ivar, BitOffset, BitFieldSize,
    106      1.1  joerg                              CGF.CGM.getContext().toBits(StorageSize),
    107      1.1  joerg                              CharUnits::fromQuantity(0)));
    108      1.1  joerg 
    109      1.1  joerg   Address Addr(V, Alignment);
    110      1.1  joerg   Addr = CGF.Builder.CreateElementBitCast(Addr,
    111      1.1  joerg                                    llvm::Type::getIntNTy(CGF.getLLVMContext(),
    112      1.1  joerg                                                          Info->StorageSize));
    113      1.1  joerg   return LValue::MakeBitfield(Addr, *Info, IvarTy,
    114      1.1  joerg                               LValueBaseInfo(AlignmentSource::Decl),
    115      1.1  joerg                               TBAAAccessInfo());
    116      1.1  joerg }
    117      1.1  joerg 
    118      1.1  joerg namespace {
    119      1.1  joerg   struct CatchHandler {
    120      1.1  joerg     const VarDecl *Variable;
    121      1.1  joerg     const Stmt *Body;
    122      1.1  joerg     llvm::BasicBlock *Block;
    123      1.1  joerg     llvm::Constant *TypeInfo;
    124      1.1  joerg     /// Flags used to differentiate cleanups and catchalls in Windows SEH
    125      1.1  joerg     unsigned Flags;
    126      1.1  joerg   };
    127      1.1  joerg 
    128      1.1  joerg   struct CallObjCEndCatch final : EHScopeStack::Cleanup {
    129      1.1  joerg     CallObjCEndCatch(bool MightThrow, llvm::FunctionCallee Fn)
    130      1.1  joerg         : MightThrow(MightThrow), Fn(Fn) {}
    131      1.1  joerg     bool MightThrow;
    132      1.1  joerg     llvm::FunctionCallee Fn;
    133      1.1  joerg 
    134      1.1  joerg     void Emit(CodeGenFunction &CGF, Flags flags) override {
    135      1.1  joerg       if (MightThrow)
    136      1.1  joerg         CGF.EmitRuntimeCallOrInvoke(Fn);
    137      1.1  joerg       else
    138      1.1  joerg         CGF.EmitNounwindRuntimeCall(Fn);
    139      1.1  joerg     }
    140      1.1  joerg   };
    141      1.1  joerg }
    142      1.1  joerg 
    143      1.1  joerg void CGObjCRuntime::EmitTryCatchStmt(CodeGenFunction &CGF,
    144      1.1  joerg                                      const ObjCAtTryStmt &S,
    145      1.1  joerg                                      llvm::FunctionCallee beginCatchFn,
    146      1.1  joerg                                      llvm::FunctionCallee endCatchFn,
    147      1.1  joerg                                      llvm::FunctionCallee exceptionRethrowFn) {
    148      1.1  joerg   // Jump destination for falling out of catch bodies.
    149      1.1  joerg   CodeGenFunction::JumpDest Cont;
    150      1.1  joerg   if (S.getNumCatchStmts())
    151      1.1  joerg     Cont = CGF.getJumpDestInCurrentScope("eh.cont");
    152      1.1  joerg 
    153      1.1  joerg   bool useFunclets = EHPersonality::get(CGF).usesFuncletPads();
    154      1.1  joerg 
    155      1.1  joerg   CodeGenFunction::FinallyInfo FinallyInfo;
    156      1.1  joerg   if (!useFunclets)
    157      1.1  joerg     if (const ObjCAtFinallyStmt *Finally = S.getFinallyStmt())
    158      1.1  joerg       FinallyInfo.enter(CGF, Finally->getFinallyBody(),
    159      1.1  joerg                         beginCatchFn, endCatchFn, exceptionRethrowFn);
    160      1.1  joerg 
    161      1.1  joerg   SmallVector<CatchHandler, 8> Handlers;
    162      1.1  joerg 
    163      1.1  joerg 
    164      1.1  joerg   // Enter the catch, if there is one.
    165      1.1  joerg   if (S.getNumCatchStmts()) {
    166      1.1  joerg     for (unsigned I = 0, N = S.getNumCatchStmts(); I != N; ++I) {
    167      1.1  joerg       const ObjCAtCatchStmt *CatchStmt = S.getCatchStmt(I);
    168      1.1  joerg       const VarDecl *CatchDecl = CatchStmt->getCatchParamDecl();
    169      1.1  joerg 
    170      1.1  joerg       Handlers.push_back(CatchHandler());
    171      1.1  joerg       CatchHandler &Handler = Handlers.back();
    172      1.1  joerg       Handler.Variable = CatchDecl;
    173      1.1  joerg       Handler.Body = CatchStmt->getCatchBody();
    174      1.1  joerg       Handler.Block = CGF.createBasicBlock("catch");
    175      1.1  joerg       Handler.Flags = 0;
    176      1.1  joerg 
    177      1.1  joerg       // @catch(...) always matches.
    178      1.1  joerg       if (!CatchDecl) {
    179      1.1  joerg         auto catchAll = getCatchAllTypeInfo();
    180      1.1  joerg         Handler.TypeInfo = catchAll.RTTI;
    181      1.1  joerg         Handler.Flags = catchAll.Flags;
    182      1.1  joerg         // Don't consider any other catches.
    183      1.1  joerg         break;
    184      1.1  joerg       }
    185      1.1  joerg 
    186      1.1  joerg       Handler.TypeInfo = GetEHType(CatchDecl->getType());
    187      1.1  joerg     }
    188      1.1  joerg 
    189      1.1  joerg     EHCatchScope *Catch = CGF.EHStack.pushCatch(Handlers.size());
    190      1.1  joerg     for (unsigned I = 0, E = Handlers.size(); I != E; ++I)
    191      1.1  joerg       Catch->setHandler(I, { Handlers[I].TypeInfo, Handlers[I].Flags }, Handlers[I].Block);
    192      1.1  joerg   }
    193      1.1  joerg 
    194      1.1  joerg   if (useFunclets)
    195      1.1  joerg     if (const ObjCAtFinallyStmt *Finally = S.getFinallyStmt()) {
    196      1.1  joerg         CodeGenFunction HelperCGF(CGM, /*suppressNewContext=*/true);
    197      1.1  joerg         if (!CGF.CurSEHParent)
    198      1.1  joerg             CGF.CurSEHParent = cast<NamedDecl>(CGF.CurFuncDecl);
    199      1.1  joerg         // Outline the finally block.
    200      1.1  joerg         const Stmt *FinallyBlock = Finally->getFinallyBody();
    201      1.1  joerg         HelperCGF.startOutlinedSEHHelper(CGF, /*isFilter*/false, FinallyBlock);
    202      1.1  joerg 
    203      1.1  joerg         // Emit the original filter expression, convert to i32, and return.
    204      1.1  joerg         HelperCGF.EmitStmt(FinallyBlock);
    205      1.1  joerg 
    206      1.1  joerg         HelperCGF.FinishFunction(FinallyBlock->getEndLoc());
    207      1.1  joerg 
    208      1.1  joerg         llvm::Function *FinallyFunc = HelperCGF.CurFn;
    209      1.1  joerg 
    210      1.1  joerg 
    211      1.1  joerg         // Push a cleanup for __finally blocks.
    212      1.1  joerg         CGF.pushSEHCleanup(NormalAndEHCleanup, FinallyFunc);
    213      1.1  joerg     }
    214      1.1  joerg 
    215  1.1.1.2  joerg 
    216      1.1  joerg   // Emit the try body.
    217      1.1  joerg   CGF.EmitStmt(S.getTryBody());
    218      1.1  joerg 
    219      1.1  joerg   // Leave the try.
    220      1.1  joerg   if (S.getNumCatchStmts())
    221      1.1  joerg     CGF.popCatchScope();
    222      1.1  joerg 
    223      1.1  joerg   // Remember where we were.
    224      1.1  joerg   CGBuilderTy::InsertPoint SavedIP = CGF.Builder.saveAndClearIP();
    225      1.1  joerg 
    226      1.1  joerg   // Emit the handlers.
    227      1.1  joerg   for (unsigned I = 0, E = Handlers.size(); I != E; ++I) {
    228      1.1  joerg     CatchHandler &Handler = Handlers[I];
    229      1.1  joerg 
    230      1.1  joerg     CGF.EmitBlock(Handler.Block);
    231      1.1  joerg     llvm::CatchPadInst *CPI = nullptr;
    232      1.1  joerg     SaveAndRestore<llvm::Instruction *> RestoreCurrentFuncletPad(CGF.CurrentFuncletPad);
    233      1.1  joerg     if (useFunclets)
    234      1.1  joerg       if ((CPI = dyn_cast_or_null<llvm::CatchPadInst>(Handler.Block->getFirstNonPHI()))) {
    235      1.1  joerg         CGF.CurrentFuncletPad = CPI;
    236      1.1  joerg         CPI->setOperand(2, CGF.getExceptionSlot().getPointer());
    237      1.1  joerg       }
    238      1.1  joerg     llvm::Value *RawExn = CGF.getExceptionFromSlot();
    239      1.1  joerg 
    240      1.1  joerg     // Enter the catch.
    241      1.1  joerg     llvm::Value *Exn = RawExn;
    242      1.1  joerg     if (beginCatchFn)
    243      1.1  joerg       Exn = CGF.EmitNounwindRuntimeCall(beginCatchFn, RawExn, "exn.adjusted");
    244      1.1  joerg 
    245      1.1  joerg     CodeGenFunction::LexicalScope cleanups(CGF, Handler.Body->getSourceRange());
    246      1.1  joerg 
    247      1.1  joerg     if (endCatchFn) {
    248      1.1  joerg       // Add a cleanup to leave the catch.
    249      1.1  joerg       bool EndCatchMightThrow = (Handler.Variable == nullptr);
    250      1.1  joerg 
    251      1.1  joerg       CGF.EHStack.pushCleanup<CallObjCEndCatch>(NormalAndEHCleanup,
    252      1.1  joerg                                                 EndCatchMightThrow,
    253      1.1  joerg                                                 endCatchFn);
    254      1.1  joerg     }
    255      1.1  joerg 
    256      1.1  joerg     // Bind the catch parameter if it exists.
    257      1.1  joerg     if (const VarDecl *CatchParam = Handler.Variable) {
    258      1.1  joerg       llvm::Type *CatchType = CGF.ConvertType(CatchParam->getType());
    259      1.1  joerg       llvm::Value *CastExn = CGF.Builder.CreateBitCast(Exn, CatchType);
    260      1.1  joerg 
    261      1.1  joerg       CGF.EmitAutoVarDecl(*CatchParam);
    262      1.1  joerg       EmitInitOfCatchParam(CGF, CastExn, CatchParam);
    263      1.1  joerg     }
    264      1.1  joerg     if (CPI)
    265      1.1  joerg         CGF.EHStack.pushCleanup<CatchRetScope>(NormalCleanup, CPI);
    266      1.1  joerg 
    267      1.1  joerg     CGF.ObjCEHValueStack.push_back(Exn);
    268      1.1  joerg     CGF.EmitStmt(Handler.Body);
    269      1.1  joerg     CGF.ObjCEHValueStack.pop_back();
    270      1.1  joerg 
    271      1.1  joerg     // Leave any cleanups associated with the catch.
    272      1.1  joerg     cleanups.ForceCleanup();
    273      1.1  joerg 
    274      1.1  joerg     CGF.EmitBranchThroughCleanup(Cont);
    275  1.1.1.2  joerg   }
    276      1.1  joerg 
    277      1.1  joerg   // Go back to the try-statement fallthrough.
    278      1.1  joerg   CGF.Builder.restoreIP(SavedIP);
    279      1.1  joerg 
    280      1.1  joerg   // Pop out of the finally.
    281      1.1  joerg   if (!useFunclets && S.getFinallyStmt())
    282      1.1  joerg     FinallyInfo.exit(CGF);
    283      1.1  joerg 
    284      1.1  joerg   if (Cont.isValid())
    285      1.1  joerg     CGF.EmitBlock(Cont.getBlock());
    286      1.1  joerg }
    287      1.1  joerg 
    288      1.1  joerg void CGObjCRuntime::EmitInitOfCatchParam(CodeGenFunction &CGF,
    289      1.1  joerg                                          llvm::Value *exn,
    290      1.1  joerg                                          const VarDecl *paramDecl) {
    291      1.1  joerg 
    292      1.1  joerg   Address paramAddr = CGF.GetAddrOfLocalVar(paramDecl);
    293      1.1  joerg 
    294      1.1  joerg   switch (paramDecl->getType().getQualifiers().getObjCLifetime()) {
    295      1.1  joerg   case Qualifiers::OCL_Strong:
    296      1.1  joerg     exn = CGF.EmitARCRetainNonBlock(exn);
    297      1.1  joerg     LLVM_FALLTHROUGH;
    298      1.1  joerg 
    299      1.1  joerg   case Qualifiers::OCL_None:
    300      1.1  joerg   case Qualifiers::OCL_ExplicitNone:
    301      1.1  joerg   case Qualifiers::OCL_Autoreleasing:
    302      1.1  joerg     CGF.Builder.CreateStore(exn, paramAddr);
    303      1.1  joerg     return;
    304      1.1  joerg 
    305      1.1  joerg   case Qualifiers::OCL_Weak:
    306      1.1  joerg     CGF.EmitARCInitWeak(paramAddr, exn);
    307      1.1  joerg     return;
    308      1.1  joerg   }
    309      1.1  joerg   llvm_unreachable("invalid ownership qualifier");
    310      1.1  joerg }
    311      1.1  joerg 
    312      1.1  joerg namespace {
    313      1.1  joerg   struct CallSyncExit final : EHScopeStack::Cleanup {
    314      1.1  joerg     llvm::FunctionCallee SyncExitFn;
    315      1.1  joerg     llvm::Value *SyncArg;
    316      1.1  joerg     CallSyncExit(llvm::FunctionCallee SyncExitFn, llvm::Value *SyncArg)
    317      1.1  joerg         : SyncExitFn(SyncExitFn), SyncArg(SyncArg) {}
    318      1.1  joerg 
    319      1.1  joerg     void Emit(CodeGenFunction &CGF, Flags flags) override {
    320      1.1  joerg       CGF.EmitNounwindRuntimeCall(SyncExitFn, SyncArg);
    321      1.1  joerg     }
    322      1.1  joerg   };
    323      1.1  joerg }
    324      1.1  joerg 
    325      1.1  joerg void CGObjCRuntime::EmitAtSynchronizedStmt(CodeGenFunction &CGF,
    326      1.1  joerg                                            const ObjCAtSynchronizedStmt &S,
    327      1.1  joerg                                            llvm::FunctionCallee syncEnterFn,
    328      1.1  joerg                                            llvm::FunctionCallee syncExitFn) {
    329      1.1  joerg   CodeGenFunction::RunCleanupsScope cleanups(CGF);
    330      1.1  joerg 
    331      1.1  joerg   // Evaluate the lock operand.  This is guaranteed to dominate the
    332      1.1  joerg   // ARC release and lock-release cleanups.
    333      1.1  joerg   const Expr *lockExpr = S.getSynchExpr();
    334      1.1  joerg   llvm::Value *lock;
    335      1.1  joerg   if (CGF.getLangOpts().ObjCAutoRefCount) {
    336      1.1  joerg     lock = CGF.EmitARCRetainScalarExpr(lockExpr);
    337      1.1  joerg     lock = CGF.EmitObjCConsumeObject(lockExpr->getType(), lock);
    338      1.1  joerg   } else {
    339      1.1  joerg     lock = CGF.EmitScalarExpr(lockExpr);
    340      1.1  joerg   }
    341      1.1  joerg   lock = CGF.Builder.CreateBitCast(lock, CGF.VoidPtrTy);
    342      1.1  joerg 
    343      1.1  joerg   // Acquire the lock.
    344      1.1  joerg   CGF.Builder.CreateCall(syncEnterFn, lock)->setDoesNotThrow();
    345      1.1  joerg 
    346      1.1  joerg   // Register an all-paths cleanup to release the lock.
    347      1.1  joerg   CGF.EHStack.pushCleanup<CallSyncExit>(NormalAndEHCleanup, syncExitFn, lock);
    348      1.1  joerg 
    349      1.1  joerg   // Emit the body of the statement.
    350      1.1  joerg   CGF.EmitStmt(S.getSynchBody());
    351      1.1  joerg }
    352      1.1  joerg 
    353      1.1  joerg /// Compute the pointer-to-function type to which a message send
    354      1.1  joerg /// should be casted in order to correctly call the given method
    355      1.1  joerg /// with the given arguments.
    356      1.1  joerg ///
    357      1.1  joerg /// \param method - may be null
    358      1.1  joerg /// \param resultType - the result type to use if there's no method
    359      1.1  joerg /// \param callArgs - the actual arguments, including implicit ones
    360      1.1  joerg CGObjCRuntime::MessageSendInfo
    361      1.1  joerg CGObjCRuntime::getMessageSendInfo(const ObjCMethodDecl *method,
    362      1.1  joerg                                   QualType resultType,
    363      1.1  joerg                                   CallArgList &callArgs) {
    364      1.1  joerg   // If there's a method, use information from that.
    365      1.1  joerg   if (method) {
    366      1.1  joerg     const CGFunctionInfo &signature =
    367      1.1  joerg       CGM.getTypes().arrangeObjCMessageSendSignature(method, callArgs[0].Ty);
    368      1.1  joerg 
    369      1.1  joerg     llvm::PointerType *signatureType =
    370      1.1  joerg       CGM.getTypes().GetFunctionType(signature)->getPointerTo();
    371      1.1  joerg 
    372      1.1  joerg     const CGFunctionInfo &signatureForCall =
    373      1.1  joerg       CGM.getTypes().arrangeCall(signature, callArgs);
    374      1.1  joerg 
    375      1.1  joerg     return MessageSendInfo(signatureForCall, signatureType);
    376      1.1  joerg   }
    377      1.1  joerg 
    378      1.1  joerg   // There's no method;  just use a default CC.
    379      1.1  joerg   const CGFunctionInfo &argsInfo =
    380      1.1  joerg     CGM.getTypes().arrangeUnprototypedObjCMessageSend(resultType, callArgs);
    381      1.1  joerg 
    382      1.1  joerg   // Derive the signature to call from that.
    383      1.1  joerg   llvm::PointerType *signatureType =
    384      1.1  joerg     CGM.getTypes().GetFunctionType(argsInfo)->getPointerTo();
    385      1.1  joerg   return MessageSendInfo(argsInfo, signatureType);
    386      1.1  joerg }
    387  1.1.1.2  joerg 
    388  1.1.1.2  joerg llvm::Constant *
    389  1.1.1.2  joerg clang::CodeGen::emitObjCProtocolObject(CodeGenModule &CGM,
    390  1.1.1.2  joerg                                        const ObjCProtocolDecl *protocol) {
    391  1.1.1.2  joerg   return CGM.getObjCRuntime().GetOrEmitProtocol(protocol);
    392  1.1.1.2  joerg }
    393  1.1.1.2  joerg 
    394  1.1.1.2  joerg std::string CGObjCRuntime::getSymbolNameForMethod(const ObjCMethodDecl *OMD,
    395  1.1.1.2  joerg                                                   bool includeCategoryName) {
    396  1.1.1.2  joerg   std::string buffer;
    397  1.1.1.2  joerg   llvm::raw_string_ostream out(buffer);
    398  1.1.1.2  joerg   CGM.getCXXABI().getMangleContext().mangleObjCMethodName(OMD, out,
    399  1.1.1.2  joerg                                        /*includePrefixByte=*/true,
    400  1.1.1.2  joerg                                        includeCategoryName);
    401  1.1.1.2  joerg   return buffer;
    402  1.1.1.2  joerg }
    403