[llvm-commits] [poolalloc] r131688 - in /poolalloc/trunk: include/assistDS/TypeChecks.h lib/AssistDS/TypeChecks.cpp runtime/DynamicTypeChecks/TypeRuntime.c
Arushi Aggarwal
aggarwa4 at illinois.edu
Thu May 19 15:12:16 PDT 2011
Author: aggarwa4
Date: Thu May 19 17:12:15 2011
New Revision: 131688
URL: http://llvm.org/viewvc/llvm-project?rev=131688&view=rev
Log:
Add code to initialize type information for
arguments to main. Assume they are initialized.
Initialize metadata to TOP.
Modified:
poolalloc/trunk/include/assistDS/TypeChecks.h
poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
Modified: poolalloc/trunk/include/assistDS/TypeChecks.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/assistDS/TypeChecks.h?rev=131688&r1=131687&r2=131688&view=diff
==============================================================================
--- poolalloc/trunk/include/assistDS/TypeChecks.h (original)
+++ poolalloc/trunk/include/assistDS/TypeChecks.h Thu May 19 17:12:15 2011
@@ -67,6 +67,7 @@
bool visitInternalFunction(Module &M, Function &F);
bool visitExternalFunction(Module &M, Function &F);
bool visitByValFunction(Module &M, Function &F);
+ bool visitMain(Module &M, Function &F);
bool visitVarArgFunction(Module &M, Function &F);
bool visitLoadInst(Module &M, LoadInst &LI);
bool visitStoreInst(Module &M, StoreInst &SI);
Modified: poolalloc/trunk/lib/AssistDS/TypeChecks.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/AssistDS/TypeChecks.cpp?rev=131688&r1=131687&r2=131688&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Thu May 19 17:12:15 2011
@@ -118,6 +118,10 @@
modified |= initShadow(M);
inst_iterator MainI = inst_begin(MainF);
+
+ // record argv
+
+ modified |= visitMain(M, *MainF);
// record all globals
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
@@ -180,6 +184,7 @@
modified |= visitVarArgFunction(M, *F);
}
+
return modified;
}
@@ -629,6 +634,41 @@
return true;
}
+bool TypeChecks::visitMain(Module &M, Function &MainFunc) {
+ if(MainFunc.arg_size() != 2)
+ // No need to register
+ return false;
+
+ Function::arg_iterator AI = MainFunc.arg_begin();
+ Value *Argc = AI;
+ Value *Argv = ++AI;
+
+ Instruction *InsertPt = MainFunc.front().begin();
+ Constant * RegisterArgv = M.getOrInsertFunction("trackArgvType", VoidPtrTy, Argc->getType(), Argv->getType(), NULL);
+ std::vector<Value *> fargs;
+ fargs.push_back (Argc);
+ fargs.push_back (Argv);
+ CallInst *CI = CallInst::Create (RegisterArgv, fargs.begin(), fargs.end(), "", InsertPt);
+ CastInst *BCII = BitCastInst::CreatePointerCast(CI, Argv->getType());
+ BCII->insertAfter(CI);
+ std::vector<User *> Uses;
+ Value::use_iterator UI = Argv->use_begin();
+ for (; UI != Argv->use_end(); ++UI) {
+ if (Instruction * Use = dyn_cast<Instruction>(UI))
+ if (CI != Use) {
+ Uses.push_back (*UI);
+ }
+ }
+
+ while (Uses.size()) {
+ User *Use = Uses.back();
+ Uses.pop_back();
+ Use->replaceUsesOfWith (Argv, BCII);
+ }
+
+ return true;
+}
+
bool TypeChecks::visitGlobal(Module &M, GlobalVariable &GV,
Constant *C, Instruction &I, unsigned offset) {
Modified: poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c?rev=131688&r1=131687&r2=131688&view=diff
==============================================================================
--- poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c (original)
+++ poolalloc/trunk/runtime/DynamicTypeChecks/TypeRuntime.c Thu May 19 17:12:15 2011
@@ -2,6 +2,7 @@
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
@@ -18,6 +19,8 @@
uint8_t *shadow_begin;
uint8_t *shadow_end;
+void trackInitInst(void *ptr, uint64_t size, uint32_t tag);
+
uintptr_t maskAddress(void *ptr) {
uintptr_t p = (uintptr_t)ptr;
uintptr_t res = (uintptr_t)ptr;
@@ -58,6 +61,26 @@
}
}
+void * trackArgvType(int argc, char **argv) {
+
+ char ** argv_temp = (char **)malloc((sizeof(char*)*(argc+1)));
+
+ int index = 0;
+ for (; index < argc; ++index) {
+ char *argv_index_temp =
+ (char *)malloc((strlen(argv[index])+ 1)*sizeof(char));
+ argv_index_temp = strcpy(argv_index_temp, argv[index]);
+
+ trackInitInst(argv_index_temp, (strlen(argv[index]) + 1)*sizeof(char), 0);
+ argv_temp[index] = argv_index_temp;
+ }
+ argv_temp[argc] = NULL;
+
+ trackInitInst(argv_temp, (argc + 1)*sizeof(char*), 0);
+
+ return (void*)argv_temp;
+}
+
/**
* Record the global type and address in the shadow memory.
*/
More information about the llvm-commits
mailing list