<div dir="ltr"><div>As an update, here is the current piece of code:<br><br></div>Inside a loop iterating over each basic block :<br><div><br><b><i>std::vector<Value*> values;<br>values.resize(cnt);<br><br>//std::vector<Value*> values(sizeof(Value*)*cnt);<br>
//SmallVector<Value*,cnt> values;<br><br>if(is)<br>{<br> LLVMContext& C = is->getContext();<br> errs()<<"\ni: \n";<br> <br> for(i=0;i<cnt;i++){<br> values[i]=ConstantInt::getSigned(Type::getInt64Ty(C),myArray[i]);<br>
errs()<<" "<<myArray[i];<br> }<br><br> is->setMetadata("path",MDNode::get(C,values));<br> errs()<<"\nmodif instr "<<*is<<"\n";<br>
<br> if( (is->getMetadata("path")) ){ <br> for(i=0;i<cnt;i++){ <br> if(is->getMetadata("path")->getOperand(i)) { <br> errs()<<"\nget isntr "<<*(is->getMetadata("path")->getOperand(i))<<"\n"; <br>
}<br> }<br> } <br>}<br>values.clear();</i></b><br><div class="gmail_extra"><br><br></div><div class="gmail_extra">I receive a memory corruption error at some basic blocks. Here are the debug outputs:<br>
<br></div><div class="gmail_extra">1. opt - <i><b>opt: malloc.c:3801: _int_malloc: Assertion `(unsigned long)(size) >= (unsigned long)(nb)' failed.</b></i><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">
2. gdb - <br><i><b>Program received signal SIGABRT, Aborted.<br>0xb7fdd424 in __kernel_vsyscall ()</b></i><br><br></div><div class="gmail_extra">3. valgrind - it executes all the code and at the problematic loop iteration I have :<br>
<br><i><b>==5134== Invalid write of size 4<br>==5134== at 0x4039280: (anonymous namespace)::Hello::runOnModule(llvm::Module&) (in /home/alex/llvm/Release+Asserts/lib/Hello.so)<br>==5134== by 0x8E33DE3: llvm::MPPassManager::runOnModule(llvm::Module&) (in /home/alex/llvm/Release+Asserts/bin/opt)<br>
==5134== by 0x8E3726F: llvm::PassManagerImpl::run(llvm::Module&) (in /home/alex/llvm/Release+Asserts/bin/opt)<br>==5134== by 0x8E37385: llvm::PassManager::run(llvm::Module&) (in /home/alex/llvm/Release+Asserts/bin/opt)<br>
==5134== by 0x41AE4D2: (below main) (libc-start.c:226)<br>==5134== Address 0x46cfa40 is 0 bytes after a block of size 200 alloc'd<br>==5134== at 0x402C454: operator new[](unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)<br>
==5134== by 0x4037AE0: (anonymous namespace)::Hello::runOnModule(llvm::Module&) (in /home/alex/llvm/Release+Asserts/lib/Hello.so)</b></i><br><br></div><div class="gmail_extra">and repeating. <br></div><div class="gmail_extra">
<br><i><b>==5230== HEAP SUMMARY:<br>==5230== in use at exit: 95,110 bytes in 317 blocks<br>==5230== total heap usage: 33,395 allocs, 33,078 frees, 4,484,753 bytes allocated<br>==5230== <br>==5230== LEAK SUMMARY:<br>
==5230== definitely lost: 7,732 bytes in 31 blocks<br>==5230== indirectly lost: 85,864 bytes in 275 blocks<br>==5230== possibly lost: 0 bytes in 0 blocks<br>==5230== still reachable: 1,514 bytes in 11 blocks<br>
==5230== suppressed: 0 bytes in 0 blocks<br>==5230== Rerun with --leak-check=full to see details of leaked memory<br>==5230== <br>==5230== For counts of detected and suppressed errors, rerun with: -v<br>==5230== ERROR SUMMARY: 16432 errors from 15 contexts (suppressed: 0 from 0)</b></i><br>
<br></div><div class="gmail_extra">I assume the main problems are:<br></div><div class="gmail_extra">1. I don't allocate well memory for values. Or maybe I am allocating only for Value* pointers, not for the actual values. Maybe I don't free the mem.<br>
</div><div class="gmail_extra">2. I cannot use array instead of vector, since <i><b>is->setMetadata("path",MDNode::get(C,values));</b></i> won't let me.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">
What do you think it is wrong? What should I try? I want only to attach some integers as metadata, one integer per operand. <br><br></div><div class="gmail_extra">Thank you !<br></div><div class="gmail_extra"><br><br></div>
<div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 29, 2013 at 10:00 AM, Alexandru Ionut Diaconescu <span dir="ltr"><<a href="mailto:alexandruionutdiaconescu@gmail.com" target="_blank">alexandruionutdiaconescu@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello Duncan,<div><br></div><div>Yes, I built it with assertions and I have also debug info.</div>
</div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">On Tue, May 28, 2013 at 5:47 PM, Duncan Sands <span dir="ltr"><<a href="mailto:baldrick@free.fr" target="_blank">baldrick@free.fr</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Alexandru, did you build LLVM with assertions enabled? If not then you<br>
should do.<br>
<br>
Ciao, Duncan.<div><div><br>
______________________________<u></u>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvmdev</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div></div></div><div class="im">-- <br><font style="color:rgb(153,153,153)">Best regards,</font><br style="color:rgb(153,153,153)">
<font style="color:rgb(153,153,153)">Alexandru Ionut Diaconescu</font><br>
</div></div>
</blockquote></div><br><br clear="all"><br>-- <br><font style="background-color:rgb(255,255,255);color:rgb(153,153,153)">Best regards,</font><br style="background-color:rgb(255,255,255);color:rgb(153,153,153)"><font style="background-color:rgb(255,255,255);color:rgb(153,153,153)">Alexandru Ionut Diaconescu</font><br>
</div></div></div>