Definitions of static functions must be visible across Transactions.

Otherwise, subsequent calls cannot use them: they cannot resolve the symbol.
This is a side-effect of our never-ending translation unit versus intermediary
end-of-translation unit actions.
This commit is contained in:
Axel Naumann 2017-03-29 17:51:12 +02:00 committed by sftnight
parent 728c296cb0
commit 7dc6a1be42

View File

@ -30,6 +30,34 @@ using namespace clang;
using namespace llvm;
using namespace llvm::legacy;
namespace {
class KeepLocalFuncPass: public FunctionPass {
static char ID;
public:
KeepLocalFuncPass() : FunctionPass(ID) {}
bool runOnFunction(Function &F) override {
if (F.isDeclaration())
return false; // no change.
// F is a definition.
if (!F.isDiscardableIfUnused())
return false;
llvm::GlobalValue::LinkageTypes LT = F.getLinkage();
if (LT == llvm::GlobalValue::InternalLinkage
|| LT == llvm::GlobalValue::PrivateLinkage) {
F.setLinkage(llvm::GlobalValue::ExternalLinkage);
return true; // a change!
}
return false;
}
};
}
char KeepLocalFuncPass::ID = 0;
BackendPasses::~BackendPasses() {
//delete m_PMBuilder->Inliner;
}
@ -134,6 +162,7 @@ void BackendPasses::CreatePasses(llvm::Module& M)
PMBuilder.populateModulePassManager(*m_MPM);
m_FPM.reset(new legacy::FunctionPassManager(&M));
m_FPM->add(new KeepLocalFuncPass());
m_FPM->add(createTargetTransformInfoWrapperPass(m_TM.getTargetIRAnalysis()));
if (m_CGOpts.VerifyModule)
m_FPM->add(createVerifierPass());