Eirini Psallida
2013-Sep-24 15:38 UTC
[LLVMdev] get the address in memory where an instruction lives
Hi, i want to get the address in memory of an instruction pointer and use it as a key in my tables. i iterate over the instructions in LLVM IR like this: for (Module::iterator fi = Mod->begin(), fi_end = Mod->end(); fi != fi_end; ++fi) { for (inst_iterator I = inst_begin(fi), E = inst_end(fi); I != E; ++I) { Instruction *ii = dyn_cast<Instruction>(&*I); errs() << &ii << "\n"; } but i get the same address for every instruction, eg 0xbfc979fc Why is this happening and how can i get the rigth address? Thanks, Eirini -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130924/77287bb6/attachment.html>
Benjamin Kramer
2013-Sep-24 15:44 UTC
[LLVMdev] get the address in memory where an instruction lives
On 24.09.2013, at 17:38, Eirini Psallida <eirini.psallida at gmail.com> wrote:> Hi, > i want to get the address in memory of an instruction pointer and use it as a key in my tables. > i iterate over the instructions in LLVM IR like this: > for (Module::iterator fi = Mod->begin(), fi_end = Mod->end(); fi != fi_end; ++fi) { > for (inst_iterator I = inst_begin(fi), E = inst_end(fi); I != E; ++I) { > Instruction *ii = dyn_cast<Instruction>(&*I); > errs() << &ii << "\n"; > } > > but i get the same address for every instruction, eg 0xbfc979fc > Why is this happening and how can i get the rigth address?You're printing the address of a variable on the stack. Try removing the '&' before 'ii'. - Ben
John Criswell
2013-Sep-24 15:49 UTC
[LLVMdev] get the address in memory where an instruction lives
On 9/24/13 10:38 AM, Eirini Psallida wrote:> Hi, > i want to get the address in memory of an instruction pointer and use > it as a key in my tables. > i iterate over the instructions in LLVM IR like this: > for (Module::iterator fi = Mod->begin(), fi_end = Mod->end(); fi != > fi_end; ++fi) { > for (inst_iterator I = inst_begin(fi), E = inst_end(fi); I != E; > ++I) { > Instruction *ii = dyn_cast<Instruction>(&*I); > errs() << &ii << "\n"; > } > > but i get the same address for every instruction, eg 0xbfc979fc > Why is this happening and how can i get the rigth address?You're getting the same address because you're printing the address of the variable that holds the pointer to the instruction (as opposed to the pointer itself). In other words, you want to print ii and not &ii. -- John T.> > Thanks, > > Eirini > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130924/d5f5d997/attachment.html>