Index: include/llvm/IR/CallSite.h =================================================================== --- include/llvm/IR/CallSite.h +++ include/llvm/IR/CallSite.h @@ -96,7 +96,7 @@ /// Get the basic block containing the call site. BBTy* getParent() const { return getInstruction()->getParent(); } - /// Return the pointer to function that is being called. + /// Return the pointer to the function that is being called. ValTy *getCalledValue() const { assert(getInstruction() && "Not a call or invoke instruction!"); return *getCallee(); @@ -104,11 +104,26 @@ /// Return the function being called if this is a direct call, otherwise /// return null (if it's an indirect call). + /// + /// See isIndirectCall() for the definition of an indirect call. FunTy *getCalledFunction() const { return dyn_cast(getCalledValue()); } + /// Return the function being called if this is either a direct call or an + /// indirect call to a cast of a function, otherwise return null. + /// + /// See isIndirectCall() for the definition of an indirect call. + FunTy *getCalledFunctionStripCasts() const { + return dyn_cast(getCalledValue()->stripPointerCasts()); + } + /// Return true if the callsite is an indirect call. + /// + /// An indirect call is any call to a Value that is not a Function or + /// Constant, even those which are trivially, statically known to call the + /// same function. For example, a call to a bitcast of a function is + /// considered indirect. bool isIndirectCall() const { const Value *V = getCalledValue(); if (!V) Index: lib/CodeGen/WinEHPrepare.cpp =================================================================== --- lib/CodeGen/WinEHPrepare.cpp +++ lib/CodeGen/WinEHPrepare.cpp @@ -953,8 +953,7 @@ continue; // Skip call sites which are nounwind intrinsics or inline asm. - auto *CalledFn = - dyn_cast(CS.getCalledValue()->stripPointerCasts()); + Function *CalledFn = CS.getCalledFunctionStripCasts(); if (CalledFn && ((CalledFn->isIntrinsic() && CS.doesNotThrow()) || CS.isInlineAsm())) continue; Index: lib/IR/Verifier.cpp =================================================================== --- lib/IR/Verifier.cpp +++ lib/IR/Verifier.cpp @@ -2743,8 +2743,7 @@ if (Attrs.hasAttribute(AttributeList::FunctionIndex, Attribute::Speculatable)) { // Don't allow speculatable on call sites, unless the underlying function // declaration is also speculatable. - Function *Callee - = dyn_cast(CS.getCalledValue()->stripPointerCasts()); + Function *Callee = CS.getCalledFunctionStripCasts(); Assert(Callee && Callee->isSpeculatable(), "speculatable attribute may not apply to call sites", I); } Index: lib/Transforms/InstCombine/InstCombineCalls.cpp =================================================================== --- lib/Transforms/InstCombine/InstCombineCalls.cpp +++ lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -4184,7 +4184,7 @@ /// If the callee is a constexpr cast of a function, attempt to move the cast to /// the arguments of the call/invoke. bool InstCombiner::transformConstExprCastCall(CallSite CS) { - auto *Callee = dyn_cast(CS.getCalledValue()->stripPointerCasts()); + Function *Callee = CS.getCalledFunctionStripCasts(); if (!Callee) return false; Index: lib/Transforms/Utils/InlineFunction.cpp =================================================================== --- lib/Transforms/Utils/InlineFunction.cpp +++ lib/Transforms/Utils/InlineFunction.cpp @@ -2017,8 +2017,7 @@ continue; // Skip call sites which are nounwind intrinsics. - auto *CalledFn = - dyn_cast(CS.getCalledValue()->stripPointerCasts()); + Function *CalledFn = CS.getCalledFunctionStripCasts(); if (CalledFn && CalledFn->isIntrinsic() && CS.doesNotThrow()) continue;