<div dir="ltr">Thanks Jon! <div><br></div><div>So you suggest the change of function to: </div><div><br></div><div>void *<span style="font-size:12.8px">wrapAssgnmt(void **,void *, void *ptr){</span></div><div><span style="font-size:12.8px">   // assgn using first two args</span></div><div><span style="font-size:12.8px">   ...</span></div><div><span style="font-size:12.8px">  // return the actual ptr</span></div><div><span style="font-size:12.8px">  return ptr;</span></div><div><span style="font-size:12.8px">}</span></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">--<div>Himanshu</div></div></div>
<br><div class="gmail_quote">On Thu, Jul 28, 2016 at 11:29 AM, Jonathan Roelofs <span dir="ltr"><<a href="mailto:jroelofs.lists@gmail.com" target="_blank">jroelofs.lists@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
<br>
On 7/28/16 12:09 PM, Himanshu via cfe-dev wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi All,<br>
<br>
I would like to perform for simulation experiments on a C codebase where<br>
based on the type of the variable, an assignment to a pointer of this<br>
type is followed by some additional instruction (lets say an external<br>
counter increment --- just to create a simple scenario). I have<br>
implemented a RecuriveASTVisitor that visits BinaryOps (after checking<br>
they are assignments) and rewrites the source by replacement.<br>
<br>
However, there are issues with multiple assignments within the same<br>
source line (such as ptr1 = ptr2 = NULL), as well as some macro<br>
expansions. I would like a robust way of doing so without breaking the code.<br>
<br>
Could someone kindly answer the following:<br>
1. Is there some existing libTool to do so?<br>
<br>
if not, then:<br>
2. My wrapper function is of the form: (listing a simplified version)<br>
      void * wrapAssgnmt (void **ptrToLhsPtr, void *rhsPtr){<br>
              *ptrToLhsPtr = rhsPtr;<br>
              // do other things for simulation<br>
              return *ptrToLhsPtr; // so that NULL based checks work.<br>
      }<br>
    compilation gives me: "warning: comparison between pointer and<br>
integer" for cases of pattern:<br>
    type *ptr;  // original code is  if( (ptr = malloc ( ... )) = NULL) ...<br>
    if((wrapAssgnmt( &ptr , malloc( ... ) ) = NULL)<br>
<br>
    I understand the warning, but I am not sure about the cause/reason.<br>
Could someone please suggest the correction?<br>
</blockquote>
<br></div></div>
This happens because your translation is not precise enough. It needs to be something like:<br>
<br>
  if ((wrapAssgnmt(&ptr, malloc( ... ), ptr) = NULL)<br>
<br>
<br>
Jon<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thanks!<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br><span class="HOEnZb"><font color="#888888">
</font></span></blockquote><span class="HOEnZb"><font color="#888888">
<br>
-- <br>
Jon Roelofs<br>
<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a><br>
CodeSourcery / Mentor Embedded<br>
</font></span></blockquote></div><br></div>