<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class=""></span><br><span class=""></span>
You might be invalidating the iterator after inserting the first
CallInst. There are multiple ways to solve this problem:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000">
<br>
<ol>
<li>Make your pass derive from the InstVistor class and implement
a visitCallInst() method. I believe the iterators in the
InstVistor class do not get invalidated when new instructions
are added.</li>
<li>Iterate over all the instructions first and record the ones to
replace in a container (e.g., a std::vector<>). A second
loop iterates over the container and replaces all the CallInsts
stored therein. <br></li><li>Look up the iterator invalidation rules for the instruction
iterator and use the iterator in a way that does not invalidate
the iterator.</li></ol></div></blockquote><div>Good call, method 2. is working fine. I remember seeing such pattern in BoudsChecking code. I guess I am not the first having troubles with this.<br></div><div><br>I took a quick look at the iterator problem<br> - For the cloned instruction, the problem is it has no parents and I guess it implies it has no link with previous or next instructions. So some nullpointers will appear when inserting the instruction because it will try to build the double linked list of instructions (I think that's the algorithmic structure employed).<br></div><div> - For the regular iterator the problem might be just the same. As it is a double linked list, when you replace the current instruction with another the current instruction probably is erased. I already made the changes so I won't try to generate the error again but I thinks that makes sense.<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="#FFFFFF" text="#000000"><ol>
</ol>
<br>
Regards,<br>
<br>
John Criswell<div><div class="h5"><br></div></div></div>
</blockquote></div>Thanks a lot! About the lli error it appears to have an undefined behavior. Some times it runs correctly, most of the times it freezes and sometimes I get the lli error. Anyway, the fact the error says that the double-linked list is corrupted make sense with my thoughts about the iterator issue.<br><br></div><div class="gmail_extra">Pierre<br></div></div>