[llvm-commits] [poolalloc] r131678 - in /poolalloc/trunk: lib/AssistDS/TypeChecks.cpp runtime/DynamicTypeChecks/TypeRuntime.c
Arushi Aggarwal
aggarwa4 at illinois.edu
Thu May 19 14:21:29 PDT 2011
Author: aggarwa4
Date: Thu May 19 16:21:29 2011
New Revision: 131678
URL: http://llvm.org/viewvc/llvm-project?rev=131678&view=rev
Log:
Add the number of variable arguments as first vararg.
Add a runtime function to check that we access no more
elements than passed.
Modified:
poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=131678&r1=131677&r2=131678&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Thu May 19 16:21:29 2011
@@ -205,6 +205,10 @@
std::vector<Value *> Args;
unsigned int i = F.arg_size() + 1;
for(i = 1 ;i < CI->getNumOperands(); i++) {
+ // As the first vararg argument pass the number of var_arg arguments
+ if(i == F.arg_size() + 1) {
+ Args.push_back(ConstantInt::get(Int64Ty, 2*(CI->getNumOperands()-1 - F.arg_size())));
+ }
if(i > F.arg_size()) {
// For each vararg argument, also add its type information before it
Args.push_back(ConstantInt::get(Int8Ty, UsedTypes[CI->getOperand(i)->getType()]));
@@ -219,6 +223,63 @@
CI->replaceAllUsesWith(CI_New);
CI->eraseFromParent();
}
+
+ // Modify the function to add a call to get the num of arguments
+ VAArgInst *VASize = 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;
+ VASize = new VAArgInst(CI->getOperand(1), Int64Ty, "NumArgs");
+ VASize->insertAfter(CI);
+ break;
+ }
+ }
+ assert(VASize && "Varargs function without a call to VAStart???");
+
+ // 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);
+
+ // Increment the counter
+
+ for (Function::iterator B = F.begin(), FE = F.end(); B != FE; ++B) {
+ for (BasicBlock::iterator I = B->begin(), BE = B->end(); I != BE;) {
+ VAArgInst *VI = dyn_cast<VAArgInst>(I++);
+ if(!VI)
+ continue;
+ if(VI == VASize)
+ continue;
+ Constant *One = ConstantInt::get(Int64Ty, 1);
+ LoadInst *OldValue = new LoadInst(Counter, "count", VI);
+ Instruction *NewValue = BinaryOperator::Create(BinaryOperator::Add,
+ OldValue,
+ One,
+ "count",
+ VI);
+ new StoreInst(NewValue, Counter, VI);
+
+
+ std::vector<Value *> Args;
+ Args.push_back(VASize);
+ Args.push_back(NewValue);
+ Args.push_back(ConstantInt::get(Int32Ty, tagCounter++));
+ Constant *Func = M.getOrInsertFunction("compareNumber", VoidTy, Int64Ty, Int64Ty,Int32Ty, NULL);
+ CallInst::Create(Func, Args.begin(), Args.end(), "", VI);
+
+ }
+ }
return true;
}
Modified: poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c?rev=131678&r1=131677&r2=131678&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c Thu May 19 16:21:29 2011
@@ -100,11 +100,19 @@
*/
void compareTypes(uint8_t typeNumberSrc, uint8_t typeNumberDest, uint32_t tag) {
if(typeNumberSrc != typeNumberDest) {
- printf("Type mismatch: detecting %u, expecting %u! %u \n", typeNumberDest, typeNumberSrc, tag);
+ printf("Type mismatch: detecting %u, expecting %u! %u \n", typeNumberDest, typeNumberSrc, tag);
}
}
/**
+ * Check that number of VAArg accessed is not greater than those passed
+ */
+void compareNumber(uint64_t NumArgsPassed, uint64_t ArgAccessed, uint32_t tag){
+ if(ArgAccessed > NumArgsPassed) {
+ printf("Type mismatch: Accessing variable %lu, passed only %lu! %u \n", ArgAccessed, NumArgsPassed, tag);
+ }
+}
+/**
* Check the loaded type against the type recorded in the shadow memory.
*/
void trackLoadInst(void *ptr, uint8_t typeNumber, uint64_t size, uint32_t tag) {
@@ -126,7 +134,7 @@
}
} else {
/* If so, set type to the type being read.
- Check that none of the bytes are typed.*/
+ Check that none of the bytes are typed.*/
for (; i < size; ++i) {
if (0xFF != shadow_begin[p + i]) {
printf("Type mismatch: detecting %u, expecting %u (0 != %u)! %u\n", typeNumber, shadow_begin[p+i], shadow_begin[p + i], tag);
@@ -162,6 +170,6 @@
uintptr_t s = maskAddress(srcptr);
memcpy(&shadow_begin[d], &shadow_begin[s], size);
#if DEBUG
- printf("Copy: %p, %p = %u | %" PRIu64 " bytes | %d\n", dstptr, (void *)d, shadow_begin[s], size, tag);
+ printf("Copy: %p, %p = %u | %" PRIu64 " bytes | %u\n", dstptr, (void *)d, shadow_begin[s], size, tag);
#endif
}
More information about the llvm-commits
mailing list