<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<META content="MSHTML 5.00.3821.2800" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT face="Times New Roman">Hi,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">Sorry for bothering you guys 
again.</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">I got problem when I am trying to recover the 
Global Variable Initial value. What I did is like the following</FONT></DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV><FONT face="Times New Roman">ConstantArray *Cstr = 
dyn_cast<ConstantArray>(gI->getInitializer());</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">// the above instruction enable me to get the 
content of initial string of global variable, like char a[10] ="test 
global";</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">And then I make some change for the Cstr and 
write it back to the global variable by gI->setInitializer(Constant *); 
Meanwhile I am trying to put a routine (constructing IR routine) into entry of 
main function, which is for recover initial vaule of global variable to the 
original string. In this routine,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">Type *PointerAryType  =  
ArrayType::get(PointerType::get(Type::SByteTy) , 20);</FONT></DIV>
<DIV><FONT face="Times New Roman">AllocaInst *PointerAry = new 
AllocaInst(PointerAryType , 0 , "AddrOfGstr", BB);</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">// Here, I tried to insert IR like alloca [20 
x sbyte *], for C code, it is char *AddrOfGstr[20]; which pointer array is for 
storing the pointer of initial value of each </FONT></DIV>
<DIV><FONT face="Times New Roman">// global variable.</FONT></DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV><FONT face="Times New Roman">So next step in my Pass, I 
should get the pointer of initial value of each global variable and assign 
them the AddrOfGstr[i]. Here, I got problem, I can get initial value by 
gI->getInitializer(), but this pointer is not the memory address of the 
initial value, it is a pointer of constant, like constant *. I cannot assign it 
to the AddrOfGstr[i]. How could I get memory address the initial vaule, not 
the pointer of constant? </FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">I tried to use the following way,</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">std::vector <Value *> 
idxVec;</FONT></DIV>
<DIV><FONT face="Times New Roman">Value *Zero1 = ConstantInt::get(Type::IntTy , 
0);</FONT></DIV>
<DIV><FONT face="Times New Roman">
<DIV><FONT face="Times New Roman">Value *Zero2 = ConstantInt::get(Type::IntTy , 
0);</FONT></DIV>
<DIV> </DIV>
<DIV>idxVec.push_back(Zero1);</DIV>
<DIV>idxVec.push_back(Zero2);</DIV></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">Constant *pStr = 
ConstantExpr::getGetElementPtr(Cstr, idxVec); // trying to get pointer of 
initial value</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">GetElementPtrInst *GEP = new 
GetElementPtrInst( PointerAry , idxVec, "GetAryElement" , BB);  //  
insert getelementptr and get the pionter of AddrOfGstr[0] </FONT></DIV>
<DIV><FONT face="Times New Roman">StoreInst *storeAddr = new StoreInst(pStr , 
GEP , BB); // trying to assign the pStr to GEP</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">The above code is for getting the pionter of 
initial value of Cstr and assign it to AddrOfGstr[0], which should be 
like</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">char a[10]="test str";</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">main(){</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">char *AddrOfGstr[20];</FONT></DIV>
<DIV><FONT face="Times New Roman">AddrOfGstr[0] = a;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">}</FONT></DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV><FONT face="Times New Roman">the code is compiled successfully, but 
when I run the pass, it failed since the instruction</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman"><FONT face="Times New Roman">Constant *pStr = 
ConstantExpr::getGetElementPtr(Cstr, idxVec);</FONT></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">I got the error as the following, 
</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">pt: Constants.cpp:1398: static llvm::Constant* 
llvm::ConstantExpr::getGetElementPtr(llvm::Constant*, const 
std::vector<llvm::Value*, std::allocator<llvm::Value*> >&): 
Assertion `Ty && "GEP indices invalid!"' failed.</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman">Is the question clear? </FONT><FONT 
face="Times New Roman">How could I fix it? Thanks so much.</FONT></DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV><FONT face="Times New Roman">Qiuyu<BR></DIV></FONT>
<DIV> </DIV>
<DIV>  </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV>
<DIV> </DIV>
<DIV><FONT face="Times New Roman"></FONT> </DIV></BODY></HTML>