<div dir="ltr">ah okay! <div><br></div><div>Thanks! </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:36 AM, Jonathan Roelofs <span dir="ltr"><<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 7/28/16 12:33 PM, Himanshu wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Thanks Jon!<br>
<br>
So you suggest the change of function to:<br>
<br>
void *wrapAssgnmt(void **,void *, void *ptr){<br>
// assgn using first two args<br>
...<br>
// return the actual ptr<br>
return ptr;<br>
}<br>
</blockquote>
<br></span>
Oh, oops. I put the parens in the wrong spot. I meant to write this:<br>
<br>
if ((wrapAssgnmt(&ptr, malloc( ... )), ptr) = NULL)<br>
<br>
as-in: use the comma operator to perform the assignment of NULL into 'ptr'.<br>
<br>
<br>
Jon<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
<br>
--<br>
Himanshu<br>
<br>
On Thu, Jul 28, 2016 at 11:29 AM, Jonathan Roelofs<br></span><div><div class="h5">
<<a href="mailto:jroelofs.lists@gmail.com" target="_blank">jroelofs.lists@gmail.com</a> <mailto:<a href="mailto:jroelofs.lists@gmail.com" target="_blank">jroelofs.lists@gmail.com</a>>> wrote:<br>
<br>
<br>
<br>
On 7/28/16 12:09 PM, Himanshu via cfe-dev wrote:<br>
<br>
Hi All,<br>
<br>
I would like to perform for simulation experiments on a C<br>
codebase where<br>
based on the type of the variable, an assignment to a pointer of<br>
this<br>
type is followed by some additional instruction (lets say an<br>
external<br>
counter increment --- just to create a simple scenario). I have<br>
implemented a RecuriveASTVisitor that visits BinaryOps (after<br>
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<br>
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<br>
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<br>
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 ( ... ))<br>
= NULL) ...<br>
if((wrapAssgnmt( &ptr , malloc( ... ) ) = NULL)<br>
<br>
I understand the warning, but I am not sure about the<br>
cause/reason.<br>
Could someone please suggest the correction?<br>
<br>
<br>
This happens because your translation is not precise enough. It<br>
needs to be something like:<br>
<br>
if ((wrapAssgnmt(&ptr, malloc( ... ), ptr) = NULL)<br>
<br>
<br>
Jon<br>
<br>
<br>
Thanks!<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br></div></div>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a> <mailto:<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>><span class=""><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>
<br>
--<br>
Jon Roelofs<br></span>
<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a> <mailto:<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a>><br>
CodeSourcery / Mentor Embedded<br>
<br>
<br>
</blockquote><div class="HOEnZb"><div class="h5">
<br>
-- <br>
Jon Roelofs<br>
<a href="mailto:jonathan@codesourcery.com" target="_blank">jonathan@codesourcery.com</a><br>
CodeSourcery / Mentor Embedded<br>
</div></div></blockquote></div><br></div>