From d14151d5f52fa9048d41d7539299243e05755ec4 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 2 Mar 2009 04:32:35 +0000 Subject: [PATCH] Cleanup handling of function attributes in calls. - No intended functionality change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65805 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGCall.cpp | 62 ++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 38f6e96c14..28152f2de1 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -22,6 +22,7 @@ #include "clang/AST/RecordLayout.h" #include "llvm/ADT/StringExtras.h" #include "llvm/Attributes.h" +#include "llvm/Support/CallSite.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" @@ -1771,46 +1772,37 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, llvm::AttrListPtr Attrs = llvm::AttrListPtr::get(AttributeList.begin(), AttributeList.end()); - llvm::Instruction *CI; - if (!InvokeDest || Attrs.getFnAttributes() & (llvm::Attribute::NoUnwind || - llvm::Attribute::NoReturn)) { - llvm::CallInst *CallInstr = - Builder.CreateCall(Callee, &Args[0], &Args[0]+Args.size()); - CI = CallInstr; - - CallInstr->setAttributes(Attrs); - if (const llvm::Function *F = dyn_cast(Callee)) - CallInstr->setCallingConv(F->getCallingConv()); - - // If the call doesn't return, finish the basic block and clear the - // insertion point; this allows the rest of IRgen to discard - // unreachable code. - if (CallInstr->doesNotReturn()) { - Builder.CreateUnreachable(); - Builder.ClearInsertionPoint(); - - // FIXME: For now, emit a dummy basic block because expr - // emitters in generally are not ready to handle emitting - // expressions at unreachable points. - EnsureInsertPoint(); - - // Return a reasonable RValue. - return GetUndefRValue(RetTy); - } + llvm::CallSite CS; + if (!InvokeDest || (Attrs.getFnAttributes() & llvm::Attribute::NoUnwind)) { + CS = Builder.CreateCall(Callee, &Args[0], &Args[0]+Args.size()); } else { llvm::BasicBlock *Cont = createBasicBlock("invoke.cont"); - llvm::InvokeInst *InvokeInstr = - Builder.CreateInvoke(Callee, Cont, InvokeDest, - &Args[0], &Args[0]+Args.size()); - CI = InvokeInstr; - - InvokeInstr->setAttributes(Attrs); - if (const llvm::Function *F = dyn_cast(Callee)) - InvokeInstr->setCallingConv(F->getCallingConv()); - + CS = Builder.CreateInvoke(Callee, Cont, InvokeDest, + &Args[0], &Args[0]+Args.size()); EmitBlock(Cont); } + CS.setAttributes(Attrs); + if (const llvm::Function *F = dyn_cast(Callee)) + CS.setCallingConv(F->getCallingConv()); + + // If the call doesn't return, finish the basic block and clear the + // insertion point; this allows the rest of IRgen to discard + // unreachable code. + if (CS.doesNotReturn()) { + Builder.CreateUnreachable(); + Builder.ClearInsertionPoint(); + + // FIXME: For now, emit a dummy basic block because expr + // emitters in generally are not ready to handle emitting + // expressions at unreachable points. + EnsureInsertPoint(); + + // Return a reasonable RValue. + return GetUndefRValue(RetTy); + } + + llvm::Instruction *CI = CS.getInstruction(); if (CI->getType() != llvm::Type::VoidTy) CI->setName("call"); -- 2.40.0