Index: llvm/include/llvm/IR/Value.h =================================================================== --- llvm/include/llvm/IR/Value.h +++ llvm/include/llvm/IR/Value.h @@ -305,6 +305,10 @@ /// Unlike replaceAllUsesWith this function skips blockaddr uses. void replaceUsesExceptBlockAddr(Value *New); + /// replaceDirectCalls - Go through the uses list for this definition and + /// make each use, which is a direct function call. + void replaceDirectCalls(Value *New); + //---------------------------------------------------------------------- // Methods for handling the chain of uses of this Value. // Index: llvm/lib/IR/Value.cpp =================================================================== --- llvm/lib/IR/Value.cpp +++ llvm/lib/IR/Value.cpp @@ -494,6 +494,19 @@ C->handleOperandChange(this, New); } +void Value::replaceDirectCalls(Value *New) { + use_iterator UI = use_begin(), E = use_end(); + for (; UI != E;) { + Use &U = *UI; + ++UI; + + auto *Usr = dyn_cast(U.getUser()); + if (!Usr || !Usr->getCalledFunction()) + continue; + U.set(New); + } +} + namespace { // Various metrics for how much to strip off of pointers. enum PointerStripKind { Index: llvm/lib/Transforms/IPO/LowerTypeTests.cpp =================================================================== --- llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -963,15 +963,18 @@ void LowerTypeTestsModule::importFunction(Function *F, bool isDefinition) { assert(F->getType()->getAddressSpace() == 0); - // Declaration of a local function - nothing to do. - if (F->isDeclarationForLinker() && isDefinition) - return; - GlobalValue::VisibilityTypes Visibility = F->getVisibility(); std::string Name = F->getName(); Function *FDecl; - if (F->isDeclarationForLinker() && !isDefinition) { + if (F->isDeclarationForLinker() && isDefinition) { + FDecl = Function::Create(F->getFunctionType(), GlobalValue::ExternalLinkage, + Name + ".cfi", &M); + FDecl->setVisibility(Visibility); + F->replaceDirectCalls(FDecl); + return; + } + else if (F->isDeclarationForLinker() && !isDefinition) { // Declaration of an external function. FDecl = Function::Create(F->getFunctionType(), GlobalValue::ExternalLinkage, Name + ".cfi_jt", &M);