summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorLorenzo Martignoni <martignlo@google.com>2014-09-30 12:33:16 +0000
committerLorenzo Martignoni <martignlo@google.com>2014-09-30 12:33:16 +0000
commit40d3deeb7da108f16dbdcb5f83e718607c07f5f8 (patch)
tree4558bc855f3a9e1668dbf3c21724f4b69a0473c9 /llvm/lib
parent28a7df0b5f871c5019f0da6c3c11824c33fe9e6c (diff)
downloadbcm5719-llvm-40d3deeb7da108f16dbdcb5f83e718607c07f5f8.tar.gz
bcm5719-llvm-40d3deeb7da108f16dbdcb5f83e718607c07f5f8.zip
Introduce support for custom wrappers for vararg functions.
Differential Revision: http://reviews.llvm.org/D5412 llvm-svn: 218671
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
index 771dcd7d9fe..446bcf79b55 100644
--- a/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DataFlowSanitizer.cpp
@@ -387,7 +387,12 @@ FunctionType *DataFlowSanitizer::getTrampolineFunctionType(FunctionType *T) {
}
FunctionType *DataFlowSanitizer::getCustomFunctionType(FunctionType *T) {
- assert(!T->isVarArg());
+ if (T->isVarArg()) {
+ // The labels are passed after all the arguments so there is no need to
+ // adjust the function type.
+ return T;
+ }
+
llvm::SmallVector<Type *, 4> ArgTypes;
for (FunctionType::param_iterator i = T->param_begin(), e = T->param_end();
i != e; ++i) {
@@ -476,7 +481,7 @@ DataFlowSanitizer::WrapperKind DataFlowSanitizer::getWrapperKind(Function *F) {
return WK_Functional;
if (ABIList.isIn(*F, "discard"))
return WK_Discard;
- if (ABIList.isIn(*F, "custom") && !F->isVarArg())
+ if (ABIList.isIn(*F, "custom"))
return WK_Custom;
return WK_Warning;
@@ -704,11 +709,6 @@ bool DataFlowSanitizer::runOnModule(Module &M) {
} else {
addGlobalNamePrefix(&F);
}
- // Hopefully, nobody will try to indirectly call a vararg
- // function... yet.
- } else if (FT->isVarArg()) {
- UnwrappedFnMap[&F] = &F;
- *i = nullptr;
} else if (!IsZeroArgsVoidRet || getWrapperKind(&F) == WK_Custom) {
// Build a wrapper function for F. The wrapper simply calls F, and is
// added to FnsToInstrument so that any instrumentation according to its
@@ -744,6 +744,11 @@ bool DataFlowSanitizer::runOnModule(Module &M) {
i = FnsToInstrument.begin() + N;
e = FnsToInstrument.begin() + Count;
}
+ // Hopefully, nobody will try to indirectly call a vararg
+ // function... yet.
+ } else if (FT->isVarArg()) {
+ UnwrappedFnMap[&F] = &F;
+ *i = nullptr;
}
}
@@ -1352,6 +1357,10 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
return;
}
+ assert(!(cast<FunctionType>(
+ CS.getCalledValue()->getType()->getPointerElementType())->isVarArg() &&
+ dyn_cast<InvokeInst>(CS.getInstruction())));
+
IRBuilder<> IRB(CS.getInstruction());
DenseMap<Value *, Function *>::iterator i =
@@ -1400,7 +1409,7 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
std::vector<Value *> Args;
CallSite::arg_iterator i = CS.arg_begin();
- for (unsigned n = FT->getNumParams(); n != 0; ++i, --n) {
+ for (unsigned n = CS.arg_size(); n != 0; ++i, --n) {
Type *T = (*i)->getType();
FunctionType *ParamFT;
if (isa<PointerType>(T) &&
@@ -1420,7 +1429,7 @@ void DFSanVisitor::visitCallSite(CallSite CS) {
}
i = CS.arg_begin();
- for (unsigned n = FT->getNumParams(); n != 0; ++i, --n)
+ for (unsigned n = CS.arg_size(); n != 0; ++i, --n)
Args.push_back(DFSF.getShadow(*i));
if (!FT->getReturnType()->isVoidTy()) {
OpenPOWER on IntegriCloud