[cfe-dev] Wrapping assignments in function call for simulation

Himanshu via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 28 11:09:51 PDT 2016


Hi All,

I would like to perform for simulation experiments on a C codebase where
based on the type of the variable, an assignment to a pointer of this type
is followed by some additional instruction (lets say an external counter
increment --- just to create a simple scenario). I have implemented a
RecuriveASTVisitor that visits BinaryOps (after checking they are
assignments) and rewrites the source by replacement.

However, there are issues with multiple assignments within the same source
line (such as ptr1 = ptr2 = NULL), as well as some macro expansions. I
would like a robust way of doing so without breaking the code.

Could someone kindly answer the following:
1. Is there some existing libTool to do so?

if not, then:
2. My wrapper function is of the form: (listing a simplified version)
      void * wrapAssgnmt (void **ptrToLhsPtr, void *rhsPtr){
              *ptrToLhsPtr = rhsPtr;
              // do other things for simulation
              return *ptrToLhsPtr; // so that NULL based checks work.
      }
    compilation gives me: "warning: comparison between pointer and integer"
for cases of pattern:
    type *ptr;  // original code is  if( (ptr = malloc ( ... )) = NULL) ...
    if((wrapAssgnmt( &ptr , malloc( ... ) ) = NULL)

    I understand the warning, but I am not sure about the cause/reason.
Could someone please suggest the correction?

Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160728/34fb7a24/attachment.html>


More information about the cfe-dev mailing list