diff options
Diffstat (limited to 'llvm/lib/Transforms/Utils/ModuleUtils.cpp')
-rw-r--r-- | llvm/lib/Transforms/Utils/ModuleUtils.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index ba4b7f3cc26..8040cc7d09c 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -174,6 +174,27 @@ std::pair<Function *, Function *> llvm::createSanitizerCtorAndInitFunctions( return std::make_pair(Ctor, InitFunction); } +Function *llvm::getOrCreateInitFunction(Module &M, StringRef Name) { + assert(!Name.empty() && "Expected init function name"); + if (Function *F = M.getFunction(Name)) { + if (F->arg_size() != 0 || + F->getReturnType() != Type::getVoidTy(M.getContext())) { + std::string Err; + raw_string_ostream Stream(Err); + Stream << "Sanitizer interface function defined with wrong type: " << *F; + report_fatal_error(Err); + } + return F; + } + Function *F = checkSanitizerInterfaceFunction(M.getOrInsertFunction( + Name, AttributeList(), Type::getVoidTy(M.getContext()))); + F->setLinkage(Function::ExternalLinkage); + + appendToGlobalCtors(M, F, 0); + + return F; +} + void llvm::filterDeadComdatFunctions( Module &M, SmallVectorImpl<Function *> &DeadComdatFunctions) { // Build a map from the comdat to the number of entries in that comdat we |