<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    On 11/3/2011 4:55 AM, Arshak Nazaryan wrote:
    <blockquote
cite="mid:CAJdHwE_RRaE8U5-chYi5vK=3j_eJgh=eC-X3W2XreKfN1VUviw@mail.gmail.com"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      Dear sir or madam,
      <div><br>
      </div>
      <div>I am a 4-th year student at Yerevan State University,
        Armenia; and I am studying LLVM in order to write my Bachelor
        thesis.</div>
    </blockquote>
    <br>
    Hi Arshak.<br>
    <br>
    <br>
    <blockquote
cite="mid:CAJdHwE_RRaE8U5-chYi5vK=3j_eJgh=eC-X3W2XreKfN1VUviw@mail.gmail.com"
      type="cite">
      <div>I am trying to write an llvm pass that just removes all "Add"
        commands and gives some statstics. </div>
      <div>Nevertheless, I get this segmentation fault:</div>
    </blockquote>
    <br>
    The problem is most likely that you're not modifying uses of the add
    instructions.  The LLVM IR has explicit def-use chains, so if you
    want to remove an instruction, you need to modify any other
    instruction *that uses that instruction* so that it does not use
    that instruction any more.<br>
    <br>
    In this case, an instruction that is using the add instruction will
    still reference the add instruction even after you've deleted it. 
    The error you're seeing is most likely due to a dangling pointer.<br>
    <br>
    To fix it, create a constant integer (ConstantInt object) and use
    the replaceAllUsesWith() method of the Instruction class to replace
    uses of the add with the integer.  Then you can erase the add from
    the program.<br>
    <br>
    By the way, it looks like you don't have a build with assertions
    enabled.  I recommend compiling with<tt><br>
      <br>
      gmake ENABLE_OPTIMIZED=0 DISABLE_ASSERTIONS=1<br>
    </tt><br>
    if you're going to be developing an LLVM pass.<br>
    <br>
    -- John T.<br>
    <br>
    <tt></tt>
    <blockquote
cite="mid:CAJdHwE_RRaE8U5-chYi5vK=3j_eJgh=eC-X3W2XreKfN1VUviw@mail.gmail.com"
      type="cite">
      <div><br>
      </div>
      <div>................some rows about functions, that are not
        changed by my pass. The errors occurs after it has modified a
        "@_Z3addii" function.</div>
      <div>
        <div>store i32 %b.0, i32* %4  and the type is ddddbbm 28</div>
        <div>  %5 = load i32* %a_addr, align 4  and the type is ddddbbm
          27</div>
        <div>  %6 = load i32* %b_addr, align 4  and the type is ddddbbm
          27</div>
        <div>  %7 = add nsw i32 %5, %6  and the type is ddddbbm 8</div>
        <div>  store i32 %7, i32* %0, align 4  and the type is ddddbbm
          28</div>
        <div>  %7 = add nsw i32 %5, %6   is erased, ba!</div>
        <div>  %7 = load i32* %0, align 4  and the type is ddddbbm 27</div>
        <div>  store i32 %7, i32* %retval, align 4  and the type is
          ddddbbm 28</div>
        <div>  br label %return  and the type is ddddbbm 2</div>
        <div>  ret i32 %retval1  and the type is ddddbbm 1</div>
        <div>0  opt             0x00000000008ed93f</div>
        <div>1  opt             0x00000000008edcea</div>
        <div>2  libpthread.so.0 0x00007f9ba1183c60</div>
        <div>3  opt             0x00000000004b3615
          llvm::PATypeHolder::get() const + 21</div>
        <div>4  opt             0x00000000008a4f11</div>
        <div>5  opt             0x00000000008a9404</div>
        <div>6  opt             0x0000000000882557
          llvm::FPPassManager::runOnFunction(llvm::Function&) + 551</div>
        <div>7  opt             0x00000000008825db
          llvm::FPPassManager::runOnModule(llvm::Module&) + 75</div>
        <div>8  opt             0x0000000000882197
          llvm::MPPassManager::runOnModule(llvm::Module&) + 503</div>
        <div>9  opt             0x0000000000882299
          llvm::PassManagerImpl::run(llvm::Module&) + 137</div>
        <div>10 opt             0x00000000004ac451 main + 4881</div>
        <div>11 libc.so.6       0x00007f9ba0459eff __libc_start_main +
          255</div>
        <div>12 opt             0x000000000049f5f9</div>
        <div>Stack dump:</div>
        <div>0.<span class="Apple-tab-span" style="white-space:pre"> </span>Program
          arguments: opt hello.bc -load
          ../llvm/llvm-2.9/plugin/BasicBlockStats.so -basic-block-stats
          -stats -o newhello.bc </div>
        <div>1.<span class="Apple-tab-span" style="white-space:pre"> </span>Running
          pass 'Function Pass Manager' on module 'hello.bc'.</div>
        <div>2.<span class="Apple-tab-span" style="white-space:pre"> </span>Running
          pass 'Module Verifier' on function '@_Z3addii'</div>
        <div>Segmentation fault</div>
      </div>
      <div><br>
      </div>
      <div>Please find the source of my pass attached.</div>
      <div>Hope to get a reply soon.</div>
      <div><br>
      </div>
      <div>Regards,</div>
      <div>Arshak Nazaryan</div>
      <div><br>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>