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

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


ah okay!

Thanks!

--
Himanshu

On Thu, Jul 28, 2016 at 11:36 AM, Jonathan Roelofs <
jonathan at codesourcery.com> wrote:

>
>
> On 7/28/16 12:33 PM, Himanshu wrote:
>
>> Thanks Jon!
>>
>> So you suggest the change of function to:
>>
>> void *wrapAssgnmt(void **,void *, void *ptr){
>>    // assgn using first two args
>>    ...
>>   // return the actual ptr
>>   return ptr;
>> }
>>
>
> Oh, oops. I put the parens in the wrong spot. I meant to write this:
>
>   if ((wrapAssgnmt(&ptr, malloc( ... )), ptr) = NULL)
>
> as-in: use the comma operator to perform the assignment of NULL into 'ptr'.
>
>
> Jon
>
>
>> --
>> Himanshu
>>
>> On Thu, Jul 28, 2016 at 11:29 AM, Jonathan Roelofs
>> <jroelofs.lists at gmail.com <mailto:jroelofs.lists at gmail.com>> wrote:
>>
>>
>>
>>     On 7/28/16 12:09 PM, Himanshu via cfe-dev wrote:
>>
>>         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?
>>
>>
>>     This happens because your translation is not precise enough. It
>>     needs to be something like:
>>
>>       if ((wrapAssgnmt(&ptr, malloc( ... ), ptr) = NULL)
>>
>>
>>     Jon
>>
>>
>>         Thanks!
>>
>>
>>         _______________________________________________
>>         cfe-dev mailing list
>>         cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
>>         http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>>
>>     --
>>     Jon Roelofs
>>     jonathan at codesourcery.com <mailto:jonathan at codesourcery.com>
>>     CodeSourcery / Mentor Embedded
>>
>>
>>
> --
> Jon Roelofs
> jonathan at codesourcery.com
> CodeSourcery / Mentor Embedded
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160728/6c78208f/attachment.html>


More information about the cfe-dev mailing list