[llvm-commits] [poolalloc] r132848 - /poolalloc/trunk/lib/AssistDS/TypeChecks.cpp

Arushi Aggarwal aggarwa4 at illinois.edu
Fri Jun 10 09:58:46 PDT 2011


Author: aggarwa4
Date: Fri Jun 10 11:58:46 2011
New Revision: 132848

URL: http://llvm.org/viewvc/llvm-project?rev=132848&view=rev
Log:
Make sure we build a correct GEP. For every new type
we must add an index.
For arrays, the starting pointer should be the
start of the array, not the global variable.

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=132848&r1=132847&r2=132848&view=diff
==============================================================================
--- poolalloc/trunk/lib/AssistDS/TypeChecks.cpp (original)
+++ poolalloc/trunk/lib/AssistDS/TypeChecks.cpp Fri Jun 10 11:58:46 2011
@@ -1132,6 +1132,7 @@
     if(!I->hasInitializer())
       continue;
     SmallVector<Value*,8>index;
+    index.push_back(ConstantInt::get(Int64Ty, 0));
     visitGlobal(M, *I, I->getInitializer(), *InsertPt, index);
   }
   //
@@ -1219,11 +1220,16 @@
     const Type * ElementType = CA->getType()->getElementType();
     // Create the type entry for the first element
     // using recursive creation till we get to the base types
+    Indices.push_back(ConstantInt::get(Int64Ty,0));
     visitGlobal(M, GV, CA->getOperand(0), I, Indices);
+    Indices.pop_back();
+    GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(&GV, Indices.begin(),
+                                                               Indices.end(),"", &I) ;
+
+    CastInst *BCI = BitCastInst::CreatePointerCast(GEP, VoidPtrTy, "", &I);
 
     // Copy the type metadata for the first element
     // over for the rest of the elements.
-    CastInst *BCI = BitCastInst::CreatePointerCast(&GV, VoidPtrTy, "", &I);
     std::vector<Value *> Args;
     Args.push_back(BCI);
     Args.push_back(getSizeConstant(ElementType));
@@ -1249,8 +1255,13 @@
     const Type *Ty = CAZ->getType();
     if(const ArrayType * ATy = dyn_cast<ArrayType>(Ty)) {
       const Type * ElementType = ATy->getElementType();
+      Indices.push_back(ConstantInt::get(Int64Ty,0));
       visitGlobal(M, GV, Constant::getNullValue(ElementType), I, Indices);
-      CastInst *BCI = BitCastInst::CreatePointerCast(&GV, VoidPtrTy, "", &I);
+      Indices.pop_back();
+      GetElementPtrInst *GEP = GetElementPtrInst::CreateInBounds(&GV, Indices.begin(),
+                                                                 Indices.end(),"", &I) ;
+
+      CastInst *BCI = BitCastInst::CreatePointerCast(GEP, VoidPtrTy, "", &I);
       std::vector<Value *> Args;
       Args.push_back(BCI);
       Args.push_back(getSizeConstant(ElementType));





More information about the llvm-commits mailing list