summaryrefslogtreecommitdiff
path: root/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2013-08-22 20:08:11 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2013-08-22 20:08:11 +0000
commit4f68e9ea8e6a9d98b60bbdde719dcb9d68991980 (patch)
tree493381e3fb074837cb30447eb6667f8652632465 /lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
parentf1366c552480f7c6b2b46b03e19bb798b3a47c66 (diff)
downloadllvm-4f68e9ea8e6a9d98b60bbdde719dcb9d68991980.tar.gz
llvm-4f68e9ea8e6a9d98b60bbdde719dcb9d68991980.tar.bz2
llvm-4f68e9ea8e6a9d98b60bbdde719dcb9d68991980.tar.xz
DataFlowSanitizer: Factor the wrapper builder out to buildWrapperFunction.
Differential Revision: http://llvm-reviews.chandlerc.com/D1441 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189053 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/Instrumentation/DataFlowSanitizer.cpp')
-rw-r--r--lib/Transforms/Instrumentation/DataFlowSanitizer.cpp53
1 files changed, 33 insertions, 20 deletions
diff --git a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index 9a46911751..e92d88de1d 100644
--- a/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -186,6 +186,9 @@ class DataFlowSanitizer : public ModulePass {
InstrumentedABI getInstrumentedABI();
WrapperKind getWrapperKind(Function *F);
void addGlobalNamePrefix(GlobalValue *GV);
+ Function *buildWrapperFunction(Function *F, StringRef NewFName,
+ GlobalValue::LinkageTypes NewFLink,
+ FunctionType *NewFT);
public:
DataFlowSanitizer(StringRef ABIListFile = StringRef(),
@@ -387,6 +390,33 @@ void DataFlowSanitizer::addGlobalNamePrefix(GlobalValue *GV) {
}
}
+Function *
+DataFlowSanitizer::buildWrapperFunction(Function *F, StringRef NewFName,
+ GlobalValue::LinkageTypes NewFLink,
+ FunctionType *NewFT) {
+ FunctionType *FT = F->getFunctionType();
+ Function *NewF = Function::Create(NewFT, NewFLink, NewFName,
+ F->getParent());
+ NewF->copyAttributesFrom(F);
+ NewF->removeAttributes(
+ AttributeSet::ReturnIndex,
+ AttributeFuncs::typeIncompatible(NewFT->getReturnType(),
+ AttributeSet::ReturnIndex));
+
+ BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", NewF);
+ std::vector<Value *> Args;
+ unsigned n = FT->getNumParams();
+ for (Function::arg_iterator ai = NewF->arg_begin(); n != 0; ++ai, --n)
+ Args.push_back(&*ai);
+ CallInst *CI = CallInst::Create(F, Args, "", BB);
+ if (FT->getReturnType()->isVoidTy())
+ ReturnInst::Create(*Ctx, BB);
+ else
+ ReturnInst::Create(*Ctx, CI, BB);
+
+ return NewF;
+}
+
bool DataFlowSanitizer::runOnModule(Module &M) {
if (!DL)
return false;
@@ -521,27 +551,10 @@ bool DataFlowSanitizer::runOnModule(Module &M) {
? getArgsFunctionType(FT)
: FT;
Function *NewF =
- Function::Create(NewFT, GlobalValue::LinkOnceODRLinkage,
- std::string("dfsw$") + F.getName(), &M);
- NewF->copyAttributesFrom(&F);
- NewF->removeAttributes(
- AttributeSet::ReturnIndex,
- AttributeFuncs::typeIncompatible(NewFT->getReturnType(),
- AttributeSet::ReturnIndex));
+ buildWrapperFunction(&F, std::string("dfsw$") + std::string(F.getName()),
+ GlobalValue::LinkOnceODRLinkage, NewFT);
if (getInstrumentedABI() == IA_TLS)
- NewF->removeAttributes(AttributeSet::FunctionIndex,
- ReadOnlyNoneAttrs);
-
- BasicBlock *BB = BasicBlock::Create(*Ctx, "entry", NewF);
- std::vector<Value *> Args;
- unsigned n = FT->getNumParams();
- for (Function::arg_iterator ai = NewF->arg_begin(); n != 0; ++ai, --n)
- Args.push_back(&*ai);
- CallInst *CI = CallInst::Create(&F, Args, "", BB);
- if (FT->getReturnType()->isVoidTy())
- ReturnInst::Create(*Ctx, BB);
- else
- ReturnInst::Create(*Ctx, CI, BB);
+ NewF->removeAttributes(AttributeSet::FunctionIndex, ReadOnlyNoneAttrs);
Value *WrappedFnCst =
ConstantExpr::getBitCast(NewF, PointerType::getUnqual(FT));