[llvm-commits] [poolalloc] r132032 - /poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
Arushi Aggarwal
aggarwa4 at illinois.edu
Tue May 24 20:30:43 PDT 2011
Author: aggarwa4
Date: Tue May 24 22:30:43 2011
New Revision: 132032
URL: http://llvm.org/viewvc/llvm-project?rev=132032&view=rev
Log:
Instrument all uses of va_start in a function.
Store the count/metadata in localvariables.
Initialize the count of arguments used to zero
on every va_start call.
This is to allow for possibly multiple va_start
calls in a given function
Modified:
poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=132032&r1=132031&r2=132032&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Tue May 24 22:30:43 2011
@@ -164,41 +164,21 @@
bool
TypeChecks::visitInternalVarArgFunction(Module &M, Function &F) {
+
+ inst_iterator InsPt = inst_begin(F);
- VAArgInst *VASize = NULL;
- VAArgInst *VAMetaData = NULL;
- CallInst *VAStart = NULL;
- for (Function::iterator B = F.begin(), FE = F.end(); B != FE; ++B) {
- for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE;) {
- CallInst *CI = dyn_cast<CallInst>(I++);
- if(!CI)
- continue;
- Function *CalledF = dyn_cast<Function>(CI->getCalledFunction());
- if(!CalledF)
- continue;
- if(!CalledF->isIntrinsic())
- continue;
- if(CalledF->getIntrinsicID() != Intrinsic::vastart)
- continue;
- VAStart = CI;
- // Modify the function to add a call to get the num of arguments
- VASize = new VAArgInst(CI->getOperand(1), Int64Ty, "NumArgs");
- // Modify the function to add a call to get the metadata array
- VAMetaData = new VAArgInst(CI->getOperand(1), VoidPtrTy, "MD");
- VASize->insertAfter(CI);
- VAMetaData->insertAfter(VASize);
- break;
- }
- }
- assert(VASize && "Varargs function without a call to VAStart???");
+ AllocaInst *VASizeLoc = new AllocaInst(Int64Ty, "", &*InsPt);
+ AllocaInst *VAMDLoc = new AllocaInst(VoidPtrTy, "", &*InsPt);
+ VASizeLoc->dump();
+ VAMDLoc->dump();
// Modify function to add checks on every var_arg call to ensure that we
// are not accessing more arguments than we passed in.
- // Add a counter variable
- AllocaInst *Counter = new AllocaInst(Int64Ty, "", VASize);
- new StoreInst(ConstantInt::get(Int64Ty, 0), Counter, VASize);
+ // Add a counter variable to the function entry
+ AllocaInst *Counter = new AllocaInst(Int64Ty, "",&*InsPt);
+ new StoreInst(ConstantInt::get(Int64Ty, 0), Counter, &*InsPt);
// Increment the counter
for (Function::iterator B = F.begin(), FE = F.end(); B != FE; ++B) {
@@ -206,10 +186,6 @@
VAArgInst *VI = dyn_cast<VAArgInst>(I++);
if(!VI)
continue;
- if(VI == VASize)
- continue;
- if(VI == VAMetaData)
- continue;
Constant *One = ConstantInt::get(Int64Ty, 1);
LoadInst *OldValue = new LoadInst(Counter, "count", VI);
Instruction *NewValue = BinaryOperator::Create(BinaryOperator::Add,
@@ -219,6 +195,8 @@
VI);
new StoreInst(NewValue, Counter, VI);
std::vector<Value *> Args;
+ Instruction *VASize = new LoadInst(VASizeLoc, "", VI);
+ Instruction *VAMetaData = new LoadInst(VAMDLoc, "", VI);
Args.push_back(VASize);
Args.push_back(OldValue);
Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[VI->getType()]));
@@ -228,6 +206,40 @@
CallInst::Create(Func, Args.begin(), Args.end(), "", VI);
}
}
+
+ CallInst *VAStart = NULL;
+ for (Function::iterator B = F.begin(), FE = F.end(); B != FE; ++B) {
+ for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE;) {
+ CallInst *CI = dyn_cast<CallInst>(I++);
+ if(!CI)
+ continue;
+ Function *CalledF = dyn_cast<Function>(CI->getCalledFunction());
+ if(!CalledF)
+ continue;
+ if(!CalledF->isIntrinsic())
+ continue;
+ if(CalledF->getIntrinsicID() != Intrinsic::vastart)
+ continue;
+ VAStart = CI;
+ // Modify the function to add a call to get the num of arguments
+ VAArgInst *VASize = new VAArgInst(CI->getOperand(1), Int64Ty, "NumArgs");
+ // Modify the function to add a call to get the metadata array
+ VAArgInst *VAMetaData = new VAArgInst(CI->getOperand(1), VoidPtrTy, "MD");
+ VASize->insertAfter(CI);
+ VAMetaData->insertAfter(VASize);
+
+ // Store the metadata
+ StoreInst *SI1 = new StoreInst(VASize, VASizeLoc);
+ SI1->insertAfter(VAMetaData);
+ StoreInst *SI2 = new StoreInst(VAMetaData, VAMDLoc);
+ SI2->insertAfter(SI1);
+
+ // Reinitialize the counter
+ StoreInst *SI3 = new StoreInst(ConstantInt::get(Int64Ty, 0), Counter);
+ SI3->insertAfter(SI2);
+ }
+ }
+ assert(VAStart && "Varargs function without a call to VAStart???");
// Find all uses of the function
for(Value::use_iterator ui = F.use_begin(), ue = F.use_end();
More information about the llvm-commits
mailing list